SQL queries that large language models write from natural language questions can execute successfully yet produce incorrect results, so execution alone does not reveal what to fix. An error taxonomy says why the query is wrong, but not where to look or how to change it. Existing methods can guide SQL correction through feedback, error reports, or generated plans alongside an unmasked query. We introduce TEG(Taxonomy-guided Error Grounding), which turns a supplied diagnosis into a structured correction input for natural language-to-SQL (NL2SQL) correction. Type-specific rules map each error type to construct classes to reconsider and an edit operation to request. TEG masks the selected constructs in the query when applicable and states that operation in an edit instruction. TEG generates candidate corrections from this input, uses execution feedback to guide candidate selection, and repeats the process one annotation at a time for queries with several errors. On NL2SQL-BUGs, TEG reaches 47.3 single-error execution accuracy and 37.0 overall with Qwen2.5-7B-Instruct. Across the model sizes and thinking modes evaluated in the main comparison, TEG outperforms all evaluated baselines on single-error queries, even when the baselines receive the same error-type annotations. With predicted types, TEG stays above direct LLM correction and ErrorLLM on single-error queries.
Figures & tables
Figure 1: Error grounding maps why a query is wrong to where and how to fix it. TEG masks the constructs selected by the error type and supplies an edit instruction. For an Attribute Mismatch , TEG masks column expressions, allowing the LLM to replace the abbreviated street field schools.streetabr with the required unabbreviated mailing street field T2.MailStreet .
Figure 2: TEG maps error types to masking rules and edit instructions. The where rule masks constructs for Mismatch and Redundancy (1); Missing and Rewrite (2) leave the query unmasked. The how rule specifies the edit. Here, step 1 replaces the masked WHERE predicate for an Explicit Condition Mismatch ; step 2 inserts the missing subquery for Subquery Missing into step 1's output.
Qwen2.5-Instruct
Qwen3-8B
Method
Error types
7B
14B
32B
Thinking OFF
Thinking ON
Base
✗
30.0
35.5
41.8
31.8
43.6
Reasoning and self-correction
CoT ( Kojima et al., 2022 )
✗
35.5
37.3
45.5
33.6
48.2
Self-Debug (Simple) ( Chen et al., 2024b )
✗
33.6
38.2
48.2
38.2
50.9
Self-Debug (Expl) ( Chen et al., 2024b )
✗
29.1
35.5
44.5
44.5
47.3
Table 1: TEG leads single-error correction across the evaluated models. Entries are execution accuracies (%) on single-error queries from NL2SQL-BUGs. In the Error types column, ✓ denotes supplied oracle error types from NL2SQL-BUGs; ✗ denotes no error types. ErrorLLM denotes our adaptation (Section 4.1 ). Qwen3-8B is evaluated with thinking OFF and ON. Bold marks the best accuracy per Qwen setting. TEG's margin over the strongest baseline ranges from 0.9 to 11.8 points.
Method
Error types
1 error
2 errors
3+ errors
Overall
Base
✗
30.0
25.9
14.1
23.7
Reasoning and self-correction
CoT ( Kojima et al., 2022 )
✗
35.5
21.5
21.8
24.4
Self-Debug (Simple) ( Chen et al., 2024b )
✗
33.6
20.9
16.9
22.4
Self-Debug (Expl) ( Chen et al., 2024b )
✗
29.1
24.6
18.3
23.9
SQL-specific refinement
Table 2: TEG leads every error-count group with Qwen2.5-7B-Instruct. Entries are execution accuracies (%) on NL2SQL-BUGs, grouped by error count; Overall covers all queries. In the Error types column, ✓ denotes supplied oracle error types from NL2SQL-BUGs; ✗ denotes no error types. ErrorLLM denotes our adaptation (Section 4.1 ). Bold marks the best value per column. TEG retains its lead on multi-error queries, although its accuracy is lower for queries with more errors.
Qwen2.5-Instruct
Qwen3-8B
Opus 4.8
Method
7B
14B
32B
Thinking OFF
Thinking ON
Base
30.0
35.5
41.8
31.8
43.6
63.6
ErrorLLM
32.7
45.5
47.3
38.2
44.5
64.5
TEG (ours)
45.5
48.2
52.7
45.5
53.6
69.1
Table 3: Single-error correction with predicted error types. Entries are single-error execution accuracies (%) on NL2SQL-BUGs. Opus 4.8 supplies the same predicted types to TEG and ErrorLLM; it also corrects queries in the Opus 4.8 column. Base receives no types. Bold marks the best value per setting. On empty predictions, TEG attempts unmasked correction; ErrorLLM retains the query.
Method
1 error
2 errors
3+ errors
Overall
TEG (ours)
47.3
36.7
29.6
37.0
w/o error annotation
38.2
34.7
21.1
31.9
w/o masking
40.9
34.3
27.5
33.9
w/o DB execution
40.9
27.3
19.0
27.9
w/o candidate selection
47.3
25.9
20.4
28.8
w/o sequential correction
47.3
32.3
23.9
33.2
Table 4: Every ablation variant has lower overall accuracy than TEG. Entries are execution accuracies (%) by error count on NL2SQL-BUGs with Qwen2.5-7B-Instruct; Overall covers all queries. Bold marks the best value per column, including ties. Without candidate selection or sequential correction, single-error accuracy ties the full method.
Method
Error types
Attribute
Value
Condition
Table
Others
Overall
Base
✗
24.3
41.4
29.4
33.3
16.7
30.0
CoT
✗
35.1
37.9
52.9
26.7
16.7
35.5
Self-Debug (Simple)
✗
24.3
41.4
35.3
53.3
16.7
33.6
Self-Debug (Expl)
✗
24.3
37.9
35.3
33.3
0 8.3
29.1
DIN-SQL
✗
10.8
51.7
23.5
13.3
16.7
24.5
MAC-SQL
✗
10.8
27.6
23.5
0 6.7
25.0
18.2
Table 5: TEG leads on Table, Condition, and Attribute errors with Qwen2.5-7B. Entries are single-error execution accuracies (%) by oracle error category with Qwen2.5-7B-Instruct. In the Error types column, ✓ denotes supplied oracle error types from NL2SQL-BUGs; ✗ denotes no error types. Others pools the less frequent categories. Bold marks the best value per column, including ties. The largest gains over Base are on Table and Condition errors.
Appendix figures & tables12 assets
Supplementary material from the paper’s appendix.
Appendix
Category
Sub-type
Edit group
Attribute-Related
Attribute Mismatch
M
Attribute Redundancy
R
Attribute Missing
Mi
Table-Related
Table Mismatch
M
Table Redundancy
R
Table Missing
Mi
Appendix
Table 6: Four edit groups turn the 31 taxonomy sub-types into edit operations. Sub-types follow the nine NL2SQL-BUGs categories. Edit groups: M = Mismatch (replace), R = Redundancy (remove), Mi = Missing (insert), Rw = Rewrite (restructure). Mismatch covers 64.7% of all annotations, so replacement is the most frequent requested edit.
Category
Sub-type
Target AST Nodes
Attribute
Mismatch, Redundancy
Column (string-level replace)
Missing
–
Table
Mismatch, Redundancy
Table
Join Cond./Type Mismatch
Join
Missing
–
Value
Mismatch, Data Format
Literal , String , Int64
Appendix
Table 7: Each maskable error sub-type selects the AST node classes that TEG masks. Targets are SQLGlot node classes, and Table-Related rows describe multi-error mode. “–” marks sub-types in the Missing and Rewrite edit groups, which pass the query through unmasked. The rule names a node class rather than a unique faulty node, so the LLM still decides which masked construct to change.
Distribution
Count
%
Errors per Query (549 queries)
1 error
110
20.0
2 errors
297
54.1
3 errors
114
20.8
4 errors
26
4.7
5 errors
2
0.4
Appendix
Table 8: Most evaluation queries carry more than one error. The 1,160 error annotations in our 549-query NL2SQL-BUGs subset by errors per query, error category, and edit group. Single-error queries are 20.0% of the subset, and Attribute and Table errors are about half of all annotations.
Example 1 : Attribute Mismatch (single error) db: california_schools
Question
What is the unabbreviated mailing street address of the school with the highest FRPM count for K-12 students?
Issued SQL
SELECT schools. streetabr FROM frpm INNER JOIN schools ON frpm.cdscode = schools.cdscode ORDER BY frpm.‘frpm count (k-12)‘ DESC LIMIT 1
Reference SQL
SELECT T2. MailStreet FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode ORDER BY T1.‘FRPM Count (K-12)‘ DESC LIMIT 1
Example 2 : Value Mismatch (single error) db: codebase_community
Question
Which user has the website URL listed at ’http://stackoverflow.com’
Issued SQL
SELECT displayname FROM users WHERE websiteurl = ’http://stackoverflow.com/u/1114’
Appendix
Table 9: An error can sit in a column, a value, or several places at once. Representative single-error and multi-error queries from NL2SQL-BUGs. Red marks the erroneous span in the issued SQL and green the corresponding span in the reference SQL. Example 3 needs both an insertion and a replacement, which TEG handles in two sequential steps.
Method
Error types
Attribute
Value
Condition
Table
Others
Overall
Qwen2.5-7B
Base
✗
24.3
41.4
29.4
33.3
16.7
30.0
CoT
✗
35.1
37.9
52.9
26.7
16.7
35.5
Self-Debug (Simple)
✗
24.3
41.4
35.3
53.3
16.7
33.6
Self-Debug (Expl)
✗
24.3
37.9
35.3
33.3
8.3
29.1
DIN-SQL
✗
10.8
51.7
23.5
13.3
16.7
24.5
Appendix
Table 10: TEG leads or ties on Attribute errors at every Qwen2.5 scale. Single-error execution accuracy by oracle error category on Qwen2.5-Instruct. In the Error types column, ✓ denotes supplied oracle error types from NL2SQL-BUGs; ✗ denotes no error types. Others pools the less frequent categories, and Overall counts all queries. Bold marks the best value per column within each model block, including ties. Other methods win smaller categories, such as DIN-SQL on Value errors at 14B and 32B.
Method
Error types
Attribute
Value
Condition
Table
Others
Overall
Qwen3-8B (Thinking OFF)
Base
✗
27.0
34.5
29.4
46.7
25.0
31.8
CoT
✗
18.9
37.9
41.2
66.7
16.7
33.6
Self-Debug (Simple)
✗
40.5
44.8
29.4
33.3
33.3
38.2
Self-Debug (Expl)
✗
43.2
44.8
35.3
66.7
33.3
44.5
DIN-SQL
✗
13.5
41.4
17.6
13.3
16.7
21.8
Appendix
Table 11: On Qwen3-8B, TEG leads or ties on Attribute errors with thinking both OFF and ON. Single-error execution accuracy by oracle error category. In the Error types column, ✓ denotes supplied oracle error types from NL2SQL-BUGs; ✗ denotes no error types. Others pools the less frequent categories, and Overall weights queries equally, not category columns. Bold marks the best value per column within each thinking mode, including ties. Other methods win smaller categories, such as Self-Debug (Simple) on Value errors with thinking ON.
Method
Attribute
Value
Condition
Table
Others
Overall
Base
19.6
19.4
15.7
24.2
22.1
22.1
Reasoning and self-correction
CoT ( Kojima et al., 2022 )
20.7
13.6
15.7
28.4
21.6
21.6
Self-Debug (Simple) ( Chen et al., 2024b )
16.7
19.4
17.1
23.2
19.7
19.6
Self-Debug (Expl) ( Chen et al., 2024b )
22.2
17.5
15.7
25.3
22.1
22.6
SQL-specific refinement
Appendix
Table 12: On multi-error queries, TEG leads every error category and reaches 34.4 overall. Execution accuracy by error category on Qwen2.5-7B-Instruct over the 439 multi-error queries. ErrorLLM and TEG use oracle types, while the other baselines run without them. A query counts in every category containing one of its errors, so the columns overlap (Attribute 275, Value 103, Condition 140, Table 194, Others 213), and bold marks the best value per column. The lead is largest on Table errors, 43.8 against 28.4 for the next best method.
Qwen2.5-Instruct
Qwen3-8B (thinking)
Method
7B
14B
32B
OFF
ON
Base
28.2
36.4
41.8
35.5
48.2
Reasoning and self-correction
CoT ( Kojima et al., 2022 )
32.7
40.9
42.7
39.1
52.7
Self-Debug (Simple) ( Chen et al., 2024b )
35.5
45.5
50.9
40.9
48.2
Self-Debug (Expl) ( Chen et al., 2024b )
28.2
38.2
45.5
45.5
48.2
Appendix
Table 13: TEG leads single-error correction when all methods receive oracle types. Single-error execution accuracy. Base, reasoning and self-correction, and SQL-specific refinement methods use prompts augmented with those types, and ErrorLLM and TEG already use the types in their own procedures. Qwen3-8B is evaluated with thinking OFF and ON, and bold marks the best accuracy per Qwen setting. The single-error margin over the strongest baseline given error types ranges from 0.9 points, at Qwen2.5-14B and at Qwen3-8B with thinking OFF, to 11.8 points at Qwen2.5-7B.
Method
1 error
2 errors
3+ errors
Overall
Base
28.2
23.2
16.9
22.6
Reasoning and self-correction
CoT ( Kojima et al., 2022 )
32.7
25.9
14.8
24.4
Self-Debug (Simple) ( Chen et al., 2024b )
35.5
24.6
21.8
26.0
Self-Debug (Expl) ( Chen et al., 2024b )
28.2
26.9
19.7
25.3
SQL-specific refinement
Appendix
Table 14: With the same oracle error types for every baseline, TEG leads at every error count. Execution accuracy on all 549 queries using Qwen2.5-7B-Instruct. Base, reasoning and self-correction, and SQL-specific refinement methods use prompts augmented with those types, and ErrorLLM and TEG already use the types in their own procedures. Bold marks the best value per column. TEG reaches 37.0 overall against 26.0 for the strongest such baseline, Self-Debug (Simple).
Method
Attribute
Value
Condition
Table
Others
Overall
Base
24.3
18.9
41.4
37.9
29.4
29.4
33.3
46.7
16.7
0 8.3
30.0
28.2
Reasoning and self-correction
CoT
35.1
21.6
37.9
34.5
52.9
47.1
26.7
53.3
16.7
16.7
35.5
32.7
Self-Debug (Simple)
24.3
24.3
41.4
48.3
35.3
41.2
53.3
46.7
16.7
16.7
33.6
35.5
Self-Debug (Expl)
24.3
16.2
37.9
31.0
35.3
35.3
33.3
53.3
0 8.3
16.7
29.1
28.2
SQL-specific refinement
Appendix
Table 15: Oracle types lift only two of six baselines, and TEG stays highest overall. Single-error execution accuracy by error category on Qwen2.5-7B-Instruct. Each pair shows results without and with the oracle error type. ErrorLLM and TEG require types, so their entries without types are dashes. Bold marks the best value per category with and without oracle error types, including ties. With error types, DIN-SQL leads on Value, and SQLFixAgent and MAC-SQL tie TEG on Table and Others.
1 error
2 errors
3+ errors
Overall
Exact match
52.7
0 8.8
0 3.5
16.2
Exact match, category only
55.5
14.8
0 3.5
20.0
Appendix
Table 16: Predicted types match about half of single-error annotations, few multi-error ones. Accuracy of the error types predicted by Opus 4.8 on all 549 queries, by the oracle number of errors (110 / 297 / 142). Exact match requires the predicted annotation to equal the oracle one as a multiset of (category, sub-type) pairs; the second row ignores the sub-type. Ignoring sub-types raises overall exact match only from 16.2 to 20.0, and the predictions under-count errors on 58.7% of queries.
Method
Attribute
Value
Condition
Table
Others
Overall
Qwen2.5-7B
24.3
41.4
29.4
33.3
16.7
30.0
TEG (predicted types)
37.8
55.2
52.9
53.3
25.0
45.5
TEG (oracle types)
37.8
51.7
58.8
66.7
25.0
47.3
Qwen2.5-14B
27.0
37.9
41.2
40.0
41.7
35.5
TEG (predicted types)
35.1
58.6
47.1
80.0
25.0
48.2
TEG (oracle types)
48.6
55.2
58.8
66.7
33.3
52.7
Appendix
Table 17: Predicted error types lower TEG’s Condition accuracy at every Qwen2.5 scale. Single-error execution accuracy by the oracle error category. Each model row is Base, a single unmasked correction call, and the indented rows add TEG with predicted or oracle types. The Opus 4.8 block uses only the types it predicts itself, and Qwen3-8B has separate thinking OFF/ON blocks. Bold marks the best overall accuracy within each model block. Attribute accuracy also drops at 14B and 32B, whereas Table and Others change in both directions on only 15 and 12 queries.
Despite the remarkable performance of large language models (LLMs) in text-to-SQL (SQL generation), correctly producing SQL queries remains challenging during initial generation. The SQL refinement task is subsequently introduced to correct syntactic and semantic errors in generated SQL queries. However, existing paradigms face two major limitations: (i) self-debugging becomes increasingly ineffective as modern LLMs rarely produce explicit execution errors that can trigger debugging signals; (ii) self-correction exhibits low detection precision due to the lack of explicit error modeling grounded in the question and schema, and suffers from severe hallucination that frequently corrupts correct SQLs. In this paper, we propose ErrorLLM, a framework that explicitly models text-to-SQL Errors within a dedicated LLM for text-to-SQL refinement. Specifically, we represent the user question and database schema as structural features, employ static detection to identify execution failures and surface mismatches, and extend ErrorLLM's semantic space with dedicated error tokens that capture categorized implicit semantic error types. Through a well-designed training strategy, we explicitly model these errors with structural representations, enabling the LLM to detect complex implicit errors by predicting dedicated error tokens. Guided by the detected errors, we perform error-guided refinement on the SQL structure by prompting LLMs. Extensive experiments demonstrate that ErrorLLM achieves the most significant improvements over backbone initial generation. Further analysis reveals that detection quality directly determines refinement effectiveness, and ErrorLLM addresses both sides by high detection F1 score while maintain refinement effectiveness.
Zijin Hong, Hao Chen, Zheng Yuan +6
The Hong Kong Polytechnic University Kowloon, Hong Kong · City University of Macau Taipa, Macau · Jilin University Changchun, China +3
Prompting-based (i.e., non-fine-tuning) Text-to-SQL methods, where underlying large language model parameters are not changed for the task, face three problems: (i) relying on coarse-grained schema information that may not reveal the fine-grained relationships needed to distinguish ambiguous columns, (ii) failing to capture recurring SQL-generation failures, and (iii) suffering from omission or hallucination of components in complex questions. This paper develops DexterSQL, a prompting/non-fine-tuning-based Text-to-SQL system that improves SQL generation with three novel components: (i) deep schema explorator that identifies ambiguous columns, analyzes their individual and joint data distributions to uncover their relationships and the distinct role of each, (ii) database-agnostic rule creator that mines mismatches between generated and gold SQL only on the training database and converts them into database-agnostic corrective rules that capture recurring LLM failure patterns; and (iii) multi-path SQL generation that introduces a dependency-tree-based intermediate representation that uses the question's sentence structure to guide its decomposition into an SQL skeleton for final SQL generation. DexterSQL achieves a higher accuracy compared to the state-of-the-art using both open-source/weight and closed-source/weight models. Particularly, DexterSQL shows a high improvement of at least 5.5% using an open-weight model (GPT-OSS-120B) on BIRDDev, with total accuracy 70.4%. DexterSQL also shows better improvement of at least 1.4% using closed-weight models, with total accuracy 72.1% and 72.9% on BIRD-Dev with GPT-4o and GPT-5.2.
Anik Pramanik, Murat Kantarcioglu, Vincent Oria +1
New Jersey Institute of Technology, USA. · Virginia Tech, USA.
Natural language to SQL (NL2SQL) conversion is an important problem for researchers and enterprises due to the ubiquitous importance of relational databases in broad-ranging practical problems. Despite the rapid advancements in the capabilities of LLMs, NL2SQL has not reached parity in accuracy with human expert SQL writers, hence needing additional improvements in NL2SQL algorithms. This study presents a new multi-agent method for NL2SQL that achieves 78.1% semantic accuracy on the BIg Bench for LaRge-scale Database (BIRD) benchmark. Our method leverages a semantically enriched representation of user-provided schema, adds user-provided business rules, and produces accurate SQL queries. The main contributions of this study are (a) We designed an optimized new orchestrator in a multi-agent solution that uses LLMs to plan, orchestrate, reflect, and self-correct to generate accurate SQL queries, (b) We developed an advanced schema enrichment method that creates context-aware metadata to improve accuracy, and (c) We demonstrated the accuracy and generalizability of the method across different domains and datasets by evaluating it on the BIRD-SQL benchmark.