Repository navigation
Validate SQL output column contracts in MCP tools - #333
Open
seyoung4503 wants to merge 5 commits into
Open
seyoung4503 wants to merge 5 commits into
seyoung4503 wants to merge 5 commits into
Conversation
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.
SQL execution success currently cannot distinguish a correct projection from missing or extra output columns. Previously observed failures include returning the right values with an extra identifier, or returning selected entities without a requested measure.
Add optional
expected_columnstorun_sql: compare exact ordered labels against actual result metadata and return an MCP error with missing/unexpected columns on mismatch. SQLAlchemy preserves labels even for zero rows using a list-compatible result. Empty results from legacy adapters without metadata explicitly fail verification; calls without a contract retain their behavior. Bound Oracle metric mode explicitly rejects this SQL-only option.This is deterministic validation of a caller-supplied contract, not automatic natural-language interpretation, type/row-count/uniqueness validation, or proof of semantic accuracy. A wrong or omitted contract can still produce a wrong answer. No system prompt, grader, gold data, or benchmark thresholds changed. Based on #332; later prompt experiment branches are not included.
Validation: 6 new stdio MCP scenarios failed before implementation and pass afterward; root tests 284 passed / 1 skipped; offline Ruff and diff checks pass. Invalid contracts never execute SQL; legacy empty-result behavior is covered. Targeted ChatGPT-auth Codex evaluation completed: bird165 0/1, local220 0/1, both successfully executed but officially incorrect. The model used
expected_columns, yet chose the wrong output contract: BIRD included an extra average column; Spider used a one-row/two-player layout. No accuracy improvement demonstrated.The first attempt exposed a regression introduced here: a success-message prefix displaced the row-count header, causing execution-provenance rejection. Fixed the renderer without loosening the verifier, added real-MCP-to-verifier tests, and reran only those failures. Both initial failures and corrected runs are archived under
bench/accuracy/mcp-review-results/output-columns/, including raw events, records, settings, scores, analysis and SHA256 index. Benchmark-generated provider-call/token zero placeholders are marked unknown in copied summaries; actual CLI usage remains in traces. Bound metric rejection and failed-contract audit are also tested.Implementation verification — reused RunSQL, DefinitionCheckedSQL schema/delegation, SQLAlchemy worker, existing safety/audit/rendering and MCP test fixture. Net +117 implementation/test lines.