PMJ_5f6964261.png Minjun Park 2026.08.27

[ACL 2026] ReSQL: A Self-Improving Text-to-SQL Framework through Retrieval-Augmented Error Reasoning

As enterprises continue to accumulate vast amounts of data, the ability to effectively leverage that data has become a key competitive advantage. Yet, extracting meaningful insights from enterprise databases still largely depends on experienced SQL developers. To bridge this gap, Text-to-SQL has emerged as a promising technology that enables users to query complex databases using natural language, making enterprise data more accessible across organizations.

Recent advances in Large Language Models (LLMs) have significantly improved Text-to-SQL performance. However, in enterprise environments where cost efficiency is essential, organizations often rely on small and medium-sized language models rather than frontier-scale models. These lightweight models still suffer from frequent SQL execution errors and exhibit limited self-correction capabilities, making reliable deployment in production environments challenging.

To address these limitations, LG AI Research introduces ReSQL (Retrieval-Augmented Error Reasoning for Text-to-SQL), a self-improving framework designed to make high-quality Text-to-SQL practical for enterprise applications. This work was presented at ACL 2026, one of the leading conferences in natural language processing.

Challenges in Enterprise Text-to-SQL
Despite remarkable progress in LLM-based Text-to-SQL systems, several challenges remain before they can be reliably deployed in real-world enterprise environments.

Security, Governance, and Operational Control
Commercial LLMs such as GPT-5 have made significant progress in addressing security concerns through private cloud deployments and strategic enterprise partnerships. Nevertheless, many large organizations continue to pursue in-house models to retain full control over sensitive data, ensure regulatory compliance, achieve predictable operational costs, reduce dependency on external platforms, and maintain ownership of their AI infrastructure.

Deploying on Resource-Constrained Devices
Another important consideration is on-device deployment. Running Text-to-SQL directly on edge devices reduces latency, protects sensitive data by eliminating external data transmission, and enables reliable operation even in environments with unstable network connectivity. Since these scenarios are constrained by limited memory and computational resources, lightweight open-source models in the 1B–9B parameter range provide a practical deployment option.

The Limits of Existing Self-Correction Methods
Existing self-correction approaches primarily rely on inference-time prompting techniques, such as iterative refinement or reranking, to improve generated SQL queries. While these methods can be effective for larger models, lightweight models often lack sufficient reasoning capacity to fully utilize the additional context provided during inference. As a result, prompt-based self-correction delivers only limited improvements in practice.

Learning from Failures Instead of Avoiding Them
Rather than attempting to correct errors only during inference, LG AI Research takes a different perspective: execution failures themselves become the source of learning.

When a generated SQL query fails, ReSQL leverages both the execution error message and the ground-truth SQL query to encourage the model to analyze and explain its own mistake. This process transforms error analysis into a rich reasoning dataset, allowing the model to learn not only what the correct SQL should be, but also why the original query failed.

Based on this insight, ReSQL builds a closed-loop self-improving pipeline that continuously collects failed examples, generates structured error reasoning, and uses the resulting data for further training. Through this iterative process, lightweight language models progressively internalize error-correction strategies without relying on manually curated supervision, ultimately becoming more robust and reliable for enterprise Text-to-SQL applications.
 
The ReSQL Framework: A Three-Stage Closed Loop for Self-Improving Text-to-SQL
ReSQL is an integrated framework in which a single language model autonomously generates, diagnoses, and learns from its own Text-to-SQL errors. Instead of treating execution failures as isolated mistakes, ReSQL turns them into training signals that continuously improve the model.

The framework consists of three key stages.
 
Stage 1. Constructing Error Reasoning Data
When a generated SQL query fails during execution, the model is provided with both the execution error message and the corresponding ground-truth SQL query. Using this information, it generates a structured error analysis that:
  1. explains the behavior of the incorrect query,

  2. identifies the root cause of the error, and

  3. proposes how the query should be corrected.

 This process transforms failed executions into high-quality reasoning data. Notably, the authors found that even a lightweight 1B-parameter model can accurately analyze its own mistakes when given the correct answer and a structured reasoning guideline.

Stage 2. Self-Improving Training
The automatically generated error reasoning data is then combined with the original Text-to-SQL training data to further fine-tune the same model using LoRA.

Rather than simply memorizing the correct SQL queries, the model learns the reasoning process behind error diagnosis and correction. This enables it to internalize structured error analysis into its parameters, fundamentally strengthening the reasoning capabilities of lightweight models.
 
Stage 3. Retrieval-Augmented Inference
During inference, if the model encounters an execution error, ReSQL retrieves the three most similar error-reasoning examples from a repository of previously generated cases. These examples are incorporated as few-shot demonstrations to guide the model's correction process.

This creates a complementary learning strategy: fine-tuning improves the model's overall reasoning ability, while retrieval augmentation provides targeted support for rare or long-tail execution errors that are difficult to learn through parameter updates alone.
 

Image 1. The Three-Stage Iterative Loop of the ReSQL Framework [1]


ReSQL in Action: Enabling 7B–9B Models to Surpass GPT-4

ReSQL delivers substantial improvements across SPIDER and BIRD, two of the most widely used benchmarks for Text-to-SQL, consistently outperforming existing self-correction approaches.
 
A Dramatic Leap for Lightweight Models
On the BIRD benchmark, Llama-3.2 1B achieved a remarkable improvement in Execution Accuracy (EX), increasing from 3.78% to 24.84%—more than a 6.5× gain. Execution Accuracy measures whether the generated SQL produces the same execution result as the ground-truth query, regardless of syntactic differences.

Similar improvements were observed across other lightweight models. Gemma-2 2B improved from 13.36% to 26.92%, while the code-specialized CodeS-1B increased from 22.23% to 34.94%. These results demonstrate that ReSQL consistently enhances the reasoning and error-correction capabilities of small language models.

Surpassing Commercial Frontier Models
When trained with ReSQL, 7B–9B parameter models achieved 81.29% Execution Accuracy on SPIDER and 53.78% on BIRD.

Notably, these results outperform GPT-4 equipped with advanced self-correction strategies, which achieved 79.98% on SPIDER and 49.87% on BIRD. The findings demonstrate that an effective self-improving framework can enable compact open models to exceed the performance of much larger commercial systems on complex Text-to-SQL tasks.
 
Better at Correcting Complex Queries
ReSQL also significantly improves the model's ability to recover from its own mistakes.

The framework achieved an average Correction Rate (CR) of 64.38% on SPIDER—more than twice the performance of conventional supervised fine-tuning. Correction Rate measures how often an initially incorrect SQL query is successfully revised into a semantically correct one through the model's self-correction process.

The improvement extends even to the benchmark's most challenging Extra Hard queries, where ReSQL achieved a 39.32% Correction Rate, demonstrating robust reasoning and error recovery under highly complex query conditions.

Image 2.  Remaining Execution Errors After the Second Refinement Stage on the SPIDER and BIRD Benchmarks, Broken Down by Difficulty [2]


Key Insights from ReSQL
Retrieval Augmentation Shines on Long-Tail Errors
A detailed error analysis revealed a clear pattern. Common execution errors, such as basic syntax mistakes, can largely be addressed through fine-tuning alone. However, Retrieval-Augmented Generation (RAG) proves especially valuable for long-tail errors—rare failure cases that appear infrequently in the training data and are therefore difficult to learn through parameter updates alone.

With retrieval-augmented error reasoning, ReSQL substantially reduced several challenging error types:
  1. 36.5% fewer ambiguous column reference errors

  2. 39.4% fewer multi-statement SQL errors

  1. 73.1% fewer ORDER BY-before-UNION errors

  2. 100% elimination of aggregation function errors within GROUP BY clauses

These findings demonstrate that retrieval and parameter learning play complementary roles: fine-tuning strengthens general reasoning capabilities, while retrieval provides targeted guidance for rare and difficult execution failures.

Ablation Studies Validate the Importance of Error Reasoning
The importance of structured error reasoning was further confirmed through ablation studies. Removing the automatically generated error reasoning data caused Execution Accuracy on BIRD to drop by 17.61 percentage points, highlighting that reasoning over execution failures is not merely an auxiliary component but a core driver of ReSQL's performance.

High-Quality Data with Practical Deployment Costs
An important question is whether models can reliably generate useful reasoning data for themselves. The results suggest they can.

Using G-Eval, the automatically generated reasoning data achieved over 85% accuracy, reaching 97.2% when generated by Llama-3.1 8B. Human evaluation of reasoning data generated by lightweight models further reported 97.5% diagnostic accuracy, demonstrating that even small models can produce highly reliable error analyses when provided with appropriate guidance.

ReSQL is also designed with practical deployment in mind. The retrieval process introduces an average overhead of approximately 100 additional tokens and less than 1.2 seconds of latency, making it lightweight enough for real-world applications. Moreover, consistent performance gains were observed not only for lightweight models but also for 32B and 70B models, demonstrating that the framework scales effectively across model sizes.

To support reproducibility and foster open research, LG AI Research has open-sourced both the ReSQL Data Generation Framework and the complete reasoning datasets generated by 1B–9B models.



What’s Next 

ReSQL demonstrates a fundamental shift in perspective: model failures can be transformed into reusable knowledge for future improvement. Rather than treating execution errors as isolated failures, ReSQL turns them into valuable supervision that enables models to continuously improve themselves.

Building on this foundation, LG AI Research plans to extend ReSQL in three key directions.

Proactive Error Prevention
The current framework focuses on correcting errors after they occur. Future work will explore proactive reasoning mechanisms that predict and prevent execution failures before they happen, reducing the need for post-hoc correction altogether.

Fully Unsupervised Self-Improvement
Today's ReSQL uses the ground-truth SQL query to generate high-quality reasoning data. A natural next step is to eliminate this dependency, enabling models to diagnose, reason about, and improve their own outputs without any gold-standard supervision.

Robustness in Real-World Deployment
Beyond benchmark datasets, future research will evaluate ReSQL under more realistic deployment scenarios, including previously unseen database schemas, new industry domains, and other production environments where adaptability and robustness are essential.

More broadly, the self-improving paradigm introduced by ReSQL extends far beyond Text-to-SQL. Any task that provides executable feedback—including code generation, tool use by AI agents, and other interactive reasoning problems—could benefit from the same closed-loop learning framework.

At LG AI Research, we believe that AI systems should not only generate answers but also learn from their own mistakes. ReSQL is one step toward that vision: building AI that continuously improves itself with minimal human intervention while becoming increasingly reliable in real-world applications.
참고

[1] Park, Minjun, et al. "ReSQL: Self-Improving Framework for Reasoning-Aware Text-to-SQL Dataset Generation." Findings of the Association for Computational Linguistics: ACL 2026. 2026.

[2] Yu, Tao, et al. "Spider: A large-scale human-labeled dataset for complex and cross-domain semantic parsing and text-to-sql task." Proceedings of the 2018 conference on empirical methods in natural language processing. 2018.

[3] Li, Jinyang, et al. "Can llm already serve as a database interface." A big bench for large-scale database grounded text-to-SQLs 2305 (2023).

[4] Askari, Arian, Christian Poelitz, and Xinye Tang. "Magic: Generating self-correction guideline for in-context text-to-sql." Proceedings of the AAAI Conference on Artificial Intelligence. Vol. 39. No. 22. 2025.

[5] Chen, Xinyun, et al. "Teaching large language models to self-debug." International Conference on Learning Representations. Vol. 2024. 2024.

[6]. Wang, Xuezhi, et al. "Self-consistency improves chain of thought reasoning in language models." arXiv preprint arXiv:2203.11171 (2022).

[7] Hu, Edward J., et al. "Lora: Low-rank adaptation of large language models." Iclr 1.2 (2022): 3.

[8] Liu, Yang, et al. "G-eval: Nlg evaluation using gpt-4 with better human alignment, 2023." arXiv preprint arXiv:2303.16634 12 (2023): 1.