Representation and retrieval
- Teacher-model output distribution → semantic intent graph
- Intent-graph fragments → retrieval of SQL building blocks
- Component-removal tests (ablations) isolate parser, retriever, and assembler errors
SQLHarness translates business questions into a structured query description and SQL building blocks, then checks the resulting SQL before allowing execution. The research asks whether this structure can produce more accurate queries for a given cost than a language model generating SQL directly.
The pipeline separates research on query representation and retrieval from the checks that control execution.
| Stage | Input or responsibility |
|---|---|
| Business request | Natural language, database schema, and task evidence. |
| Intent graph | Explicit entities, constraints, operations, and relations. |
| Fragment retrieval | SQL building blocks retrieved using the intent graph for lightweight assembly. |
| Authority boundary | SQL syntax-tree (AST), schema, policy, timeout, and execution-limit checks. |
A generated query can be valid SQL and still answer the wrong question. SQLHarness separates the request’s meaning, the SQL structures available for retrieval, and permission to execute. This makes a failure attributable to a stage instead of treating every wrong result as a prompt problem.
The repository’s version 0.2 example represents “Which region has the most customers?” with a customer entity, a region attribute, a count operation grouped by region, and an argmax operation limited to one result. Directed edges connect the count to its customer target and region grouping; the output returns the region constrained by that maximum.
Retrieval uses the graph to select parameterized SQL building blocks; the assembler receives the graph, selected fragments, and database schema to propose SQL. The necessary operations here are joining customers to regions, grouping, counting, and selecting the largest group. The saved graph is an illustrative contract example, not a recorded model-generated retrieval trace. The executable fixture below separately demonstrates the resulting SQL and authority checks.
Inspect the complete graph, source spans, and schema candidates. Read the architecture contract and proposed training path.
The Model Context Protocol (MCP) server and command-line evaluator call the same DatabaseAuthority. Every exposed execution tool uses these checks: database IDs resolve inside a configured root, SQL is parsed and checked against the schema and read-only policy, and allowed execution uses a read-only SQLite connection with a deadline and row cap.
| MCP tool | Responsibility |
|---|---|
list_databases | List databases inside the configured authority root. |
inspect_schema | Return the selected database’s tables and columns. |
validate_sql | Check syntax, schema references, and policy without executing the proposal. |
explain_sql | Validate the proposal before returning a bounded SQLite query plan. |
execute_readonly_sql | Validate again, then execute under time and row limits. |
Decisions include structured errors and deterministic receipt IDs for tracing. A receipt is an identifier for a decision, not a claim of immutable storage. Read-only enforcement limits database effects; it does not establish that an allowed query answers the business question correctly. Inspect the safety boundary and its limits.
This cached run is produced by the repository’s real validation and execution code. It needs no API key.
Business request: Which region has the most customers?
Task evidence: Count customers by region and return only the largest group.
SELECT r.name, COUNT(*) AS customer_count FROM customers AS c JOIN regions AS r ON c.region_id = r.id GROUP BY r.id, r.name ORDER BY customer_count DESC LIMIT 1| Validation and execution | Recorded result |
|---|---|
| Decision | executed |
| Receipt | 0a59a1292a6ef895eea3 |
| Tables | customers, regions |
| Columns | c.region_id, customer_count, r.id, r.name |
| Errors | None |
| Result | Matched reference result; Northeast, 3 customers |
| Latency | 0.21 ms |
Requested operation: Clean up purchases below $10.
DELETE FROM purchases WHERE amount < 10Policy rejection: non_readonly_operations: DELETE. Decision: blocked. Database untouched. Receipt: 794c586a63e3e8bfd993.
Offline demonstration fixture, not a score on the BIRD text-to-SQL benchmark. Its purpose is to prove the harness is executable and the safety path is inspectable.
Every comparison method receives the same fixed BIRD examples, database schema, and evaluation conditions.
Arm A
Question + schema → SQL generated directly by a frontier language model.
Arm B
Intent graph → retrieved fragments → lightweight assembly.
Arm C
Remove each component to measure its actual contribution.
| Evaluation role | Measure |
|---|---|
| Primary | Execution accuracy |
| Efficiency | Cost per correct query |
| Operations | End-to-end latency |
| Diagnosis | Errors classified by pipeline stage |
The structured system did not improve the accuracy–cost tradeoff on this small comparison. That negative result is preserved beside the component evidence and governed execution path.
Frozen comparison · 20 train / 5 held out
| Measure | Observed |
|---|---|
| Direct model (Astra) correct | 4/5 |
| SQLHarness with dense retrieval correct | 3/5 |
| SQLHarness with learned retrieval correct | 3/5 |
| Queries left unanswered by parser | 1 |
| Method | Reported usage and latency |
|---|---|
| Direct generation | 5.61 s mean model latency · 77,327 tokens |
| SQLHarness with learned retrieval | 67.23 s mean observed latency · 142,764 reported tokens |
Five-example development comparison. SQLHarness tokens cover four completed pipelines and omit the timed-out parser, so they understate true consumption. The latency fields also differ: direct generation reports model latency, while the structured result combines recorded parser and assembler latency. The fixed-version BIRD per-query evaluator reproduces the 80% versus 60% scores. Read the complete result and error decomposition.
First held-out vertical slice · 3 examples
| Measure | Observed |
|---|---|
| Direct model correct | 2/3 |
| SQLHarness correct | 2/3 |
| Parser-timeout abstention | 1 |
| Training examples → fragments | 7 → 48 |
| Method | Reported usage and latency |
|---|---|
| Direct generation | 6.35 s/query · 45,546 tokens across 3 |
| SQLHarness v0.1 | 46.19 s/completed query · 70,197 tokens across 2 |
Three-example development comparison. The third direct query followed conflicting benchmark
evidence (COUNT > 2) instead of the question and reference SQL (COUNT >= 2);
SQLHarness timed out before answering it. Read the full failure analysis.
Fragment retrieval isolated · lexical / dense / learned · 20/5 split
| Measure (Recall@3: share of required SQL structures found within the top 3 candidates) | Observed |
|---|---|
| Required exact SQL structures present in catalog | 58.82% |
| Lexical Recall@3 | 15.38% |
| Dense Recall@3 | 23.08% |
| Learned Recall@3 | 15.38% |
Five-example development comparison; four graphs were available and three queries had a relevant exact structure in the catalog. Dense BGE-small reaches 23.08% Recall@12; the learned ranker improves Recall@1 but falls to 15.38% at rank 12. Only 58.82% of the required exact SQL structures exist in the catalog, limiting what any retrieval method can return. Read the retrieval analysis.
The five-query comparison exposed different ceilings: one parser timeout prevented assembly, and the 20-example fragment catalog contained only 58.82% of the exact SQL structures required by the held-out set. Ranking cannot recover a structure absent from the catalog. The learned ranker improved the first result but lost relevant structures farther down the list, without changing final correctness.
Those observations favor expanding the catalog and distilling the parser before further ranker tuning. Repeated teacher samples also had much less agreement on graph edges than nodes, so teacher graphs are treated as candidates to refine rather than unquestioned training labels. These are next research hypotheses, not measured improvements.
The 500-example preflight below checks whether reference queries can run within local limits. The five-query CLI pilot checks the direct generation path. The initial seven-train/three-held-out slice tests an early structured pipeline; the later 20-train/five-held-out comparison tests the expanded system and retrieval variants. Their scores describe different development experiments and are not pooled into one benchmark result.
Arm A preflight
| Preflight check | Observed |
|---|---|
| Frozen examples | 500 |
| SQLite databases | 11 |
| Reference queries executed within local limits | 99.6% (498/500) |
| Result truncations | 0 |
This preflight tests reproducibility rather than model performance. The official BIRD evaluator determines the final score.
Development pilot · Codex CLI / GPT-6 Astra
| Measure | Observed |
|---|---|
| Locally correct | 4/5 |
| Valid SQL | 5/5 |
| Mean model latency | 6.34s |
| CLI-reported tokens | 75,206 |
Five-query diagnostic run. The single rejection selected the correct entity but returned an extra aggregate column, causing a strict result-shape mismatch. CLI usage is not assigned API cost because it runs through the authenticated Codex product runtime.