[Paper Review] Retrieval-augmented GPT-3.5-based Text-to-SQL Framework with Sample-aware Prompting and Dynamic Revision Chain
This paper proposes a retrieval-augmented GPT-3.5-based Text-to-SQL framework that uses sample-aware prompting and a dynamic revision chain to improve SQL generation accuracy. By simplifying input questions and retrieving intent-aligned examples, and iteratively refining SQL via feedback from execution results and explanations, the method achieves state-of-the-art performance on three benchmarks, outperforming strong baselines especially on complex queries.
Text-to-SQL aims at generating SQL queries for the given natural language questions and thus helping users to query databases. Prompt learning with large language models (LLMs) has emerged as a recent approach, which designs prompts to lead LLMs to understand the input question and generate the corresponding SQL. However, it faces challenges with strict SQL syntax requirements. Existing work prompts the LLMs with a list of demonstration examples (i.e. question-SQL pairs) to generate SQL, but the fixed prompts can hardly handle the scenario where the semantic gap between the retrieved demonstration and the input question is large. In this paper, we propose a retrieval-augmented prompting method for a LLM-based Text-to-SQL framework, involving sample-aware prompting and a dynamic revision chain. Our approach incorporates sample-aware demonstrations, which include the composition of SQL operators and fine-grained information related to the given question. To retrieve questions sharing similar intents with input questions, we propose two strategies for assisting retrieval. Firstly, we leverage LLMs to simplify the original questions, unifying the syntax and thereby clarifying the users' intentions. To generate executable and accurate SQLs without human intervention, we design a dynamic revision chain which iteratively adapts fine-grained feedback from the previously generated SQL. Experimental results on three Text-to-SQL benchmarks demonstrate the superiority of our method over strong baseline models.
Motivation & Objective
- To address the challenge of retrieval bias in few-shot prompt learning for Text-to-SQL, where static demonstrations fail when semantic gaps exist between input questions and retrieved examples.
- To improve zero-shot and few-shot generalization in Text-to-SQL by dynamically adapting prompts using sample-aware demonstrations that reflect both intent and structural SQL components.
- To generate executable and accurate SQL queries without human intervention by enabling iterative refinement through fine-grained feedback from database interactions.
- To enhance model robustness on complex queries by incorporating LLM-based question simplification and intent-based retrieval using question skeletons.
Proposed method
- The framework retrieves similar intent-based examples using LLM-generated simplified versions of input questions and question skeletons to reduce semantic gaps.
- Sample-aware demonstrations are constructed by combining SQL operators and fine-grained information relevant to the input question’s intent.
- A dynamic revision chain is introduced, where each iteration improves the SQL query using feedback from SQL execution results, natural language explanations, and schema content.
- The system uses LLMs to simplify original questions, unifying syntax and clarifying user intent to improve retrieval effectiveness.
- The retrieval process leverages both simplified questions and structural question skeletons to identify semantically similar examples for prompting.
- The dynamic revision chain performs iterative refinement: each new version of the SQL is generated based on feedback from the previous one, enabling self-correction.
Experimental results
Research questions
- RQ1Can LLM-based question simplification improve the retrieval of semantically similar examples in few-shot Text-to-SQL prompting?
- RQ2How does incorporating sample-aware demonstrations—combining SQL structure and intent—enhance few-shot generalization in LLM-based Text-to-SQL?
- RQ3To what extent does a dynamic revision chain with fine-grained feedback improve SQL execution accuracy and reduce errors in complex queries?
- RQ4Does the proposed framework outperform strong baselines, especially on hard and extra-hard query categories?
Key findings
- The proposed method outperforms strong baseline models on all three Text-to-SQL benchmarks—Spider, Spider-SYN, and Spider-DK—especially on hard and extra-hard query levels.
- On the Spider-DK dataset, the model improves execution accuracy by 13.6% on easy-level queries and 11.0% on hard-level queries when the dynamic revision chain is used.
- The ablation study shows that removing either the simplification or revision module leads to significant performance drops, with the simplification module contributing most to easy-level improvements (12.5% drop in Spider-DK).
- The dynamic revision chain provides the most benefit in later iterations, with the second iteration yielding greater accuracy gains than the first on Spider-SYN and Spider-DK, indicating progressive refinement.
- Case studies demonstrate that the model correctly identifies exact column values (e.g., 'French' citizenship) and self-corrects errors like incorrect use of COUNT() without GROUP BY, which other models fail to resolve.
- The model achieves state-of-the-art performance, with the largest improvements observed on complex queries, confirming its effectiveness in handling challenging, real-world Text-to-SQL scenarios.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.