Text-to-SQL is the task of translating natural language queries into executable SQL for a given database, enabling non-expert users to access structured data without writing SQL manually. Despite rapid advances driven by large language models (LLMs), existing approaches still struggle with complex queries in real-world settings, where database schemas are large and questions require multi-step reasoning over many interrelated tables. In such cases, providing the full schema often exceeds the context window, while one-shot generation frequently produces non-executable SQL due to syntax errors and incorrect schema linking. To address these challenges, we introduce AV-SQL, a framework that decomposes complex Text-to-SQL into a pipeline of specialized LLM agents. Central to AV-SQL is the concept of agentic views: agent-generated Common Table Expressions (CTEs) that encapsulate intermediate query logic and filter relevant schema elements from large schemas. AV-SQL operates in three stages: (1) a rewriter agent compresses and clarifies the input query; (2) a view generator agent processes schema chunks to produce agentic views; and (3) a planner, generator, and revisor agent collaboratively compose these views into the final SQL query. Extensive experiments show that AV-SQL achieves 70.38% execution accuracy on the challenging Spider 2.0 benchmark, outperforming state-of-the-art baselines, while remaining competitive on standard datasets with 85.59% on Spider, 72.16% on BIRD and 63.78% on KaggleDBQA. Our source code is available at https://github.com/pminhtam/AV-SQL.
Figures & tables
Figure 1. A motivating example from BIRD-dev (sample 501) illustrates the limitations of traditional Text-to-SQL on complex questions over large schemas. Providing the full schema in a single prompt can exceed the context window and increase the risk of syntax and logical errors. Our approach instead splits the schema into smaller chunks, generates and validates agent views (CTE queries: VCTE(1), … VCTE(k) ), and then composes them into the final SQL, improving robustness under long-context constraints.
Notation
Description
Q
Natural language question
K
external knowledge evidence
D
A relational database
S
Schema of the database D
T={T1,T2,…,Tm}
Set of tables in the database D
Ci={c1i,c2i,…,cnii},
Set of columns of table i in the database D
Table 1. Summary of Important Notations
Method
Single candidate
Zero-shot
Handle large DB
DIN-SQL ( Pourreza and Rafiei, 2023 ) , DAIL-SQL ( Gao et al., 2024b ) , MAC-SQL ( Wang et al., 2024 )
✓
✗
✗
MCS-SQL ( Lee et al., 2025 ) , CHESS ( Talaei et al., 2024 )
✗
✗
✗
Alpha-SQL ( Li et al., 2025 )
✗
✓
✗
ReForCE ( Deng et al., 2025 ) , AutoLink ( Wang et al., 2025 )
✗
✓
✓
AV-SQL
✓
✓
✓
Table 2. Comparison of AV-SQL with representative Text-to-SQL methods in terms of (i) single-candidate generation, (ii) zero-shot applicability, and (iii) ability to handle large databases (e.g., Spider 2.0 schemas).
Figure 2. Overview of AV-SQL . The framework begins with preprocessing—schema splitting and vector database initialization for value preprocessing—followed by three main stages: (1) Question Rewriting which reformulates the input question, optionally using external knowledge, into a clearer and more explicit form; (2) Agent View Generation, which decomposes the long-context schema into smaller chunks and produces execution-validated intermediate CTE-based agent views that capture key reasoning steps while identifying relevant schema elements; and (3) SQL Generation, which uses three agents: a planner, a SQL generator, and a revision agent to produce the final executable SQL query from the filtered schema and validated agent views.
Figure 3. Token-length distribution of large database schemas before and after schema compression.
Method
Infer model
BIRD ↑
Spider ↑
Latency(s) ↓
Multi-candidate
MCS-SQL ( Lee et al., 2025 )
GPT-4
63.36
86.80
-
Alpha-SQL-7B ( Li et al., 2025 )
Qwen2.5-7B
66.80
84.00
>1000
Alpha-SQL-14B ( Li et al., 2025 )
Qwen2.5-14B
68.70
87.00
>1000
Alpha-SQL-32B ( Li et al., 2025 )
Qwen2.5-32B
69.70
-
>1000
XiyanSQL-32B ( Gao et al., 2024a )
XiyanSQL-32B
73.34
-
-
Table 3. Execution Accuracy (EX) of our approach compared to baselines on the Spider and BIRD benchmarks.
Method
Easy
Medium
Hard
Extra
CodeS-7B ( Li et al., 2024c )
94.80
91.00
75.30
66.90
CodeS-15B ( Li et al., 2024c )
95.60
90.40
78.20
61.40
DIN-SQL(GPT-4) ( Pourreza and Rafiei, 2023 )
92.30
87.40
76.40
62.70
DAIL-SQL(GPT-4) ( Gao et al., 2024b )
91.50
90.10
75.30
62.70
Alpha-SQl-7B ( Li et al., 2025 )
94.00
89.20
76.40
63.30
Alpha-SQl-14B ( Li et al., 2025 )
94.00
91.00
79.90
72.30
Table 4. Execution Accuracy (EX) across different query hardness levels on the Spider benchmark.
Method
Simple
Mod
Chall
DAIL-SQL(GPT-4) ( Gao et al., 2024b )
63.00
45.60
43.10
MAC-SQL(GPT-4) ( Wang et al., 2024 )
65.73
52.69
40.28
CodeS-7B ( Li et al., 2024c )
64.60
46.90
40.30
CodeS-15B ( Li et al., 2024c )
65.80
48.80
42.40
Alpha-SQL-7B ( Li et al., 2025 )
72.60
59.30
53.10
Alpha-SQL-14B ( Li et al., 2025 )
74.60
61.00
55.90
Table 5. Execution Accuracy (EX) on BIRD dev set by difficulty level. For brevity, the abbreviation ”Mod” stands for ”Moderate” while ”Chall” denotes ”Challenging”
Method
EX (%)
Easy
Medium
Hard
Extra
All
DIN-SQL(gpt-4) ( Pourreza and Rafiei, 2023 )
-
-
-
-
27.00
Incremental ICL ( Fan et al., 2024 ) (gpt-3.5)
-
-
-
-
34.60
RESDSQL ( Li et al., 2023 )
-
-
-
-
31.90
RAT-SQL ( Wang et al., 2020a )
-
-
-
-
13.56
ZeroNL2SQL(gpt-4) ( Fan et al., 2024 )
-
-
-
-
42.40
Table 6. Execution Accuracy (EX) of our approach compared to baselines on the KaggleDBQA dataset.
Method
Infer model
EX ↑
Avg Tokens ↓
SFT CodeS-15B ( Li et al., 2024c )
CodeS-15B
0.00
–
DIN-SQL ( Pourreza and Rafiei, 2023 )
GPT-4o
0.00
32k
CHESS ( Talaei et al., 2024 )
GPT-4o
1.28
–
DAIL-SQL ( Gao et al., 2024b )
GPT-4o
2.20
124k
LC-NL2SQL ( Chung et al., 2025 )
gpt-5-mini
0.00
–
Spider-Agent ( Lei et al., 2024 )
Qwen2.5-32B
5.48
–
Table 7. Execution Accuracy (EX) on Spider 2.0-Snow. Values in parentheses mark cases where the score reported in the published paper differs substantially from the official leaderboard; the parenthesized number corresponds to the leaderboard score.
Method
Infer model
Easy
Medium
Hard
Spider-Agent ( Lei et al., 2024 )
+
o1-preview
39.84
21.14
15.61
+
o3-mini
31.25
18.29
11.56
+
GPT-4o
24.22
11.38
6.94
+
Qwen2.5-32B
4.47
2.31
5.48
AV-SQL
Table 8. Execution Accuracy (EX) by difficulty level (easy/medium/hard) on Spider2-snow dataset
Figure 4. Recall Execution Accuracy on the Spider2.0-Snow benchmark under the multi-candidate setting.
Setting
Spider-2-snow
Spider
BIRD
KaggleDBQA
GPT-5-mini
Gemini-3-Pro
Llama-3.3
Gemini-3-Pro
Llama-3.3
Gemini-3-Pro
Llama-3.3
Gemini-3-Pro
w/o rewriter
57.22
64.90
78.34
84.53
65.45
71.64
48.65
62.16
w/o exe feedback (SQL)
50.82
63.99
80.33
84.91
64.54
71.77
51.35
61.62
w/o exe feedback (CTE+SQL)
41.68
57.77
79.01
84.77
64.47
70.90
50.81
61.08
w/o planner
55.76
63.99
79.40
84.62
65.97
72.23
54.05
61.62
w/o reviseSQL
60.15
65.08
82.50
87.14
67.47
72.82
54.59
65.41
Table 9. Ablation study of major pipeline component–rewriter, planner, revisor, and execution feedback (exe feedback)–measured by Execution Accuracy (EX) across Spider2-Snow, Spider, BIRD, and KaggleDBQA. Llama-3.3 denotes Llama-3.3-70B.
Information provided
Spider2-snow
Spider
BIRD
KaggleDBQA
GPT-5-mini
Gemini-3-Pro
Llama-3.3
Gemini-3-Pro
Llama-3.3
Gemini3-Pro
Llama3.3
Gemini3-Pro
Aggregated Validated Agent Views ( VCTE )
58.68
64.72
79.83
85.42
67.41
71.64
51.89
62.70
Global Schema Selection ( Sfiltered )
57.59
63.25
79.57
84.72
65.71
71.77
50.27
61.62
All outputs ( VCTE + Sfiltered )
65.08
70.38
83.66
85.59
68.19
72.16
53.51
63.78
Table 10. Ablation study on the contribution of each output from the Agent View Generation stage – ( VCTE ) and ( Sfiltered ) – to SQL generation performance (EX) across Spider2-Snow, Spider, BIRD, and KaggleDBQA. Llama-3.3 denotes Llama-3.3-70B.
Method
Infer model
Precision
Recall
MACSQL ( Wang et al., 2024 )
+
Qwen2.5
62.00
63.88
+
Llama 3.3
68.30
68.91
+
GPT-5-Mini
59.41
79.22
+
Gemini-3-Pro
70.62
86.45
CHESS ( Talaei et al., 2024 )
Table 11. Precision and recall of schema filtering across methods and inference models in Spider2-snow dataset.
Figure 5. Token usage and runtime breakdown by pipeline agent for AV-SQL with Gemini-3-Pro on Spider2.0-snow. The left nested donut chart shows the proportion of token usage, while the right pie chart shows the proportion of total runtime spent on each agent.
Figure 6. Error taxonomy of AV-SQL with Gemini-3-Pro on Spider2-snow.
Rewriter
View Gen.
SQL Generation
EX ↑
Planner
SQL Gen.
Revisor
Homogeneous
Llama-3.3
Llama-3.3
Llama-3.3
Llama-3.3
Llama-3.3
27.42
GPT-5-mini
GPT-5-mini
GPT-5-mini
GPT-5-mini
GPT-5-mini
65.08
Gemini-3-Pro
Gemini-3-Pro
Gemini-3-Pro
Gemini-3-Pro
Gemini-3-Pro
70.38
Hybrid
Table 12. Execution Accuracy (EX) on Spider2-Snow under hybrid LLM configurations, where different backbone models are assigned to different agents.
LLM-based agents for text-to-SQL often struggle with latency-performance trade-off, where performance improvements come at the cost of latency or vice versa. We reformulate text-to-SQL generation within the lens of software test coverage where the original query is prepared with a suite of test cases with simpler, atomic SQLs that are executed in parallel and together ensure semantic coverage of the original query. After iterating on test case coverage, the final SQL is generated only when enough information is gathered, leveraging the explored test case SQLs to ground the final generation. We validated our framework on a state-of-the-art benchmark for text-to-SQL, Spider 2.0, achieving a new state-of-the-art with 70.2% execution accuracy.
Text-to-SQL maps natural language questions to executable SQL queries. Modern databases often contain large and complex schemas, making schema linking a critical step for accurate SQL generation. Existing methods either rely on full-schema generation, which leaves schema linking implicit within a large search space, or use a separate retriever trained with static gold-column supervision, whose targets may be suboptimal for the current generator policy. To address this issue, we propose Adaptive Co-optimization via Empirical Credit Assignment for Text-to-SQL (ACE-SQL), a reinforcement learning (RL) framework that jointly optimizes schema retrieval and SQL generation under execution feedback. ACE-SQL constructs an online column-set pool from generator rollouts and derives adaptive on-policy retrieval targets from the column set most frequently associated with execution-correct rollouts. This induces bidirectional adaptation, where the retriever adapts toward column sets that the generator can execute correctly, while the generator adapts to the retriever's evolving schema selections under execution feedback. With approximately 3k synthetic Text-to-SQL question-database pairs for RL training, ACE-SQL achieves 65.3% greedy execution accuracy on BIRD Dev while using 0.93k output tokens per query. The repository is available at https://github.com/xbchen1/ACE-SQL.
Xiaobing Chen, Ai Jian, Eryu Guo +1
Harbin Engineering University, Harbin, China · Harbin Institute of Technology, Harbin, China · Beijing University of Posts and Telecommunications, Beijing, China
Large language models have substantially advanced Text-to-SQL systems, yet applying them to enterprise-scale databases remains challenging. Real-world databases often contain large and heterogeneous schemas, incomplete metadata, dialect-specific SQL syntax, and complex analytical questions that are difficult to solve with a single SQL query. To address these challenges, we propose ProSPy, a Profiling-driven SQL--Python agentic framework for enterprise-scale Text-to-SQL. ProSPy structures the reasoning process into four stages: it first extracts fine-grained data evidence through automatic profiling, progressively prunes large schemas into task-relevant contexts, fetches intermediate views through a dialect-agnostic SQL interface, and finally performs flexible downstream analysis with Python. This design combines the efficiency of SQL over large databases with the flexibility of Python-based analysis, while reducing reliance on unreliable metadata and improving robustness across SQL dialects. Experiments on Spider 2.0-Lite and Spider 2.0-Snow show that ProSPy consistently outperforms strong baselines with both open-source and proprietary models, achieving execution accuracies of 60.15% and 60.51% with Claude-4.5-Opus, without majority voting. Further analysis shows that ProSPy is robust to SQL dialect variations and achieves a favorable trade-off between schema recall and precision.
Zhaorui Yang, Huawei Zheng, Sen Yang +14
1State Key Lab of CAD&CG, Zhejiang University · School of Software Technology, Zhejiang University · 3Tencent TEG +2