SQL-Trail: Multi-Turn Reinforcement Learning with Interleaved Feedback for Text-to-SQL

Harper Hua, Zhen Han, Zhengyuan Shen, Meng-Chieh Lee, Sheng Guan, Qi Zhu, Sullam Jeoung, Yueyan Chen, Yunfei Bai, Shuai Wang, Vassilis N. Ioannidis, Huzefa Rangwala

TL;DR

SQL-Trail is a novel multi-turn reinforcement learning (RL) framework that transforms Text-to-SQL generation from a fragile, one-shot translation task into an interactive, self-correcting dialogue with the database. By utilizing an adaptive turn-budget mechanism and a dense composite reward panel, SQL-Trail sets a new state of the art, outperforming much larger proprietary models while demonstrating up to 18× higher data efficiency than prior single-pass RL methods.

What Problem Does This Paper Address?

Most state-of-the-art Text-to-SQL systems rely on a single-pass paradigm: given a natural language question and a database schema, the model attempts to generate the perfect SQL query in a single shot.

However, real-world databases present severe challenges: ambiguous user questions, massive and noisy schemas, and strict syntax requirements where a single typo breaks the query. Humans don't write complex code this way; they interactively probe the database, examine intermediate results, and debug errors. Single-pass models lack this capacity to self-correct, leading to a significant performance gap on complex benchmarks.

Text-to-SQL challenges and the shift to multi-turn generation.

Methods

The authors introduce SQL-Trail, an agentic framework that implements an iterative reason–execute–observe loop. The model generates a reasoning trace and a candidate SQL query, executes it against a real database engine, and uses the structured feedback (data previews or error messages) to refine its next attempt.

The training pipeline consists of two main phases:

  1. Supervised Fine-Tuning (SFT) Distillation: Small open-weight models (Qwen2.5-Coder 3B/7B/14B) are trained on high-quality multi-turn trajectories generated by a frontier teacher model (Claude 3.7 Sonnet). This establishes a strong baseline for instruction-following and tool use.
  2. Multi-Turn Reinforcement Learning (GRPO): The model is optimized using Group Relative Policy Optimization (GRPO), enhanced by two core innovations:
  3. Clip-Higher GRPO: A modified clipping mechanism that raises the upper bound for likelihood ratios, allowing the policy to make larger updates on promising, highly exploratory trajectories.
  4. Composite Reward Panel: Instead of relying solely on sparse binary execution rewards, the authors introduce a six-term rule-based reward panel. This includes a final execution reward, a difficulty-aware turn-budget reward (penalizing redundant steps), and four auxiliary shaping rewards (bi-gram overlap, schema grounding, syntax validity, and format compliance).
Overview of the SQL-TRAIL framework and training pipeline.

Datasets

  • Spider: A widely used cross-domain Text-to-SQL benchmark. Trajectories derived from Spider-train were used for the SFT phase, and the model was evaluated on the dev/test sets.
  • SynSQL-2.5M: A massive synthetic corpus used to curate the RL training set. The authors filtered this down to 1,027 highly informative samples, split into a difficulty-balanced set (700 "hard-but-solvable" queries) and an exploration set (327 persistent failure modes).
  • BIRD: A highly challenging, value-centric benchmark with large real-world schemas. The BIRD-dev set was held out entirely during training to evaluate out-of-distribution (OOD) generalization.
  • Robustness Suites: Spider-DK, Spider-Syn, and Spider-Realistic were used to test resilience against schema perturbations and lexical shifts.

Key Insights and Ideas

  • Higher Ceiling via Interaction: Single-pass RL models improve rapidly but saturate early. Multi-turn RL continues to scale because the environment provides richer feedback and a longer optimization horizon.
  • The Power of Token-Level Guidance: Counterintuitively, sparse execution rewards provide weak optimization signals early on. The bi-gram similarity reward proved to be the most impactful partial reward, providing dense token-transition signals that stabilize the generation of valid SQL skeletons.
  • Adaptive Turn Budgeting: Rather than overthinking easy queries or giving up on hard ones, the turn-efficiency reward successfully incentivizes the agent to dynamically allocate more interaction depth to complex questions while remaining concise on simple ones.
Training dynamics showing multi-turn RL outperforming single-pass RL over time.

Key Results

  • Outperforming Proprietary Giants: On the OOD BIRD-dev benchmark, SQL-Trail-7B achieved 64.2% execution accuracy (via majority voting), outperforming the much larger Claude 3.7 Sonnet teacher model by 4.1 percentage points, despite never seeing BIRD data during training.
  • Extreme Data Efficiency: SQL-Trail achieved these state-of-the-art results using just 1,873 training examples (1,000 SFT + 1,027 RL), delivering 7× to 18× higher data efficiency per 1,000 samples compared to prior single-pass RL baselines like SQL-R1.
  • Robustness: SQL-Trail-7B set new performance records across all three robustness suites, showing particular strength on Spider-Syn, proving that environment probing helps the agent infer user intent despite noisy or altered schema names.

Limitations and Future Work

  • Environment Dependency: SQL-Trail assumes access to an interactive database execution environment during inference. This may be impractical in environments with strict privacy controls, limited connectivity, or high query costs.
  • Inference Overhead: Multi-turn interactions inherently increase latency and token consumption compared to single-pass generation, presenting a clear cost-quality trade-off for production deployments.
  • Inductive Biases: The heavy reliance on reward shaping (like bi-gram matching) might bias the model toward specific syntactic structures, potentially penalizing alternative but equally valid SQL formulations.

Summary updated

BibTeX
@inproceedings{hua2026sql,
  author = {Harper Hua and Zhen Han and Zhengyuan Shen and Meng-Chieh Lee and Sheng Guan and Qi Zhu and Sullam Jeoung and Yueyan Chen and Yunfei Bai and Shuai Wang and Vassilis N. Ioannidis and Huzefa Rangwala},
  title = {{SQL-Trail: Multi-Turn Reinforcement Learning with Interleaved Feedback for Text-to-SQL}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  doi = {10.18653/v1/2026.acl-long.1677},
}
Figure