Abstract
Translating natural language questions into SQL queries, known as text-to-SQL, is a long-standing research problem. Effective text-to-SQL synthesis can become very challenging due to (i) the extensive size of database catalogs (descriptions of tables and their columns) and database values, (ii) reasoning over large database schemas, (iii) ensuring the functional validity of the generated queries, and (iv) navigating the ambiguities of natural language questions. We introduce CHESS, a Large Language Model (LLM) based multi-agent framework for efficient and scalable SQL synthesis, comprising four specialized agents, each targeting one of the aforementioned challenges: the Information Retriever (IR) extracts relevant data, the Schema Selector (SS) prunes large schemas, the Candidate Generator (CG) generates high-quality candidates and refines queries iteratively, and the Unit Tester (UT) validates queries through LLM-based natural language unit tests. Our framework offers configurable features that adapt to various deployment constraints, including 1) Supporting industrial-scale databases: leveraging the Schema Selector agent, CHESS efficiently narrows down very large database schemas into manageable sub-schemas, boosting system accuracy by approximately $2\%$ and reducing the number of LLM tokens by $\times 5$. 2) State-of-the-Art privacy-preserving performance: Among the methods using open-source models, CHESS achieves state-of-the-art performance, resulting in a high-performing, privacy-preserving system suitable for industrial deployment. 3) Scalablity with additional compute budget: In settings with high computational budgets, CHESS achieves $71.10\%$ accuracy on the BIRD test set, within $2\%$ of the leading proprietary method, while requiring approximately $83\%$ fewer LLM calls.
Introduction
While Large Language Models (LLMs) like GPT-4 have demonstrated impressive capabilities in translating human questions into database queries (text-to-SQL), real-world industrial databases present significant hurdles. These environments often feature "messy" data, ambiguous column names, and massive catalogs containing thousands of tables and columns. Existing systems frequently struggle with the "Lost-in-the-Middle" problem, where LLMs lose track of relevant information in massive prompts, leading to a significant accuracy gap compared to human experts. Furthermore, ensuring the reliability of generated queries without incurring prohibitive computational costs remains a major challenge for production-ready systems.
The CHESS Framework
CHESS is a multi-agent framework designed to be modular, efficient, and privacy-preserving. It decomposes the text-to-SQL pipeline into four specialized roles:
- Information Retriever (IR): Employs a hierarchical approach using Locality Sensitive Hashing (LSH) for fast syntactic matching and vector databases for semantic context, enabling efficient retrieval across millions of rows.
- Schema Selector (SS): Acts as a pruning engine to iteratively narrow down massive schemas into manageable sub-schemas. For databases with over 4,000 columns, the SS can filter down to the most relevant ~10 columns, drastically reducing token consumption.
- Candidate Generator (CG): Generates SQL from the pruned context and utilizes a Revise Tool to execute queries, catch errors, and iteratively refine the output.
- Unit Tester (UT): Generates natural language unit tests to verify that the query accurately answers the user's question, ranking candidates based on test performance.
Experimental Evaluation
The framework was evaluated on several benchmarks, including BIRD (large-scale, complex), Spider (cross-domain), and a custom Synthetic Industrial-scale Schema designed to test the limits of schema pruning with 4,337 columns.
Key Results
CHESS achieved a state-of-the-art 71.10% execution accuracy on the BIRD test set, placing it within 2% of the top proprietary methods while requiring 83% fewer LLM calls. On the Spider benchmark, it reached 87.2% accuracy, outperforming established baselines like DIN-SQL.
Discussion and Insights
A primary finding is that schema pruning is a performance multiplier. For massive schemas, the Schema Selector (SS) boosted accuracy by 2% by removing prompt noise, allowing the LLM to reason more effectively. Additionally, CHESS demonstrates that open-source models (like Llama-3-70B) can compete with proprietary cloud-based systems when deployed within a specialized agentic framework, offering a viable path for privacy-preserving industrial applications.
Conclusion
CHESS addresses the scalability and reliability challenges of industrial text-to-SQL synthesis through a specialized multi-agent architecture. Future work will focus on fine-tuning smaller, specialized models for individual agent roles and improving the system's ability to handle inherent natural language ambiguities through proactive clarification.
Summary updated