Text-to-SQL systems increasingly rely on context banks: curated collections of example queries, metric definitions, and domain knowledge that tell a model how an organization writes its queries. In the enterprise, a bank grows over years as many analysts add entries, checked one at a time for correctness (does the SQL answer its own question?) and rarely for consistency with one another. Yet correctness is often loosely defined: a question seldom fixes how an entity is counted or which table defines it, so two entries can each pass review yet resolve the same decision in opposite ways. We call this condition context bank rot. A second question follows: does a system that uses a bank generalize from it, or only reproduce it? Existing benchmarks cannot tell, as they do not control how far a test question sits from the context. We answer both questions by comparing queries decision by decision, with a fast scorer distilled from human-calibrated LLM judges. Turned inward, the comparison diagnoses and repairs a bank. Fine-tuning on a cleaned BIRD-train bank beats a same-size random subset at every epoch (+2.6 points on average), and 92.4% of our removals had their SQL corrected by an independent expert audit, against 45.6% of audited entries. In-context examples that follow one convention beat those following the opposite one by 13.3 points, while a mix is barely better than none. Turned outward, the comparison generates test questions at a controlled distance from a bank, a pipeline we call CAT (Context-Aware Testing). On CAT-BIRD, for retrieval and fine-tuning alike, the benefit of a bank falls step by step with distance and is largely gone once about three quarters of a question's logic is new, and on CAT-Spider the benefit of retrieval likewise shrinks with distance.
Figures & tables
(a) Licensed Value Change p=(0.80,0.00,0.20)
(b) Convention Conflict p=(0.00,0.33,0.67)
eA/eB : “ Schools in Amador / in Alameda with Low Grade 9, High Grade 12? ” SELECT COUNT(T1.‘School Name‘) ... WHERE T2.County = ’Amador’|’Alameda’
eA : “ Accounts in Tabor eligible for loans (type=’OWNER’). ” ... JOIN disp T3 ON T1.account_id = T3.account_id WHERE T3.type = ’OWNER’ eB : “ How many accounts in Prague are eligible for loans ? ” ... INNER JOIN loan T3 ON T1.account_id = T3.account_id
Reading: 4 of 5 roles identical; the county differs, but each question names its own county, so β=0 .
Reading: One shared role: eA follows its domain note ( disp ), eB joins loan . Both pass per-entry review; only the comparison reveals that the bank defines one concept two ways.
Figure 1: Two entry pairs with their ACN profiles p=(α,β,ω) . A value that each question names for itself is a difference but not a conflict (a); a shared role realized two incompatible ways is a conflict (b). Both pairs are real and taken from BIRD.
Bank
Dialect
Entries
Overlapping pairs
Conflict c
Duplicate d
BHI
BIRD-train (69 DBs)
SQLite
6,980
81,398
0.053
0.033
86.8
BIRD-dev (11 DBs)
SQLite
1,534
20,245
0.051
0.016
88.6
Spider-train, subset (42 DBs)
SQLite
3,001
29,210
0.008
0.111
87.4
LiveSQLBench (18 DBs)
PostgreSQL
270
203
0.187
0.000
66.1
Table 1: Bank Health Index of four public context banks before cleaning (rates are shares of overlapping pairs). Spider-train: medium and harder questions in its 42 largest databases. LiveSQLBench ( 15 entries per database) is pooled. BIRD-dev is held out from scorer training; the other banks contributed training pairs (the 6 held-out LiveSQLBench databases alone give c=0.235 , BHI 58.6 ).
Training set
BHI
Base
Ep. 1
Ep. 2
Ep. 3
Ep. 4
Ep. 3, moderate
Ep. 3, challenging
Bad-kept ( n=5,650 )
85.9
46.5
49.7
51.4
50.3
50.2
40.9
22.9
Random ( n=5,648 )
86.7
46.5
49.0
52.3
52.3
51.3
43.8
25.1
Cleaned ( n=5,648 )
90.7
46.5
52.9
53.9
54.3
54.0
45.6
28.1
Table 2: Execution accuracy (%) on BIRD-dev ( n=1,534 ) of Qwen2.5-7B fine-tuned on each training set; BHI scores the training set, and the last two columns split Epoch 3 by BIRD difficulty.
Context in prompt
Paired questions
Outside questions
( n=120 )
( n=151 )
Matched convention
66.7
70.2
Mixed (uncleaned bank)
60.8
62.9
None (zero-shot)
58.3
66.2
Opposite convention
53.3
40.4
Matched − opposite
+13.3 ( p=0.0004 )
+29.8 ( p<10−11 )
Table 3: Execution accuracy (%) of Gemini-3.8-Flash on convention-open BIRD questions under four context conditions. Outside questions belong to no pair and use the R1 examples. The bottom row is matched minus opposite (exact McNemar test); Table 11 splits it by convention.
Model
System
d0
d1
d2
d3
dmax
CAT-BIRD ( n per group)
397
200
200
100
200
Gemini-3.8-Flash
No context
76.8
78.0
76.5
76.0
74.0
Top-3 retrieved
99.0(+22.2)
90.0(+12.0)
87.0(+10.5)
79.0(+3.0)
77.0(+3.0)
Claude-Sonnet-5
No context
75.8
76.5
78.5
78.0
71.0
Top-3 retrieved
96.7(+20.9)
90.0(+13.5)
86.0(+7.5)
77.0(−1.0)
76.0(+5.0)
Qwen2.5-7B
Base (no context)
48.4
35.5
40.0
37.0
33.5
Table 4: Execution accuracy (%) on CAT-BIRD by distance between the test question and the context bank, with group sizes. Parentheses give the gain from the bank: retrieval over no context, and bank fine-tuning over the no-bank control (Qwen) or the base model (Gemma). Fine-tuned rows: epoch 20 , no retrieved context (Appendix G ).
Appendix figures & tables12 assets
Supplementary material from the paper’s appendix.
Appendix
Evaluation set
Pairs
Align MAE
Align Spearman
Conflict AUC
Held-out BIRD-dev, all
2,879
0.020
0.970
0.982
real pairs
1,690
0.020
0.855
0.872
constructed pairs
1,189
0.021
0.966
1.000
Human calibration set
288
0.057
0.934
0.880
Appendix
Table 5: Accuracy of the scorer. MAE and Spearman are for α^ ; AUC is for β^ .
Step
200
1,000
2,000
3,000
4,000
5,000
Align MAE
0.154
0.114
0.067
0.063
0.059
0.057
Align Spearman
0.700
0.878
0.915
0.932
0.932
0.934
Conflict AUC
0.792
0.848
0.894
0.892
0.883
0.880
Appendix
Table 6: Scorer accuracy on the human calibration set during training ( 5,142 steps, 2 epochs).
Table 8: Two-stage audit of the flagged pairs in california_schools ( n=252 ), by scorer conflict score. Stage 1 rates exclude the 36 pairs whose judge call failed; those pairs are kept, as in Table 10 .
Applies when
Prefers
Exception
R1
The question asks “how many X” and the SQL joins through a one-to-many relationship that can count X twice
COUNT(DISTINCT key of X )
The question asks for occurrences (“how many transactions”)
R2
A “how many X” or “which X” question joins three or more tables, and one path chains sibling tables that each reference X
The join path that passes through X’s own table
–
R3
The question names a specific value (place, name, code) and the two SQL use different literals
The literal that matches the question text
–
R4
A concept has both a primary column (flag or category) and a derived text column, and the two SQL use different ones
The primary column, unless the question names the derived value
–
R5
The question asks for a date range and the two SQL compare dates differently
BETWEEN on typed dates over string extraction
–
R6
The question asks for “the highest/most” (one answer) and the SQL differ in ORDER BY … LIMIT 1 vs. = MAX(…)
ORDER BY … LIMIT 1
The question asks for all tied rows
Appendix
Table 9: The Track B rulebook. Each rule applies only when its condition holds and the two SQL queries differ in the stated way.
BIRD-dev
BIRD-train
Candidate pairs ( β^≥0.03 )
2,127
3,101
Keep both: no conflicting unit in the ACN profile
1,043
1,368
Keep both: the two questions ask for different things
529
542
Keep both: no error or rule found on recheck
2
2
Remove one side: internal error
68
619
Remove one side: rule
38
64
Appendix
Table 10: Where Track B candidate pairs end. “Keep both” outcomes remove nothing; “internal error” and “rule” remove one side of the pair. Removed entries are counted after deduplication, since one entry can lose several pairs.
Context in prompt
Convention-A gold
Convention-B gold
Matched convention
70.0
63.3
Mixed (uncleaned bank)
66.7
55.0
None (zero-shot)
68.3
48.3
Opposite convention
60.0
46.7
Matched − opposite
+10.0 ( p=0.11 )
+16.7 ( p=0.002 )
Appendix
Table 11: The in-context consistency effect on the paired questions, split by the convention of the gold query ( n=60 per side).
Conflicting examples (% of bank)
No context
0
19.4
33.0
43.2
50.0
Bank BHI
–
75.7
20.4
13.3
8.5
8.9
Gemini-3.8-Flash
57.3
75.2
68.3
65.0
59.3
58.1
Claude-Sonnet-5
49.2
70.7
66.3
61.8
58.9
54.1
Appendix
Table 12: Execution accuracy (%) on 246 held-out real BIRD and Spider questions, with their original gold SQL, as conflicting examples are added to a deliberately synthesized bank in which every entry is judged defensible. The test questions are the same in every column. The 0% bank follows the same counting and superlative conventions as the test gold; each column adds more entries that follow the opposite convention (bank size 75 to 150 ), removing none. Rows retrieve the 8 most similar bank entries; No context gives the schema only. BHI is computed over this small, targeted bank, so its values are not comparable with Table 1 ; the consistent bank scores below 100 because of its R6 entries (Table 13 ).
Figure 2: Accuracy on the same 246 test questions as the share of conflicting examples in the bank grows (Table 12 ). Solid lines retrieve the 8 most similar bank entries; dashed lines give the schema only.
Model
Subset
n
No context
0%
19.4%
33.0%
43.2%
50.0%
Bank BHI
R1
–
100.0
5.4
1.3
0.9
1.2
R6
–
71.0
26.8
19.7
13.5
14.1
Gemini-3.8-Flash
R1
126
47.6
73.0
64.3
59.5
50.0
48.4
R6
120
67.5
77.5
72.5
70.8
69.2
68.3
BIRD
181
49.7
72.4
64.1
60.8
51.9
50.8
Spider
65
78.5
83.1
80.0
76.9
80.0
78.5
Appendix
Table 13: Table 12 split by rule and by source (execution accuracy, %). Bank BHI is per rule.
Model
System
d0
d1
d2
d3
dmax
CAT-Spider ( n per group)
314
200
149
90
200
Gemini-3.8-Flash
No context
81.2
80.5
73.8
77.8
85.5
Top-3 retrieved
95.5(+14.3)
87.5(+7.0)
75.8(+2.0)
76.7(−1.1)
89.5(+4.0)
Claude-Sonnet-5
No context
76.1
75.0
69.8
75.6
77.5
Top-3 retrieved
94.6(+18.5)
87.5(+12.5)
76.5(+6.7)
80.0(+4.4)
83.5(+6.0)
Qwen2.5-7B
Base (no context)
57.0
57.0
43.6
41.1
59.5
Appendix
Table 14: Execution accuracy (%) on CAT-Spider, as in Table 4 . Unlike CAT-BIRD, CAT-Spider’s d2 and d3 are not matched to d0 on no-context accuracy, and its dmax is matched on hardness levels only.
Run
Epoch
d0
d1
d2
d3
dmax
Qwen2.5-7B, bank
0
48.4
35.5
40.0
37.0
33.5
2
65.0
46.0
43.5
44.0
47.5
5
84.1
57.5
48.5
46.0
46.5
10
90.9
56.0
44.5
43.0
45.5
15
91.7
55.0
45.0
40.0
47.5
20
92.4
55.0
45.5
41.0
48.0
Appendix
Table 15: Per-epoch execution accuracy (%) of fine-tuned systems on CAT-BIRD (selected epochs).
Text-to-SQL enables natural language access to databases, and recent LLMs have substantially advanced its capabilities. Existing benchmarks such as Spider, BIRD, and Spider~2.0 evaluate schema generalization, large-scale databases, and realistic workflows, but largely overlook enterprise scenarios where SQL generation depends on private business knowledge, such as internal metrics, reporting conventions, and organizational rules. We introduce EntSQL, an enterprise-oriented Text-to-SQL benchmark for evaluating long-context grounding over proprietary business documents. EntSQL contains 1,066 aligned Chinese-English semantic examples across five business domains, with most examples requiring domain knowledge beyond the question and schema and involving complex SQL structures. On English inputs, the best evaluated system reaches only 15.9% when long-form documents are provided, highlighting the difficulty of grounding SQL generation in enterprise knowledge.
Chengxi Liao, Tao Xu, Zulong Chen +7
1HKUST (GZ) · 2Alibaba Group · 4Guangdong Laboratory of Artificial Intelligence and Digital Economy (SZ) +1
Recent work has shown that reinforcement learning from execution feedback can substantially improve text-to-SQL performance, often enabling smaller models to match or exceed much larger systems. However, most existing approaches treat SQL generation as a single-turn task, limiting the model's ability to recover from errors through iterative refinement. We present ReToolSQL, a two-stage training framework for text-to-SQL that combines (i) a supervised warm-start on rejection-sampled reasoning traces with (ii) agentic reinforcement fine-tuning (RFT) over multi-turn tool-use trajectories. The key insight is that the two stages act on complementary axes, the supervised fine-tuning (SFT) on verified privileged-teacher traces expands the set of solvable questions (raising pass@k coverage on the hardest cases), while RFT converts that expanded capability into higher single-pass accuracy by teaching the model when to verify, what evidence to retrieve, and how to repair faulty SQL from execution feedback. Applied to Gemma 4 instruction-tuned (31B), RFT alone achieves 73.66% execution accuracy (EX) on the BIRD-SQL development benchmark (74.12% EX with self-consistency). Initializing RFT from the SFT checkpoint (SFT→RFT) yields our strongest model at 74.32% EX single-pass and 74.77% EX with self-consistency. At the time of writing, this ranked first on the BIRD single-model development-set leaderboard. The approach uses composite rewards anchored on execution correctness, requires no human annotation beyond the benchmark itself, and operates within a single dense 31B model, showing that a properly designed SFT→RFT pipeline over tool-use trajectories is a practical path toward robust enterprise-grade text-to-SQL.
Translating natural language questions to SQL queries (Text-to-SQL) is a long-standing problem in database research. Recent efforts have focused on improving accuracy by building increasingly complex multi-stage large LLM pipelines, layering task decomposition, schema linking, and model-based query selection on top of an LLM. Despite this growing complexity, a substantial gap (>10%) between such systems and human experts persists on benchmarks, suggesting that pipeline engineering alone has hit a ceiling. We show that human-level Text-to-SQL performance is achievable by fine-tuning an LLM using RLVR on clean data, without pipeline components. In this paper, we identified the dominant bottleneck for RLVR on Text-to-SQL: existing training data contains pervasive annotation errors that mislead optimization. To address this, we developed a multi-round, expert-driven verification pipeline and used it to curate BIRD-Platinum, a dataset of 2.5k verified instances sampled from BIRD Train, with errors corrected in 61% of instances. We show that fine-tuning Qwen3-235B on BIRD-Platinum yields consistent improvements (11-16%) over BIRD Train on Arcwise-Plat (an expert-verified version of BIRD) and Spider2, outperforming SOTA open-source systems by 0.6-16%. Furthermore, we diagnosed two failure modes of standard RLVR on Text-to-SQL. We find that (1) result-based rewards have non-trivial false positive rates, and (2) models systematically ignore the external knowledge in BIRD-style problems. To address them, we propose ReViSQL-BIRD, a specialized reward shaping method that combines result-based rewards with SQL equivalence verification and leverages process rewards for incentivizing external-knowledge use. We fine-tuned Kimi-K2.6 with ReViSQL-BIRD. On Arcwise-Plat, ReViSQL-BIRD-K2.6 is the first method to achieve human-level accuracy (92.96%), outperforming top five open-source systems by 10-22%.