---
title: Zero-shot & Few-shot NL2SQL
url: https://www.emergentmind.com/topics/zero-shot-and-few-shot-nl2sql
type: topic
---

# Zero-shot & Few-shot NL2SQL

Zero-shot and few-shot NL2SQL refer to methodologies that enable models to generate SQL queries from natural language without, or with minimal, task-specific supervision, especially on unseen database schemas, domains, or query structures. These approaches leverage large pre-trained language models (PLMs), large language models (LLMs), meta-learning, self-augmentation, execution-guided search, and prompt engineering. They are critical for adapting NL2SQL systems to real-world scenarios where exhaustive annotation is unattainable or where generalization to new environments is required.

## 1. Zero-Shot and Few-Shot NL2SQL: Definitions and Core Challenges

Zero-shot NL2SQL comprises mapping a natural language input $Q$ and database schema $S$ to a SQL query $Y$, where the model has not been exposed to any annotated (Q, S, SQL) triplets for the target schema or domain. Few-shot NL2SQL permits a small number $k \ll |\text{train}|$ of annotated examples per test schema, leveraging either in-context learning or meta-learning.

Core challenges include:

- **Schema Generalization:** Adapting to new tables, columns, and relational structures absent in training data.
- **Compositionality:** Composing complex SQL patterns (e.g., joins, nested queries) absent from training supervision.
- **Semantic Parsing Robustness:** Disambiguating question intents and aligning them precisely with schema elements, particularly when header names and cell values are ambiguous or unseen.
- **Minimal Data Regime:** Achieving high test-time performance with little to no labeled data from the target domain—posing a substantial drop in accuracy for standard supervised models.

On standard benchmarks, the gap between zero/few-shot and fully supervised models remains non-trivial, especially for schemas with little overlap with training data [2010.05243][2109.05395][2306.08891][2511.04710][2502.11438][2502.17248].

## 2. Fundamental Methodological Paradigms

### 2.1 Slot-Filling and Sketch-Based Models

Early data-agnostic approaches (e.g., RoBERTa+Bi-LSTM slot models) decompose NL2SQL as a sequence of slot prediction tasks:
- SELECT $\langle$aggregate$\rangle$ $\langle$column$\rangle$ FROM $\langle$table$\rangle$ [WHERE $\langle$col$\rangle$ $\langle$op$\rangle$ $\langle$val$\rangle$]*
- Each slot is predicted with a separate submodel, and input features comprise question and header embeddings plus binary knowledge vectors encoding string matches [2010.05243].

### 2.2 Content-Aware and Meta-Learning Architectures

Advances include leveraging table content via similarity-driven cell selection for value grounding, and introducing meta-learning (e.g., MAML) so that parameter updates on support sets induce rapid generalization to novel tables. Auxiliary content features are used for WHERE-column and WHERE-value selection, and episodic training splits support and query tables to simulate zero-shot transfer [2109.05395].

### 2.3 Large Language Models and Prompt-Based Inference

LLMs perform text-to-SQL via prompt engineering, without or with very few in-context exemplars. Prompt templates range from:
- **Zero-shot:** Provide only schema and instruction header; model must synthesize full SQL pattern de novo [2511.04710].
- **Few-shot retrieval:** Add $k$ NL-SQL paired exemplars based on random or similarity-based retrieval or self-augmentation [2511.04710][2502.11438][2203.08568].
- **In-context learning for dialogue state tracking:** The IC-DST framework reformulates DST state changes as SQL SELECT statements and builds prompts with schema blocks, in-context exemplars, and a test request; exemplars are selected via SBERT-based retrieval [2203.08568].

### 2.4 Self-Augmentation and Example Filtering

SAFE-SQL introduces a self-augmentation framework: the LLM is prompted to generate $N$ synthetic NL-SQL pairs and corresponding reasoning paths, which are then filtered by semantic similarity $S(Q_e,Q_t)$, structural alignment $A(Q_e,Q_t)$, and a reasoning path quality rating $R_e$. Only examples with composite score above $\theta$ are retained for in-context learning, removing dependency on external retrieval sets [2502.11438].

### 2.5 Execution-Guided Search and Monte Carlo Tree Search (MCTS)

Alpha-SQL frames zero-shot SQL generation as an MCTS problem, with LLMs dynamically proposing SQL construction actions (e.g., schema selection, column value identification, revision). Candidate SQLs are scored by self-supervised execution consistency rewards without requiring gold annotation, mitigating the combinatorial search space present in zero supervision [2502.17248].

### 2.6 Hybrid PLM–LLM Pipelines

ZeroNL2SQL interleaves a schema-aware, fine-tuned PLM to generate valid “sketches” (SELECT/FROM/KEYWORDS) with an LLM that completes the sketch (WHERE, JOIN, ORDER BY) using black-box prompting and database-aware predicate calibration. Execution-based selection ensures functional correctness [2306.08891].

## 3. Prompt Construction and Example Selection Strategies

Prompt construction is central to both zero- and few-shot NL2SQL performance:

| Prompt Type           | Input Components                                    | Example Selection             |
|---------------------- |-----------------------------------------------------|-------------------------------|
| Zero-shot             | Instruction, schema                                 | None or formatting example    |
| Few-shot (retrieval)  | Instruction, schema, $k$ exemplars                  | Random, similarity, or retriever|
| Self-augmented        | Instruction, schema, LLM-generated examples + filter| Self-generation + thresholding|
| Structured Few-shot   | Canonicalized instruction/schema/response triples   | Hand-crafted or auto-selected |

In few-shot regimes, schema-aware and structured prompts provide substantial gains over naive concatenation. Ordering by relevance and explicit reasoning paths (as chain-of-thought demonstrations) further boost performance for compositional or extra-hard queries [2511.04710][2502.11438][2203.08568].

## 4. Performance Analysis and Benchmark Results

Recent benchmarks on Spider, BIRD, and MultiWOZ demonstrate:

- Data-agnostic RoBERTa-based models reach execution accuracy (Acc_ex) of 74.7% in true zero-shot regimes (unseen schemas), showing only a 1–2 point drop from seen schemas [2010.05243].
- MC-SQL, leveraging table content and meta-learning, achieves 89.7% EX on WikiSQL zero-shot dev, +7.7% logical-form gain over baseline SQLova [2109.05395].
- SAFE-SQL (self-augmentation) obtains execution accuracy of 87.9% (GPT-4o) on Spider dev, surpassing best few-shot baselines by over 1 pp and naive zero-shot by ≈15 pp [2502.11438].
- GEMMA-SQL yields 65% EM/62% TS in zero-shot, with structured and schema-aware few-shot prompting pushing up to 88% EM/86% TS [2511.04710].
- Alpha-SQL reaches 69.7% EX on BIRD dev (Qwen2.5-32B), 2.5 pp above GPT-4o-based zero-shot, and matches best fine-tuned baselines on Spider dev with 87.0% [2502.17248].
- ZeroNL2SQL achieves a 44.9% execution accuracy on KaggleDBQA zero-shot (vs. 31.9% for PLM-only, 24.3% for vanilla ChatGPT), and 74.9% on Dr.Spider, indicating 10–20 pp gains from combining sketch PLMs, LLMs, and predicate calibration [2306.08891].

Few-shot gains are typically +10–20 pp for EM/TS when moving from zero-shot to schema/rank-aware prompting or in-context learning.

## 5. Component Ablations and Limitations

Ablation studies highlight critical design choices:

- Removing schema linking or reasoning-path demonstrations in SAFE-SQL yields −7.5 and −3.5 pp EX, respectively; not using self-augmentation drops EX by −10.8 pp [2502.11438].
- In Alpha-SQL, omitting key MCTS actions (schema selection, SQL revision) results in 0.6–1.8 pp accuracy deficit [2502.17248].
- Content-aware predictors yield >6 pp LF improvement on zero-shot WikiSQL; omitting meta-learning decreases performance by 1–2 pp [2109.05395].
- Data-agnostic, privacy-preserving approaches depend acutely on descriptive header names and fail on ambiguous mappings or multi-table SQL [2010.05243].

Recognized limitations involve:

- Restricted SQL expressiveness (single-table, limited clause support) in earlier models [2010.05243][2109.05395].
- Dependence on LLM base quality for prompt-based/self-augmentation methods; weak LLMs generate poor or noisy synthetic examples [2502.11438].
- Manual or heuristic thresholds for OOD and relevance filtering, which require tuning and may not generalize across domains [2502.11438][2511.04710].
- Computational cost for meta-learning and MCTS-based approaches; scaling to multi-turn or conversational NL2SQL is a continuing challenge [2306.08891][2502.17248].

## 6. Extensions, Applications, and Future Directions

Current research highlights several promising directions:

- Extending zero/few-shot NL2SQL to multi-turn, conversational settings, as in text-to-SQL-driven dialogue state tracking [2203.08568][2306.08891].
- Hybridization of search-based (MCTS) and few-shot strategies, e.g., using few-shot completions as seeds for search or reward model fine-tuning [2502.17248].
- Automating relevance threshold calibration using statistical or adversarial methods [2502.11438].
- Incorporating execution-guided or SMT-based symbolic constraints to prune semantically invalid candidate queries before prediction or as verifier models [2502.17248][2306.08891].
- Leveraging self-augmented or automatically synthesized demonstrations for downstream fine-tuning or as support for different SQL dialects and domain adaptation [2502.11438][2511.04710].

A plausible implication is that, as LLM capabilities increase and example synthesis/filtering becomes more reliable and automated, the distinction between few-shot and zero-shot NL2SQL will further blur—making in-context, prompt-driven generation with execution feedback the default paradigm, especially for emerging database environments and unseen cross-domain table schemas.

Source: https://www.emergentmind.com/topics/zero-shot-and-few-shot-nl2sql