LearNAT: Learning NL2SQL with AST-guided Task Decomposition for Large Language Models
Weibin Liao, Xin Gao, Tianyu Jia, Rihong Qiu, Yifan Zhu, Yang Lin, Xinyu Ma, Junfeng Zhao, Yasha Wang
Abstract
Natural Language to SQL (NL2SQL) has emerged as a critical task for enabling seamless interaction with databases. Recent advancements in Large Language Models (LLMs) have demonstrated remarkable performance in this domain. However, existing NL2SQL methods predominantly rely on closed-source LLMs leveraging prompt engineering, while open-source models typically require fine-tuning to acquire domain-specific knowledge. Despite these efforts, opensource LLMs struggle with complex NL2SQL tasks due to the indirect expression of user query objectives and the semantic gap between user queries and database schemas. Inspired by the application of reinforcement learning in mathematical problem-solving to encourage step-by-step reasoning in LLMs, we propose LearNAT (Learning NL2SQL with AST-guided Task Decomposition), a novel framework that improves the performance of open-source LLMs on complex NL2SQL tasks through task decomposition and reinforcement learning. LearNAT introduces three key components: (1) a Decomposition Synthesis Procedure that leverages Abstract Syntax Trees (ASTs) to guide efficient search and pruning strategies for task decomposition, (2) Margin-aware Reinforcement Learning, which employs fine-grained step-level optimization via DPO with AST margins, and (3) Adaptive Demonstration Reasoning, a mechanism for dynamically selecting relevant examples to enhance decomposition capabilities. Extensive experiments on two benchmark datasets, Spider and BIRD, demonstrate that LearNAT enables a 7B-parameter open-source LLM to achieve performance comparable to GPT-4, while offering improved efficiency and accessibility. Our work marks a significant step toward democratizing NL2SQL capabilities, illustrating that carefully designed task decomposition strategies can narrow the performance gap between open-source and closed-source models. Furthermore, the proposed approach not only advances the state-of-the-art in NL2SQL but also provides valuable insights into enhancing LLMs' reasoning abilities for complex structured prediction tasks.
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.
6 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- ProMed: Shapley Information Gain Guided Reinforcement Learning for Proactive Medical LLMs cites Direct Preference Optimization: Your Language Model is Secretly a Reward Model
- ProMed: Shapley Information Gain Guided Reinforcement Learning for Proactive Medical LLMs cites Magical: Medical Lay Language Generation via Semantic Invariance and Layperson-tailored Adaptation
- Direct Preference Optimization: Your Language Model is Secretly a Reward Model cites Training language models to follow instructions with human feedback
- Large Language Models are Zero-Shot Reasoners cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- Large Language Models are Zero-Shot Reasoners cites Training language models to follow instructions with human feedback
- HuggingGPT: Solving AI Tasks with ChatGPT and its Friends in Hugging Face cites Large Language Models are Zero-Shot Reasoners
- HuggingGPT: Solving AI Tasks with ChatGPT and its Friends in Hugging Face cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- HuggingGPT: Solving AI Tasks with ChatGPT and its Friends in Hugging Face cites Training language models to follow instructions with human feedback
- Chain-of-Thought Prompting Elicits Reasoning in Large Language Models cites Training language models to follow instructions with human feedback
- 3DS: Medical Domain Adaptation of LLMs via Decomposed Difficulty-based Data Selection cites ProMed: Shapley Information Gain Guided Reinforcement Learning for Proactive Medical LLMs
Cited by top-tier papers6
- ProMed: Shapley Information Gain Guided Reinforcement Learning for Proactive Medical LLMsHongxin Ding, Baixiang Huang, Yue Fang, Weibin Liao et al.ACL 2026 · 10 citations
- Magical: Medical Lay Language Generation via Semantic Invariance and Layperson-tailored AdaptationWeibin Liao, Tianlong Wang, Yinghao Zhu, Yasha Wang et al.NeurIPS 2025 · 7 citations
- APEX-SQL: Talking to the data via Agentic Exploration for Text-to-SQLBowen Cao, Weibin Liao, Yushi Sun, Dong Fang et al.KDD 2026 · 7 citations
- 3DS: Medical Domain Adaptation of LLMs via Decomposed Difficulty-based Data SelectionHongxin Ding, Yue Fang, Runchuan Zhu, Xinke Jiang et al.EMNLP 2025 · 1 citation
- LEAF-SQL: Level-Wise Exploration with Adaptive Fine-Graining for Text-to-SQL Skeleton PredictionZhao Tan, Xiping Liu, Qing Shu, Qizhi Wan et al.ICDE 2026
Builds on21
- Training language models to follow instructions with human feedbackLong Ouyang, Jeffrey Wu, Xu Jiang, Diogo Almeida et al.NeurIPS 2022 · 24,707 citations
- Chain-of-Thought Prompting Elicits Reasoning in Large Language ModelsJason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma et al.NeurIPS 2022 · 22,562 citations
- Direct Preference Optimization: Your Language Model is Secretly a Reward ModelRafael Rafailov, Archit Sharma, Eric Mitchell, Christopher D. Manning et al.NeurIPS 2023 · 10,924 citations
- Large Language Models are Zero-Shot ReasonersTakeshi Kojima, Shixiang Shane Gu, Machel Reid, Yutaka Matsuo et al.NeurIPS 2022 · 8,168 citations
- HuggingGPT: Solving AI Tasks with ChatGPT and its Friends in Hugging FaceYongliang Shen, Kaitao Song, Xu Tan, Dongsheng Li et al.NeurIPS 2023 · 1,778 citations
Related papers
- STaR-SQL: Self-Taught Reasoner for Text-to-SQLMingqian He, Yongliang Shen, Wenqi Zhang, Qiuying Peng et al.ACL 2025
- ReEx-SQL: Reasoning with Execution-Aware Reinforcement Learning for Text-to-SQLYaxun Dai, Wenxuan Xie, Xialie Zhuang, Tianyu Yang et al.ACL 2026 · 8 citations
- OpenSQL: Data-Efficient Text-to-SQL for Open-Source LLMs via Synthesized Intermediate SupervisionRuilin Hu, Yuyu Luo, Guoliang Li, Shuangqiao Wu et al.VLDB 2026 · 4 citations
- DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-CorrectionMohammadreza Pourreza, Davood RafieiNeurIPS 2023 · 909 citations
- DB-Explore: Automated Database Exploration and Instruction Synthesis for Text-to-SQLHaoyuan Ma, Yongliang Shen, Hengwei Liu, Wenqi Zhang et al.EMNLP Findings 2025 · 2 citations
