Skip to content

fix(mcp): improve execute_sql response-too-large error to suggest limit parameter#39003

Merged
aminghadersohi merged 1 commit into
apache:masterfrom
aminghadersohi:amin/execute-sql-suggest-limit
Apr 3, 2026
Merged

fix(mcp): improve execute_sql response-too-large error to suggest limit parameter#39003
aminghadersohi merged 1 commit into
apache:masterfrom
aminghadersohi:amin/execute-sql-suggest-limit

Conversation

@aminghadersohi
Copy link
Copy Markdown
Contributor

@aminghadersohi aminghadersohi commented Apr 1, 2026

User description

SUMMARY

When execute_sql responses exceed the token limit, the error message now provides more actionable suggestions:

  1. SQL LIMIT clause — suggests adding LIMIT to the query
  2. Tool limit parameter — suggests using the execute_sql limit parameter to cap rows (only when not already specified)
  3. General reduction suggestion — when no limit parameter is set, the general "add a limit" suggestion now fires for execute_sql (previously only fired for list_* tools)

Before:
The error only showed a generic SQL LIMIT suggestion. The tool's own limit parameter was never mentioned, and the general "add a limit" suggestion was skipped entirely for execute_sql.

After:

Response too large: ~33,348 tokens (limit: 25,000)

This response would overwhelm the LLM context window.
Please modify your query to reduce the response size:

1. Use the 'limit' parameter (e.g., limit=100) to cap the number of rows returned — need ~25% reduction
2. Add a LIMIT clause to your SQL query (e.g., SELECT * FROM table LIMIT 100)
3. Use the execute_sql 'limit' parameter to cap rows returned (e.g., limit=100) — this overrides any SQL LIMIT clause

TESTING

  • Added test_execute_sql_with_limit_param_no_duplicate_suggestion test
  • Updated test_tool_specific_suggestions_execute_sql to verify both SQL LIMIT and parameter suggestions
  • All 33 tests in test_token_utils.py pass

BEFORE/AFTER SCREENSHOTS OR COVERAGE URL

N/A — backend-only change, no UI impact.


CodeAnt-AI Description

Make oversized SQL results point users to the right limit option

What Changed

  • When execute_sql returns too much data, the error now suggests both adding a SQL LIMIT clause and using the tool’s limit parameter.
  • If a limit is already set, the message avoids repeating that suggestion and keeps the guidance focused on reducing the result size.
  • The error text for SQL-based size reduction is clearer and more direct.

Impact

✅ Fewer oversized SQL responses
✅ Clearer limit guidance for query errors
✅ Less trial and error when trimming result sets

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

…it parameter

When execute_sql responses exceed the token limit, the error message now
suggests both adding a SQL LIMIT clause and using the tool's limit
parameter. Previously only the SQL LIMIT was mentioned, and the general
"add a limit" suggestion was skipped for execute_sql entirely.
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Apr 1, 2026

Code Review Agent Run #0b2e76

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: c4243d6..c4243d6
    • superset/mcp_service/utils/token_utils.py
    • tests/unit_tests/mcp_service/utils/test_token_utils.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@dosubot dosubot Bot added the change:backend Requires changing the backend label Apr 1, 2026
@codeant-ai-for-open-source codeant-ai-for-open-source Bot added the size:M This PR changes 30-99 lines, ignoring generated files label Apr 1, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.42%. Comparing base (a67ca05) to head (c4243d6).
⚠️ Report is 47 commits behind head on master.

Files with missing lines Patch % Lines
superset/mcp_service/utils/token_utils.py 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #39003      +/-   ##
==========================================
- Coverage   64.42%   64.42%   -0.01%     
==========================================
  Files        2536     2536              
  Lines      131103   131107       +4     
  Branches    30434    30436       +2     
==========================================
  Hits        84467    84467              
- Misses      45173    45177       +4     
  Partials     1463     1463              
Flag Coverage Δ
hive 40.08% <0.00%> (-0.01%) ⬇️
mysql 60.94% <0.00%> (-0.01%) ⬇️
postgres 61.02% <0.00%> (-0.01%) ⬇️
presto 40.10% <0.00%> (-0.01%) ⬇️
python 62.61% <0.00%> (-0.01%) ⬇️
sqlite 60.64% <0.00%> (-0.01%) ⬇️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aminghadersohi aminghadersohi merged commit 851bbee into apache:master Apr 3, 2026
72 of 73 checks passed
michael-s-molina pushed a commit that referenced this pull request Apr 6, 2026
qfcwell pushed a commit to qfcwell/superset that referenced this pull request May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend size/M size:M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants