Repository navigation
Bound get_schema results for very wide tables in the SQL toolsets - #74017
Merged
pankajkoti merged 3 commits intoOct 1, 2026
Merged
pankajkoti merged 3 commits into
pankajkoti merged 3 commits into
Conversation
SQLToolset and DataFusionToolset exposed get_schema with no bound on the number of columns returned. On a table with thousands of columns the result is a six-figure-byte payload, and because an agent calls get_schema before it can write a query, that payload enters message history early and its cost is re-paid on every later model request. A prior change bounded the query tool but deliberately left get_schema alone, because column names are what the agent needs to write SQL, so truncating to the first N columns would leave it unable to reference or discover the rest. The bound therefore filters and summarizes rather than truncating. An optional name_contains substring lets the agent ask for the columns relevant to its question, and above the column cap or the byte budget the full list is replaced by a summary that reports the shape (column count, a type histogram, a sample of columns) and points back at the filter, matching the query tool's bounded-output contract. Co-Authored-By: Claude <[email protected]>
pankajkoti
force-pushed
the
bound-get-schema-results-for-wide-tables-sql-toolsets
branch
from
October 1, 2026 09:49
9c43264 to
f710a8d
Compare
pankajkoti
marked this pull request as ready for review
October 1, 2026 14:29
pankajkoti
requested review from
Lee-W,
ashb,
gopidesupavan and
kaxil
as code owners
October 1, 2026 14:29
kaxil
reviewed
Oct 1, 2026
Review found that sampling the first max_columns columns made the summary about as large as the list it replaced and dropped the tail, which is the truncate-to-first-N behaviour the design set out to avoid. The preview is now a small fixed sample, so the summary stays far smaller than the full list at any table width while still pointing the agent at the name_contains filter. Alongside that, from the same review: when the histogram alone does not fit the budget it is dropped but the sample is still filled, the summary hint is worded from the limit it actually hit and pluralized, the no-match hint no longer sends the agent back to the same filter on a wide table and now carries total_columns, the changelog tells callers to check truncated before reading columns, and max_result_bytes is documented as also bounding get_schema. Adds tests for the byte-budget contract and that each toolset forwards its own bounds. Co-Authored-By: Claude <[email protected]>
pankajkoti
force-pushed
the
bound-get-schema-results-for-wide-tables-sql-toolsets
branch
from
October 1, 2026 16:39
ab78b84 to
9f45867
Compare
kaxil
reviewed
Oct 1, 2026
A column too wide for the remaining budget now skips rather than stopping the sample loop, so a wide struct type at the front of the preview window no longer leaves sample_columns empty. The preview is an unordered illustration of names, so there is no prefix to preserve. Also pins the max_columns boundary: exactly the cap returns the full list, one more summarizes by count, and exactly the cap over the byte budget summarizes by bytes. Co-Authored-By: Claude <[email protected]>
kaxil
approved these changes
Oct 1, 2026
pankajkoti
deleted the
bound-get-schema-results-for-wide-tables-sql-toolsets
branch
October 1, 2026 19:11
This was referenced Oct 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
get_schemainSQLToolsetandDataFusionToolsetreturned every column of atable with no bound. On a table with a few thousand columns that is a
six-figure-byte tool result, and because an agent calls
get_schemabefore itcan write a query, the result enters message history early and its cost is
re-paid on every later model request. On a several-thousand-column table an
agent could exhaust its context before issuing a single query, even after
#71317 bounded the
querytool.#71317 deliberately left
get_schemaalone, because the same fix does nottransfer: column names are the information the agent needs to write SQL, so
truncating to the first N columns leaves it unable to reference or discover the
rest.
How
get_schemanow mirrors thequerytool's bounded-output contract:{"columns": [{"name", "type"}, ...], "column_count": N}instead of a bare list.name_containssubstring filter, so the agent can askfor the columns relevant to its question on a wide table.
max_columns(new constructor argument, default 100) or the existingmax_result_bytesbudget, the full list is replaced by a bounded summary:column_count, atype_histogram, asample_columnspreview, andtruncated/truncated_by/hintthat name the limit hit and point backat
name_contains.Both toolsets move together. The shared logic lives in
build_schema_resultnext to
build_query_resultinquery_results.py. The provider changelogrecords the tool-result shape change, and the toolset docs gain a "Bounded
schema results" section.
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.8) following the guidelines
🤖 Generated with Claude Code