Lune

AAAI2025Top-tier venue

MAGIC: Generating Self-Correction Guideline for In-Context Text-to-SQL

Arian Askari, Christian Pölitz, Xinye Tang

Abstract

Self-correction in text-to-SQL is the process of prompting large language model (LLM) to revise its previously incorrectly generated SQL, and commonly relies on manually crafted self-correction guidelines by human experts that are not only labor-intensive to produce but also limited by the human ability in identifying all potential error patterns in LLM responses. We introduce MAGIC, a novel multi-agent method that automates the creation of the self-correction guideline. MAGIC uses three specialized agents: a manager, a correction, and a feedback agent. These agents collaborate on the failures of an LLM-based method on the training set to iteratively generate and refine a self-correction guideline tailored to LLM mistakes, mirroring human processes but without human involvement. Our extensive experiments show that MAGIC's guideline outperforms expert human's created ones. We empirically find out that the guideline produced by MAGIC enhances the interpretability of the corrections made, providing insights in analyzing the reason behind the failures and successes of LLMs in selfcorrection. All agent interactions are publicly available at https://huggingface.co/datasets/microsoft/MAGIC .

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

11 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • SQLens: An End-to-End Framework for Error Detection and Correction in Text-to-SQL cites DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-Correction
  • SQLens: An End-to-End Framework for Error Detection and Correction in Text-to-SQL cites Teaching Large Language Models to Self-Debug
  • SQLens: An End-to-End Framework for Error Detection and Correction in Text-to-SQL cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • Self-Refine: Iterative Refinement with Self-Feedback cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-Correction cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • SHARE: An SLM-based Hierarchical Action CorREction Assistant for Text-to-SQL cites DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-Correction
  • SHARE: An SLM-based Hierarchical Action CorREction Assistant for Text-to-SQL cites Teaching Large Language Models to Self-Debug
  • SHARE: An SLM-based Hierarchical Action CorREction Assistant for Text-to-SQL cites CRITIC: Large Language Models Can Self-Correct with Tool-Interactive Critiquing
  • Teaching Large Language Models to Self-Debug cites Self-Refine: Iterative Refinement with Self-Feedback
  • Teaching Large Language Models to Self-Debug cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • CRITIC: Large Language Models Can Self-Correct with Tool-Interactive Critiquing cites Self-Refine: Iterative Refinement with Self-Feedback
  • CRITIC: Large Language Models Can Self-Correct with Tool-Interactive Critiquing cites Teaching Large Language Models to Self-Debug
  • CRITIC: Large Language Models Can Self-Correct with Tool-Interactive Critiquing cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • PTD-SQL: Partitioning and Targeted Drilling with LLMs in Text-to-SQL cites Self-Refine: Iterative Refinement with Self-Feedback
  • PTD-SQL: Partitioning and Targeted Drilling with LLMs in Text-to-SQL cites DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-Correction
  • PTD-SQL: Partitioning and Targeted Drilling with LLMs in Text-to-SQL cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers11

  1. SQLens: An End-to-End Framework for Error Detection and Correction in Text-to-SQLYue Gong, Chuan Lei, Xiao Qin, Kapil Vaidya et al.NeurIPS 2025 · 21 citations
  2. ExCyTIn-Bench: Evaluating LLM agents on Cyber Threat InvestigationYiran Wu, Mauricio Velazco, Andrew Zhao, Manuel Luján et al.ICML 2026 · 14 citations
  3. SHARE: An SLM-based Hierarchical Action CorREction Assistant for Text-to-SQLGe Qu, Jinyang Li, Bowen Qin, Xiaolong Li et al.ACL 2025 · 13 citations
  4. Uncovering the Impact of Chain-of-Thought Reasoning for Direct Preference Optimization: Lessons from Text-to-SQLHanbing Liu, Haoyang Li, Xiaokang Zhang, Ruotong Chen et al.ACL 2025 · 10 citations
  5. PTD-SQL: Partitioning and Targeted Drilling with LLMs in Text-to-SQLRuilin Luo, Liyuan Wang, Binghuai Lin, Zicheng Lin et al.EMNLP 2024 · 4 citations

Builds on11

  1. Chain-of-Thought Prompting Elicits Reasoning in Large Language ModelsJason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma et al.NeurIPS 2022 · 22,562 citations
  2. Self-Refine: Iterative Refinement with Self-FeedbackAman Madaan, Niket Tandon, Prakhar Gupta, Skyler Hallinan et al.NeurIPS 2023 · 4,972 citations
  3. Teaching Large Language Models to Self-DebugXinyun Chen, Maxwell Lin, Nathanael Schärli, Denny ZhouICLR 2024 · 1,085 citations
  4. DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-CorrectionMohammadreza Pourreza, Davood RafieiNeurIPS 2023 · 909 citations
  5. CRITIC: Large Language Models Can Self-Correct with Tool-Interactive CritiquingZhibin Gou, Zhihong Shao, Yeyun Gong, Yelong Shen et al.ICLR 2024 · 699 citations

Related papers

  1. TS-SQL: Test-driven Self-refinement for Text-to-SQLWenbo Xu, Haifeng Zhu, Liang Yan, Chuanyi Liu et al.EMNLP Findings 2025 · 2 citations
  2. MARS-SQL: A Multi-Agent Reinforcement Learning Framework For Text-To-SQLHaolin Yang, Jipeng Zhang, Zhitao He, Alexander Zhou et al.ICML 2026 · 12 citations
  3. SQLFixAgent: Towards Semantic-Accurate Text-to-SQL Parsing via Consistency-Enhanced Multi-Agent CollaborationJipeng Cen, Jiaxin Liu, Zhixu Li, Jingjing WangAAAI 2025 · 18 citations
  4. ErrorLLM: Modeling SQL Errors for Text-to-SQL RefinementZijin Hong, Hao Chen, Zheng Yuan, Qinggang Zhang et al.KDD 2026 · 3 citations
  5. DAC: Decomposed Automation Correction for Text-to-SQLDingzirui Wang, Longxu Dou, Xuanliang Zhang, Qingfu Zhu et al.EMNLP Findings 2025 · 5 citations
Dusk over the sea between two cliffs drawn in fine vertical lines