SQL-of-Thought: Multi-agentic Text-to-SQL with Guided Error Correction
Saumya Chaturvedi, Aman Chadha, Laurent Bindschaedler · 2025
Read SQL-of-Thought: Multi-agentic Text-to-SQL with Guided Error Correction by Saumya Chaturvedi, Aman Chadha, Laurent Bindschaedler (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2509-00581.txt.
Introduction
Saumya Chaturvedi, with two co-authors, Aman Chadha and Laurent Bindschaedler, builds SQL-of-Thought, a system that turns plain questions into SQL, the language used to query databases. Better text-to-SQL widens access to data for people who do not write code.
Chaturvedi and her co-authors split the task among agents for schema linking, matching words to tables, subproblem finding, query planning, SQL writing, and a guided correction loop. Unlike systems that only fix errors by running the query, theirs uses a taxonomy, a classified list of error types, to guide dynamic fixes, with in-context learning and chain-of-thought reasoning, step-by-step thinking. The method reaches leading results on the Spider dataset and its variants.
Catalog record
| CREATOR | Saumya Chaturvedi, Aman Chadha, Laurent Bindschaedler |
|---|---|
| YEAR | 2025 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 30 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2509-00581
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
SQL-of-Thought: Multi-agentic Text-to-SQL with Guided Error Correction Saumya Chaturvedi, Aman Chadha, Laurent Bindschaedler Abstract Converting natural language queries into SQL queries is a crucial challenge in both industry and academia, aiming to increase access to databases and large-scale applications. This work examines how in-context learning and chain-of-thought can be utilized to develop a robust solution for text-to-SQL systems. We propose SQL-of-Thought: a multi-agent framework that decomposes the Text2SQL task into schema linking, subproblem identification, query plan generation, SQL generation, and a guided correction loop. Unlike prior systems that rely only on execution-based static correction, we introduce taxonomy-guided dynamic error modification informed by in-context learning. SQL-of-Thought achieves state-of-the-art results on the Spider dataset and its variants, combining guided error taxonomy with reasoning-based query planning. 1 Introduction Text-to-SQL (NL2SQL) has emerged as a crucial problem in both research and real-world applications, enabling non-technical users to query structured databases through natural language. While early sequence-to-sequence and schema-aware models improved accessibility, they often struggled with generalization, resulting in subpar performance. Recent advances in large language models (LLMs) and prompting techniques have significantly raised performance, with methods such as DIN-SQL [ 11 ] and DAIL-SQL [ 5 ] decomposing the task into subtasks. However, as highlighted by Li et al. [ 7 ] and Biswal et al. [ 1 ] , even the most advanced systems remain brittle when dealing with realistic queries. This is because execution-based feedback alone cannot correct logically incorrect, yet syntactically valid, SQL queries. Multi-agent approaches [ 21 , 12 , 14 ] and reasoning-guided prompting [ 19 , 10 ] have shown potential to bridge this gap. Multi-agent systems enhance modularity and specialization; however, their error correction still relies heavily on execution signals or static re-generation. On the other hand, reasoning-based methods improve query planning, yet unguided reasoning can often introduce new errors or inefficiencies. What is needed is a systematic way to combine multi-agent decomposition with structured reasoning and interpretable correction. We tackle this issue using SQL-of-Thought, a multi-agent framework designed to enhance SQL queries. This framework incorporates several key components: (i) specialized agents for schema linking, identifying subproblems, generating query plans, synthesizing SQL, and correcting errors; (ii) a taxonomy-guided error correction loop that categorizes SQL failure modes and rectifies them through a Chain of Thought reasoning process; and (iii) an analysis comparing reasoning and non-reasoning models across different agent roles. Our framework achieves state-of-the-art execution accuracy on Spider [ 22 ] , Spider-Realistic [ 3 ] , and Spider-SYN [ 4 ] , while also showcasing effective cost-performance trade-offs through the use of hybrid models. These results demonstrate that compact, guided reasoning, paired with structured error feedback, is a more reliable approach for SQL querying than solely relying on execution-based refinement. We make the following contributions: • SQL-of-Thought: A novel multi-agent solution for NL2SQL, complete with Schema Linking, Subproblem identification, Chain of Thought (CoT) for query plan generation, SQL generation, and an explicit error correction loop. • Guided Error Modification driven by a comprehensive Error Taxonomy and In-Context Learning • A detailed analysis of Reasoning and Non-reasoning model choices for SQL-of-Thought • State of the Art results on Spider [ 22 ] benchmark and its variations: Spider-Realistic [ 3 ] , and Spider-SYN [ 4 ] . Figure 1: Architecture of SQL-of-Thought. The process begins as the user asks a natural language question. The relevant schema is fetched from the database, and sent alongwith the question to Schema Linking agent, which extracts the useful tables and columns needed to solve the question. This cropped schema and the question is sent to the Subproblem agent, which divides the problem into smaller, clause-wise subproblems. Then the Query Plan Agent is invoked, using Chain of Thought to procedurally generate an executable Query Plan. This query plan is used by the SQL Agent to generate a valid SQL solution, which is then executed on the DB Execution engine. If the execution fails, the correction loop is invoked, with the execution error, error taxonomy, and incorrect SQL sent to the Correction Plan Agent, to investigate the error and generate a Correction Plan using a CoT-guided rectification mechanism to fix it. The Correction SQL Agent uses this plan to generate the correct SQL query. The Guided Correction Loop is invoked until the query is successful or maximum attempts are finished. 2 Related Work 2.1 History of NL2SQL Initial works for Text-to-SQL used major sequence-to-sequence architectures such as PLMs (Programming Language Models), for example RESDSQL [ 8 ] , which identified relevant schema from the question and then used it to construct the SQL query. Other choices were GNNs (Graph Neural Networks), Recurrent Neural Networks (RNNs), Transformers, and most recently LLMs for natural language to SQL conversion. With the advent of LLMs, prompt engineering on powerful models like GPT [ 2 , 9 ] and Claude enabled fine-grained and faster solutions for NL2SQL. Shi et al [ 16 ] highlights how LLM-based solutions outperformed all other alternatives for programming text-to-SQL. DIN-SQL [ 11 ] attempted in-context learning with error correction, decomposing subproblems, and defining different prompt templates to tackle each subtask. However, their method only regenerates prompts in case of failure, without specific error information. DAIL-SQL [ 5 ] designs sophisticated SQL-code style prompt templates to encode the question and database schema. These templates provide few-shot examples for schema linking and SQL query generation, utilizing GPT-4 to generate solutions. DAILSQL-SC employs self-consistency to postprocess solutions for further refining. Some studies [ 7 ] discuss production readiness and evaluation frameworks for NL2SQL using various prompting methods, again verifying that LLM-based approaches generally outperform pretrained task-specific models through higher reliability and generalization. They classify queries into four categories: subqueries, joins, logical connectors, and order-by clauses, to measure model efficacy across increasing levels of difficulty. The TAG framework [ 1 ] showed how existing models fail on complex real-world queries, highlighting that most NL2SQL models and benchmarks are only effective for roughly 20% of realistic user queries. They introduce a reasoning framework that decomposes the problem into three stages: (i) query synthesis through NL2SQL parsing, (ii) query execution over the underlying database, and (iii) answer generation, where an LLM integrates both the natural language query and execution results to produce a final human-readable answer. The TAG framework [ 1 ] demonstrated how existing models struggle with complex real-world queries and proposed steps for query synthesis, execution, and answer generation. Multi-agent frameworks, such as Wang et al. [ 20 ] , introduced syntax validation and execution optimization, but relied mainly on execution feedback. 2.2 Agentic Approaches Tool-SQL [ 21 ] pioneered the tool-first agentic framework, where an LLM-based agent iteratively generates and refines SQL queries with the aid of two tools: a database retriever to resolve condition mismatches and an error detector for stricter constraint validation. The approach primarily addressed database mismatches, such as missing highlights, altered paraphrasing, and similar issues. Chase SQL [ 12 ] defines an elaborate framework consisting of value retrieval, multiple candidate generators and query fixers, and a selection agent. The candidates generate a query plan by prompting the LLM through an "EXPLAIN" keyword. The multi-agent framework proposed by Shao et al. [ 14 ] introduces a four-agent system where specialized roles (developer, researcher, executor,