TL;DR
AV-SQL is a novel multi-agent framework that tackles the challenge of generating complex SQL queries over massive, real-world database schemas. By breaking large schemas into manageable chunks and generating verifiable intermediate "agentic views" (Common Table Expressions), it prevents error propagation and achieves a state-of-the-art 70.38% execution accuracy on the rigorous Spider 2.0 benchmark in a fully zero-shot setting.
What Problem Does This Paper Address?
While Large Language Models (LLMs) have gotten incredibly good at translating natural language into SQL (Text-to-SQL), they hit a wall when confronted with enterprise-scale databases. Real-world schemas often contain hundreds of tables and thousands of columns, easily exceeding an LLM's context window or diluting its attention.
When traditional systems attempt to generate a single, monolithic SQL query from a massive schema, they frequently suffer from two major issues:
- Schema-linking mistakes: Hallucinating column names or joining tables on incorrect keys.
- Entangled errors: A single query might contain a mix of syntax errors, incorrect joins, and bad filters. Because database execution feedback only reports the first error it encounters, debugging these monolithic queries holistically becomes nearly impossible.
Methods
AV-SQL introduces a multi-stage pipeline powered by specialized LLM agents that decompose the problem into smaller, verifiable steps.
- Preprocessing & Schema Compression: To fit large databases into LLM prompts, AV-SQL clusters near-duplicate tables and columns (e.g., grouping
sales_2023andsales_2024into a single pattern). It then splits the compressed schema into length-based chunks. - Question Rewriting: A rewriter agent reformulates the user's query and filters out noisy external knowledge, producing a highly explicit, structured prompt.
- Agent View Generation (The Core): Instead of writing the final query, view-generator agents examine individual schema chunks and produce agentic views—executable Common Table Expressions (CTEs) that handle localized logic (like filtering a specific table). Crucially, these intermediate CTEs are executed against the database immediately. If they fail, an iterative validation-and-repair loop fixes them before moving forward.
- SQL Generation: Finally, three collaborative agents—a Planner (creates a high-level query plan), a SQL Generator (composes the final query using the validated CTEs), and a Revisor (verifies semantic correctness)—assemble the final executable SQL.
Datasets
The authors evaluated AV-SQL across several prominent Text-to-SQL benchmarks:
- Spider 2.0 (Spider2-Snow): A highly challenging, enterprise-scale benchmark featuring massive schemas (averaging 800 columns per database) and complex multi-step questions targeting Snowflake dialects.
- BIRD: A large-scale professional domain benchmark.
- Spider (1.0): The standard cross-domain benchmark for multi-table SQL generation.
- KaggleDBQA: A benchmark consisting of real-world web databases with unrestricted user questions.
Key Insights and Ideas
- Decomposition Beats Global Pruning: Traditional methods try to prune the schema globally before generating SQL, which often accidentally discards required join paths. AV-SQL shifts the paradigm by treating chunk-level reasoning as explicit schema filtering via executable code.
- The Power of Verifiable Intermediate Steps: By forcing agents to write independent, executable CTEs for small parts of the schema, errors are isolated. If an agent links a wrong column, the error is caught and repaired at the CTE level, preventing it from corrupting the final query structure.
- Zero-Shot Viability: Unlike many top-performing systems that require complex few-shot exemplar selection or expensive task-specific fine-tuning, AV-SQL achieves state-of-the-art results purely through prompt-based agent coordination.
Key Results
AV-SQL demonstrated massive performance leaps, particularly on large-scale databases:
- Spider 2.0-Snow: Powered by Gemini-3-Pro, AV-SQL achieved 70.38% execution accuracy, dramatically outperforming recent state-of-the-art agentic baselines like ReForCE (35.83%) and AutoLink (34.92%). Standard monolithic approaches like DIN-SQL scored 0.00% because the schemas simply could not fit or function within a single prompt.
- Standard Benchmarks: AV-SQL remained highly competitive on normal-scale datasets, scoring 85.59% on Spider, 72.16% on BIRD, and 63.78% on KaggleDBQA, beating out several multi-candidate and fine-tuned baselines.
Limitations and Future Work
An analysis of AV-SQL's failures revealed that filtering (36.2%) and aggregation (34.1%) errors constitute over 70% of its mistakes. While the framework successfully eliminated most syntax and schema-linking bugs through execution feedback, the agents still occasionally struggle with complex conditional logic and mathematical groupings over large datasets.
The authors note that future work will focus on sharpening the agents' reasoning capabilities for these complex filters and exploring hybrid LLM configurations to optimize computational costs.
Summary updated