Lune

ICDE2024Top-tier venue

PURPLE: Making a Large Language Model a Better SQL Writer

Tonghui Ren, Yuankai Fan, Zhenying He, Ren Huang, Jiaqi Dai, Can Huang, Yinan Jing, Kai Zhang, Yifan Yang, X. Sean Wang

Abstract

Large Language Model (LLM) techniques play an increasingly important role in Natural Language to SQL (NL2SQL) translation. LLMs trained by extensive corpora have strong natural language understanding and basic SQL generation abilities without additional tuning specific to NL2SQL tasks. Existing LLMs-based NL2SQL approaches try to improve the translation by enhancing the LLMs with an emphasis on user intention understanding. However, LLMs sometimes fail to generate appropriate SQL due to their lack of knowledge in organizing complex logical operator composition. A promising method is to input the LLMs with demonstrations, which include known NL2SQL translations from various databases. LLMs can learn to organize operator compositions from the input demonstrations for the given task. In this paper, we propose PURPLE (Pre-trained models Utilized to Retrieve Prompts for Logical Enhancement), which improves accuracy by retrieving demonstrations containing the requisite logical operator composition for the NL2SQL task on hand, thereby guiding LLMs to produce better SQL translation. PURPLE achieves a new state-of-the-art performance of 80.5% exact-set match accuracy and 87.8% execution match accuracy on the validation set of the popular NL2SQL benchmark Spider. PURPLE maintains high accuracy across diverse benchmarks, budgetary constraints, and various LLMs, showing robustness and cost-effectiveness.

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.

21 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

  • ReEx-SQL: Reasoning with Execution-Aware Reinforcement Learning for Text-to-SQL cites DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-Correction
  • ReEx-SQL: Reasoning with Execution-Aware Reinforcement Learning for Text-to-SQL cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • ReEx-SQL: Reasoning with Execution-Aware Reinforcement Learning for Text-to-SQL cites Grounding Natural Language to SQL Translation with Data-Based Self-Explanations
  • DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-Correction cites Language Models are Few-Shot Learners
  • DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-Correction cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • Teaching Large Language Models to Self-Debug cites Language Models are Few-Shot Learners
  • Teaching Large Language Models to Self-Debug cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • OpenSQL: Data-Efficient Text-to-SQL for Open-Source LLMs via Synthesized Intermediate Supervision cites DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-Correction
  • OpenSQL: Data-Efficient Text-to-SQL for Open-Source LLMs via Synthesized Intermediate Supervision cites SQL-R1: Training Natural Language to SQL Reasoning Model By Reinforcement Learning
  • OpenSQL: Data-Efficient Text-to-SQL for Open-Source LLMs via Synthesized Intermediate Supervision cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • SQL-R1: Training Natural Language to SQL Reasoning Model By Reinforcement Learning cites DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-Correction
  • SQL-R1: Training Natural Language to SQL Reasoning Model By Reinforcement Learning cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • CogSQL: A Cognitive Framework for Enhancing Large Language Models in Text-to-SQL Translation cites DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-Correction
  • CogSQL: A Cognitive Framework for Enhancing Large Language Models in Text-to-SQL Translation cites Teaching Large Language Models to Self-Debug
  • CogSQL: A Cognitive Framework for Enhancing Large Language Models in Text-to-SQL Translation cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • Grounding Natural Language to SQL Translation with Data-Based Self-Explanations cites DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-Correction
  • Grounding Natural Language to SQL Translation with Data-Based Self-Explanations cites Teaching Large Language Models to Self-Debug
  • Grounding Natural Language to SQL Translation with Data-Based Self-Explanations cites Language Models are Few-Shot Learners
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers21

  1. SQL-R1: Training Natural Language to SQL Reasoning Model By Reinforcement LearningPeixian Ma, Xialie Zhuang, Chengjin Xu, Xuhui Jiang et al.NeurIPS 2025 · 94 citations
  2. CogSQL: A Cognitive Framework for Enhancing Large Language Models in Text-to-SQL TranslationHongwei Yuan, Xiu Tang, Ke Chen, Lidan Shou et al.AAAI 2025 · 12 citations
  3. 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
  4. Grounding Natural Language to SQL Translation with Data-Based Self-ExplanationsYuankai Fan, Tonghui Ren, Can Huang, Zhenying He et al.ICDE 2025 · 7 citations
  5. 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

Builds on28

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
  2. Chain-of-Thought Prompting Elicits Reasoning in Large Language ModelsJason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma et al.NeurIPS 2022 · 22,562 citations
  3. BART: Denoising Sequence-to-Sequence Pre-training for Natural Language Generation, Translation, and ComprehensionMike Lewis, Yinhan Liu, Naman Goyal, Marjan Ghazvininejad et al.ACL 2020 · 1,224 citations
  4. Teaching Large Language Models to Self-DebugXinyun Chen, Maxwell Lin, Nathanael Schärli, Denny ZhouICLR 2024 · 1,085 citations
  5. DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-CorrectionMohammadreza Pourreza, Davood RafieiNeurIPS 2023 · 909 citations

Related papers

  1. The Power of Constraints in Natural Language to SQL TranslationTonghui Ren, Chen Ke, Yuankai Fan, Yinan Jing et al.VLDB 2025 · 4 citations
  2. Enhancing Text-to-SQL Capabilities of Large Language Models: A Study on Prompt Design StrategiesLinyong Nan, Yilun Zhao, Weijin Zou, Narutatsu Ri et al.EMNLP Findings 2023 · 49 citations
  3. Enhancing Text-to-SQL Parsing through Question Rewriting and Execution-Guided RefinementWenxin Mao, Ruiqi Wang, Jiyu Guo, Jichuan Zeng et al.ACL Findings 2024 · 19 citations
  4. Text-to-SQL Empowered by Large Language Models: A Benchmark EvaluationDawei Gao, Haibin Wang, Yaliang Li, Xiuyu Sun et al.VLDB 2024 · 609 citations
  5. Structure-Guided Large Language Models for Text-to-SQL GenerationQinggang Zhang, Hao Chen, Junnan Dong, Shengyuan Chen et al.ICML 2025
Dusk over the sea between two cliffs drawn in fine vertical lines