Manuscript Offprint

arXiv:2608.27796

ReToolSQL: Agentic Reinforcement Learning for Robust Text-to-SQL

Pratik Kakkar, Chandra Dhir, Ravi Shankar, Pareekshit Reddy Gaddam, Anup Shirgaonkar

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original. This text is shared under the same licence.

Abstract

Recent work has shown that reinforcement learning from execution feedback can substantially improve text-to-SQL performance, often enabling smaller models to match or exceed much larger systems. However, most existing approaches treat SQL generation as a single-turn task, limiting the model's ability to recover from errors through iterative refinement. We present RETOOLSQL, a two-stage training framework for text-to-SQL that combines (i) a supervised warm-start on rejection-sampled reasoning traces with (ii) agentic reinforcement fine-tuning (RFT) over multi-turn tool-use trajectories. The key insight is that the two stages act on complementary axes, the supervised fine-tuning (SFT) on verified privileged-teacher traces expands the set of solvable questions (raising pass@k coverage on the hardest cases), while RFT converts that expanded capability into higher single-pass accuracy by teaching the model when to verify, what evidence to retrieve, and how to repair faulty SQL from execution feedback. Applied to Gemma 4 instruction-tuned (31B), RFT alone achieves 73.66% execution accuracy (EX) on the BIRD-SQL development benchmark (74.12% EX with self-consistency). Initializing RFT from the SFT checkpoint (SFT→RFT) yields our strongest model at 74.32% EX single-pass and 74.77% EX with self-consistency. At the time of writing, this ranked first on the BIRD single-model development-set leaderboard. The approach uses composite rewards anchored on execution correctness, requires no human annotation beyond the benchmark itself, and operates within a single dense 31B model, showing that a properly designed SFT→RFT pipeline over tool-use trajectories is a practical path toward robust enterprise-grade text-to-SQL.

Keywords: Text-to-SQL, BIRD-SQL, Reinforcement Learning from Execution Feedback, GRPO, Agentic Tool Use, Self-Consistency Decoding

1 Introduction

Text-to-SQL is a promising interface for natural-language data access, but robust deployment remains difficult in realistic settings where schemas are large, values are noisy, and correctness depends on execution rather than surface-form similarity. Benchmarks such as BIRD (Li et al., 2023) highlight this challenge by evaluating systems through execution accuracy (EX) on complex cross-domain databases, exposing persistent failures in schema linking, value grounding, and numerical or temporal reasoning. Although recent instruction-tuned large language models can generate correct SQL for many questions, they remain brittle as a single incorrect join, literal, or aggregation often causes failure, and single-pass generation offers no mechanism for recovery.

*Corresponding authors: pratik.kakkar@jpmchase.com, chandra.dhir@jpmchase.com

Disclaimer: This paper was prepared for informational purposes and is not a product of the Research Department of JPMorganChase. JPMorganChase makes no representation, warranty or undertaking whatsoever and disclaims all liability for the completeness, accuracy or reliability of the information contained herein. This document is not intended as investment research or investment advice, or a recommendation, offer or solicitation for the purchase or sale of any security, financial instrument, financial product or service, or to be used in any way for evaluating the merits of participating in any transaction, and shall not constitute a solicitation under any jurisdiction or to any person, if such solicitation under such jurisdiction or to such person would be unlawful.

ReToolSQL Training Architecture

Figure

Figure 1: High-level overview of RETOOLSQL. A natural-language question and enriched schema are processed by the Gemma 4 31B policy, which interacts with database tools across multiple turns to produce verified SQL. In the training loop, B1,B2,…B_1, B_2, \ldots denote the prompt groups sampled per training step (each containing G=16G=16 multi-turn trajectories for a single question), and R1,R2,…R_1, R_2, \ldots the trajectory-level composite rewards R=∑kwkRkR = \sum_k w_k R_k (Section 3.8) that yield the group-relative advantages driving the GRPO update. Groups with zero reward variance (std = 0) are discarded by dynamic sampling (Section 3.5), as they contribute no gradient signal.

Recent work shows that reinforcement learning from execution feedback can substantially improve text-to-SQL performance, often allowing relatively smaller models to rival much larger systems (Yao et al., 2026; Shao et al., 2024). Yet most existing methods still treat SQL generation as a single-turn act: the model proposes one query, receives a terminal reward, and is not explicitly trained to use execution feedback as part of an iterative reasoning process. At the same time, many of the strongest systems rely on increasingly heavyweight pipelines with multiple generators, selectors, or orchestration stages (Pourreza et al., 2025; Liu et al., 2026; Talaei et al., 2024), improving accuracy at the cost of inference-time complexity. This motivates a central question: can a single dense model learn to propose, verify, and repair its own SQL through tool interaction while retaining a simple serving architecture?

We address this question with RETOOLSQL, a text-to-SQL system trained with agentic reinforcement learning over multi-turn tool-use trajectories (Figure 1). Our approach adapts the tool-integrated RL recipe of ReTool (Feng et al., 2026), which teaches an LLM when and how to invoke a code interpreter for mathematical reasoning, to the task of natural-language-to-SQL generation. In place of the code interpreter, we equip the policy with a suite of read-only database tools (a sandboxed SQL executor, a column profiler, and a BM25 value search) and add schema-linking reward terms, so that tool use is grounded in real database evidence specific to text-to-SQL. Instead of treating database execution as a post-hoc filter, RETOOLSQL places these read-only tools directly inside the training environment and learns from their execution feedback: the policy can execute candidate SQL, inspect runtime feedback, profile uncertain columns, and search stored values before committing to a final answer. Training uses a GRPO-style objective (Shao et al., 2024) over complete propose-verify-repair trajectories with a composite reward anchored on execution correctness and schema-linking signals. As a result, the policy learns not only to produce SQL, but also when to verify, what evidence to retrieve, and how to revise a faulty draft in response to the database feedback.

Reinforcement-learned Tool-use for SQL.

Applied to Gemma 4 instruction-tuned (31B), agentic RL alone achieves 73.66% execution accuracy on the BIRD-SQL development set (74.12% with self-consistency). Initializing RL from a supervised fine-tuning (SFT) checkpoint trained on rejection-sampled reasoning traces (a two-stage SFT→RFT pipeline) yields our strongest model at 74.32% single-pass and 74.77% with self-consistency, improving over both individual stages. The SFT warm-start expands pass@16 coverage on hard questions, and agentic RL converts that expanded coverage into higher single-pass accuracy. Together, these results show that a carefully designed SFT→RFT pipeline over tool-use trajectories is a practical path toward robust, enterprise-grade text-to-SQL within a single dense model.

References (19)