Source-linked AI summary
Enhancing Few-shot Text-to-SQL Capabilities of Large Language Models: A Study on Prompt Design Strategies
Linyong Nan, Yilun Zhao, Weijin Zou, Narutatsu Ri, Jaesung Tae, Ellen Zhang, Arman Cohan, Dragomir Radev
TL;DR
Text-to-SQL over structured repositories requires accurate information retrieval, while neural models have memory limitations that complicate direct access to large knowledge sources. This study investigates SQL-syntax-based demonstration selection and prompt strategies, finding benefits from balancing similarity with diversity and from database-related augmentation in some settings.
Problem
Structured-source question answering requires accurate retrieval and aggregation, while neural models’ memory limitations complicate direct access to large knowledge sources.
Source: §1 · p. 1Method
The study systematically tests Text-to-SQL demonstration selection and instruction formats, retrieving examples by SQL syntax and balancing similarity with diversity.
Source: §1 · p. 2Results
Similarity-plus-diversity selection maximized performance gains, while database-related augmentation benefited LLMs in some circumstances and its effects varied by setting.
Source: §1 · p. 2, §3.2 · pp. 5–6Takeaways & Limitations
The findings provide a basis for future research on whether the approach transfers to other domains.
Source: §6 · p. 10The experiments relied on OpenAI APIs that have been or will be deprecated, preventing replication with the same APIs.
Source: Limitations · p. 10
Abstract
from arXiv · showhide
In-context learning (ICL) has emerged as a new approach to various natural language processing tasks, utilizing large language models (LLMs) to make predictions based on context that has been supplemented with a few examples or task-specific instructions. In this paper, we aim to extend this method to question answering tasks that utilize structured knowledge sources, and improve Text-to-SQL systems by exploring various prompt design strategies for employing LLMs. We conduct a systematic investigation into different demonstration selection methods and optimal instruction formats for prompting LLMs in the Text-to-SQL task. Our approach involves leveraging the syntactic structure of an example's SQL query to retrieve demonstrations, and we demonstrate that pursuing both diversity and similarity in demonstration selection leads to enhanced performance. Furthermore, we show that LLMs benefit from database-related knowledge augmentations. Our most effective strategy outperforms the state-of-the-art system by 2.5 points (Execution Accuracy) and the best fine-tuned system by 5.1 points on the Spider dataset. These results highlight the effectiveness of our approach in adapting LLMs to the Text-to-SQL task, and we present an analysis of the factors contributing to the success of our strategy.
1 Introduction
Text-to-SQL systems translate natural-language questions into executable SQL, but prompt-based semantic parsing has underperformed fine-tuned systems and is sensitive to demonstration-prompt structure. This study examines prompt design strategies and reports that its strongest strategy surpasses both comparison systems on Spider.
1 Introduction
- Structured-source question answering requires accurate information extraction and aggregation, while neural models face limited working memory and unreliable long-term memory.Understanding retrieval and aggregation is also important for assessing system reliability and robustness.Source: §1 · p. 1
- A neural semantic parser translates natural-language queries into formal sequences such as SQL, which a symbolic reasoner executes against structured sources.The study focuses on improving the semantic parsing module for relational-database question answering.Source: §1 · p. 1
- Prompt-based semantic parsing has underperformed fine-tuned counterparts, while demonstration-prompt structure significantly affects ICL performance.These findings motivate examining prompt configurations for semantic parsing.Source: §1 · p. 2
- 84.4 Execution Accuracy on Spider is 2.5 points above the state-of-the-art system and 5.1 points above the best fine-tuned system.The reported result is for the study's most effective strategy.Source: §1 · p. 2
- The study systematically investigates demonstration selection and instruction formats, retrieving examples by SQL syntax and emphasizing both diversity and similarity.It also reports benefits from database-related knowledge augmentation in certain circumstances.Source: §1 · p. 2
2 Methods
The methods combine SQL-structure-based demonstration retrieval with database representations and schema-related knowledge in prompts. An integrated procedure uses a preliminary SQL prediction to choose demonstrations and aggregates predictions across shot counts.
2 Methods
- Prompt design treats resource representation, augmentation, arrangement, instruction wording, and per-test demonstration selection as key ICL choices.The study proposes enhancements for these components and evaluates them against existing methods.Source: §2 · p. 2
2.1 Demonstration Selection
- SQL-structure retrieval first partitions examples by difficulty category, then clusters discrete syntax vectors to select examples that share a category but vary in problem structure.A preliminary predictor drafts the test SQL; its category selects the candidate partition, and k-means supplies diverse demonstrations.Source: §2.1 · pp. 2–3
2.2 Schema Representation in Instruction
- The method represents databases as CREATE-query code and augments prompts with column definitions and entity-relationship summaries.CREATE-query linearization includes column data types and foreign-key constraints; entity-relationship summaries are useful when multiple tables must be combined.Source: §2.2 · pp. 3–4
2.3 Integrated Strategy for Text-to-SQL
- The integrated procedure builds prompts from selected demonstrations and schema knowledge, then uses majority voting across predictions from different shot counts.A preliminary SQL prediction determines the category and corresponding demonstrations; execution-error outputs are removed before voting.Source: §2.3 · p. 4
3 Experiments
The experiments evaluate prompting strategies across semantic-parsing datasets and find that similarity-plus-diversity sampling, schema augmentation, and voting improve ICL performance. Results also vary by schema augmentation method and prompting setting.
3.1 Experimental Settings
- Spider is a cross-domain semantic-parsing dataset with complex Text-to-SQL problems, originating from 200 databases across 138 domains; we use its 7,000 training examples as our pool of annotated examples.Source: §3.1 · p. 4
- The study evaluates Codex from 1 to 10 shots and ChatGPT from 1 to 5 shots, using execution accuracy.Source: §3.1 · p. 5
- Prompting baselines include random, similarity, diversity, and combined sampling, with database schemas represented as text or SQL CREATE queries.Source: §3.1 · p. 5
3.2 Main Results
- Similarity-sampling experiments were limited to Spider because the Codex API was deprecated, leaving its performance on other datasets untested.Source: §3.2 · p. 5
- Similarity-plus-diversity sampling improves average performance across datasets, while schema representation and voting across different shot outcomes further improve overall ICL performance.Source: §3.2 · p. 5, Figure 1 · p. 6
- CREATE-query database linearization improves zero-shot performance over text-sequence prompts; structural augmentation helps few-shot Codex slightly more, while semantic augmentation benefits zero-shot Codex and few-shot ChatGPT.Source: §3.2 · pp. 5–6, Figure 1 · p. 6
4 Analysis
The analysis examines SQL-syntax-based retrieval, alternative demonstration representations, schema augmentation, and prompting strategies across problem difficulty and preliminary models. It finds value in balancing similarity and diversity, while augmentation and strategy effects vary by setting and problem type.
4.1 Prediction-Syntax based Retrieval
- Syntax coverage and similarity both contribute to selected-example quality, and their simple sum correlates with system performance.SQL syntax directly represents problem structure, which can help when the example pool lacks similar problems or semantic representations do not capture structural differences.Source: §4.1 · pp. 6–7
4.2 Comparative Analysis of Retrieval Methods
- Question-only representations effectively support similarity retrieval; RoBERTa-base compares better than text-embedding-ada-002, and database linearization as SQL improves embeddings.The comparison also found comparable retrieval performance from models not fine-tuned on Text-to-SQL examples.Source: §4.2 · pp. 7–8
- Predicted-SQL syntactic embeddings are the most effective basis for comparing examples in diversity-based demonstration selection.Source: §4.2 · p. 8
4.3 Schema Augmentation
- Semantic augmentation with descriptions of all table columns benefits zero-shot performance, while improvement is not apparent in the few-shot setting.Source: §4.3 · p. 8
4.4 Effectiveness Analysis
- Similarity-diversity benefits most problem types but not the diverse medium split; schema semantics helps easy and medium problems, while schema structure helps more complex ones.The authors hypothesize that challenging problems require a more comprehensive understanding of database structure; the integrated approach helps across examples, especially difficult ones.Source: §4.4 · pp. 8–9
4.5 Preliminary Models
- Higher-performing preliminary models bring gradual improvements, while their effect on similarity-diversity and integrated approaches is relatively minor.Source: §4.5 · p. 9
5 Related Work
The related work reviews in-context learning and prompt design, then describes how table-related tasks encode structured data. It situates Text-to-SQL as requiring alignment between question entities and schema structure.
5.1 In-Context Learning
- In-context learning lets large language models adapt to tasks at inference time from a few demonstrations, and this paper examines prompt-input representations.The section frames ICL as a way to learn from examples provided in context.Source: §5.1 · p. 9
5.1.1 Prompt Organization
- Prompt organization research selects and orders demonstrations using suitability metrics, semantic similarity, learned retrieval, active selection, or diversity-and-similarity strategies.The authors contrast retrieving a diverse set from an existing pool with approaches that first construct a diverse, representative pool.Source: §5.1.1 · pp. 9–10
5.1.2 Prompt Formatting
- Prompt formatting research studies how prompt structure affects task performance, including chain-of-thought methods and automated instruction search.Examples include sampling multiple reasoning paths, eliciting follow-up questions, and scoring candidate instructions.Source: §5.1.2 · p. 10
5.2 Table-related task Encoding
- Table-related tasks encode structured inputs as text sequences with structural markers, while Text-to-SQL also requires schema alignment and structural understanding.For Text-to-SQL, the encoder must align question entities to the schema and represent keys and column types.Source: §5.2 · p. 10
6 Conclusions
The conclusion presents SQL-structure-based demonstration selection, balancing diversity and similarity, alongside database-knowledge augmentation as the paper’s findings. It identifies transfer to other domains as a future direction.
6 Conclusions
- The study selects Text-to-SQL demonstrations using SQL syntactic structure and emphasizes both diversity and similarity as sampling objectives.The conclusion also reports that LLMs benefit from database-related knowledge augmentations.Source: §6 · p. 10
- The authors identify transferability of the approach to other domains as a direction for future research.They frame more accurate, robust, and comprehensible QA systems as an aim of continued improvement in LLM semantic parsing.Source: §6 · p. 10
- The conclusion reports that LLMs benefit from database-related knowledge augmentations.Source: §6 · p. 10
Limitations
The study reports reproducibility constraints from relying on OpenAI APIs and says its benefits for smaller or more constrained annotated-example pools remain unsubstantiated.
Limitations
- The experiments relied on OpenAI APIs that have been or will be deprecated, preventing replication with the same APIs.The authors say this hinders reproducibility and plan to provide results using open-source LLMs.Source: Limitations · p. 10
- The approach’s benefits with smaller or more constrained annotated-example pools are unclear and could not be substantiated.The authors posit that it may cover similar problem structures when identically structured examples are unavailable, but lacked the budget and API access to test this.Source: Limitations · p. 10
Appendix
The appendix illustrates prompt formats and schema representations for Text-to-SQL, including baseline database encodings, semantic schema descriptions, and schema-structure augmentation.
Appendix
- The baseline prompt examples represent databases as text or SQL code and pair the schema with a natural-language question and SQL answer.The examples include queries over gymnast and people tables and over department, management, and head tables.Source: Appendix · p. 15
- Semantic schema augmentation adds column descriptions as inline or block comments to the database schema in example prompts.The appendix shows both comment placements for a department-management schema example.Source: Appendix · pp. 16–17
- Structure augmentation represents schema relations explicitly, including links between tables through primary and foreign keys.Figure 9 is captioned as showing examples of schema-structure representation construction.Source: Figure 9 · p. 18, Appendix · p. 19
- Figures 10–12 compare few-shot sampling and schema-augmentation strategies across demonstration counts, with Figure 12 additionally separating difficulty levels.Source: Figure 10 · p. 20, Figure 11 · p. 20, Figure 12 · p. 21