TL;DR
MTIR-SQL introduces a multi-turn reinforcement learning framework for Text-to-SQL that allows large language models (LLMs) to interactively execute queries and self-correct based on real-time database feedback. By enhancing the GRPO algorithm with a trajectory filtering mechanism and removing traditional KL constraints, a compact 4B-parameter model achieves state-of-the-art performance, outperforming models more than twice its size.
What Problem Does This Paper Address?
Translating natural language questions into accurate SQL queries (Text-to-SQL) is highly challenging, especially when dealing with complex multi-table joins, nested structures, or real-world "dirty" data.
While Reinforcement Learning (RL) has recently been used to optimize LLMs for this task, existing methods treat database execution feedback as a static, final scalar reward. This means the model generates a query in a single shot and receives a score, but it cannot dynamically debug or correct syntax and semantic errors during the generation process. Furthermore, applying standard RL algorithms like GRPO (Group Relative Policy Optimization) to multi-turn tool-use scenarios typically suffers from severe training instability and reward collapse due to distribution drift from external environment outputs.
Methods
The authors propose MTIR-SQL (Multi-turn Tool-Integrated Reasoning SQL), a framework that reframes Text-to-SQL as an interactive, multi-turn dialogue between the LLM and a database executor tool.
Key innovations include:
- Multi-turn Execution Paradigm: Instead of generating a query in one shot, the model generates a Chain-of-Thought (CoT) process and a tool call, receives the database execution result (or error message), and uses that feedback to progressively refine its query across multiple turns ($T$).
- GRPO-Filter Algorithm: An extension of standard GRPO tailored for multi-turn interactions:
- Unconstrained Optimization: The traditional KL divergence penalty constraint between the policy and reference model is removed to prevent distribution collapse and allow more flexible policy updates.
- Selective Rollout Filtering: To stabilize training, the framework filters out low-quality trajectories during rollout generation (e.g., discarding rollouts that exceed maximum tries without a correct answer, have inaccurate tool call formats, or show low variance within a group).
- Streamlined Reward Design: Combines format rewards ($R_f$), execution feasibility rewards ($R_e$), and final result correctness rewards ($R_r$) to guide the policy effectively.
Datasets
The framework was trained and evaluated on two major Text-to-SQL benchmarks:
- SPIDER: A large-scale, cross-domain benchmark focusing on SQL structural complexity across 200 databases.
- BIRD: A challenging real-world benchmark featuring large-scale databases with "dirty" data, emphasizing both execution accuracy and efficiency.
The authors applied strict data filtering to ensure reference queries returned valid, non-empty results to avoid reward hacking during RL training.
Key Insights and Ideas
- Feedback as Context, Not Just Reward: Treating database execution errors or empty results as conversational context rather than just a negative scalar reward allows the model to learn how to debug itself, mimicking a human developer's workflow.
- The Danger of KL Constraints in Multi-Turn RL: Traditional RLHF relies heavily on KL penalties to keep the model close to the base policy. However, the authors found that in multi-turn tool use, removing the KL constraint combined with aggressive trajectory filtering actually stabilizes training and prevents reward collapse.
- Optimal Turn Budgeting: More turns generally lead to better performance because the model has more chances to self-correct. However, an excessive number of turns (e.g., 6+) can introduce training instability and reward saturation, indicating a sweet spot for interaction depth.
Key Results
- Small Model, Big Impact: Built on top of a modest Qwen3-4B base model, MTIR-SQL achieved 64.4% execution accuracy on the BIRD Dev set. This significantly outperforms much larger open-source models like Qwen2.5-Coder-7B (50.9%) and SFT Code5-15B (58.47%), and matches the performance of proprietary models like ChatGPT + CoT (64.64%).
- Benchmark Superiority: On the SPIDER benchmark, the framework achieved 84.6% execution accuracy on the Dev set and 83.4% on the Test set, demonstrating strong cross-domain generalization.
- Ablation Validation: Removing the execution reward ($R_e$) caused the largest performance drop (from 63.1% down to 59.4% in ablation runs), proving that real-time execution feedback is the cornerstone of the framework's success.
Limitations and Future Work
- Turn-Induced Instability: While multi-turn reasoning helps, setting the maximum tool-calling turns too high (e.g., 6) can still lead to training instability and reward collapse.
- Computational Overhead: Multi-turn rollouts increase sequence lengths and interaction steps during training and inference, which demands higher computational resources and increases latency.
- Future Directions: The authors suggest further exploring balanced reward systems and optimizing interaction efficiency to reduce the computational footprint of multi-turn reasoning.
Summary updated