Why, Where, How: Taxonomy-guided Error Grounding for Code Repair in NL2SQL

Suchan Lee, Woomin Song, Hwanjo Yu, Sangwoo MoarXiv 2026

TL;DR

TEG (Taxonomy-guided Error Grounding) is a novel framework for repairing SQL queries generated by Large Language Models (LLMs). By translating high-level error diagnoses into specific code masks ("where") and edit instructions ("how"), TEG significantly outperforms existing self-correction methods, achieving a 47.3% execution accuracy on single-error queries from the NL2SQL-BUGs benchmark.

What Problem Does This Paper Address?

Natural Language to SQL (NL2SQL) is a critical task for data-driven agents, but LLMs often produce "silent" semantic errors. A generated query might be syntactically perfect and execute without an exception, yet return the wrong data.

While researchers have developed error taxonomies to categorize why a query is wrong (e.g., "Attribute Mismatch"), simply telling an LLM the error type isn't enough. The model still needs to figure out where in the complex SQL string the fault lies and how to modify the structure to fix it. Existing methods often provide raw execution feedback or generic critiques, which frequently fail to guide the model toward the correct structural repair.

Methods

The authors introduce TEG, which operationalizes error repair through three distinct pillars:

  1. Where (Masking): Instead of showing the model the full, incorrect query, TEG uses a parser (SQLGlot) to identify the Abstract Syntax Tree (AST) nodes associated with a specific error type. It then replaces these nodes with a <MASK> token. For example, an "Attribute Mismatch" triggers masking of column expressions.
  2. How (Edit Instructions): Each error type is mapped to a deterministic edit operation: Replace (for mismatches), Remove (for redundancy), Insert (for missing clauses), or Restructure (for complex logic errors).
  3. Sequential Re-grounding: For queries with multiple errors, TEG doesn't try to fix everything at once. It processes one error at a time, re-parsing and re-masking the query after each step. This prevents the model from becoming overwhelmed by too many masks or conflicting instructions.
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.

Finally, TEG employs a Candidate Selection stage. It generates multiple potential fixes (using paraphrased versions of the original question), filters out those that fail to execute or return empty/null results, and uses an LLM "refiner" to pick the best final query.

Datasets

The primary evaluation was conducted on NL2SQL-BUGs, a benchmark derived from the BIRD dataset.

  • Scope: 549 incorrect SQL queries across 11 SQLite databases.
  • Diversity: The evaluation covers 29 distinct error sub-types across 9 broad categories (e.g., Attribute-Related, Table-Related, Join-Related).
  • Complexity: The dataset includes both single-error and multi-error queries (up to 5 errors per query).

Key Insights and Ideas

  • Masking as a Strong Prior: The "aha moment" here is that masking is more effective than just labeling. By hiding the incorrect code, TEG prevents the LLM from being biased by its own previous mistakes (a common issue in self-correction). It turns a difficult repair task into a simpler "fill-in-the-blank" task.
  • The Power of Deterministic Rules: While LLMs are great at generation, they can be unreliable at precise fault localization. TEG offloads the "localization" to deterministic AST-matching rules, ensuring the model always looks at the right place.
  • Sequential > Parallel: Ablation studies showed that fixing errors one-by-one is significantly better than a single-pass approach. This is because an insertion or restructuring in step one might completely change the "where" for step two.
The sequential process for multi-error queries.

Key Results

TEG was tested across various model sizes (Qwen2.5-7B, 14B, 32B) and "thinking" modes.

  • Superior Performance: Using Qwen2.5-7B-Instruct, TEG reached 47.3% accuracy on single-error queries, beating the closely related ErrorLLM (33.6%) and standard Chain-of-Thought (35.5%).
  • Robustness: Even when using predicted error types (from Claude Opus 4.8) instead of ground-truth "oracle" labels, TEG maintained a lead over direct LLM correction.
  • Ablation Impact: Removing the masking component dropped single-error accuracy from 47.3% to 40.9%, proving that "where" you look is just as important as knowing "why" it's wrong.

Limitations and Future Work

  • Dependency on Diagnosis: TEG requires an initial error diagnosis. While the paper shows it works with predicted types, the overall pipeline's success is capped by the accuracy of the error detector.
  • Execution as a Proxy: The candidate selection relies on execution feedback. However, a query that returns rows isn't guaranteed to be semantically correct (it could be a "lucky" wrong query).
  • Computational Cost: The sequential nature and generation of multiple candidates increase the number of LLM calls and total inference time per repair.
  • Future Directions: The authors suggest extending this "grounding" logic to general-purpose programming (e.g., masking API calls for "API-misuse" errors) and configuration file repair.

Summary updated

BibTeX
@misc{lee2026why,
  author = {Suchan Lee and Woomin Song and Hwanjo Yu and Sangwoo Mo},
  title = {{Why, Where, How: Taxonomy-guided Error Grounding for Code Repair in NL2SQL}},
  year = {2026},
  eprint = {2610.05060},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2610.05060},
}
Figure