Papers
Topics
Authors
Recent
Search
2000 character limit reached

CogniSQL-R1-Zero: Execution-Aligned Text-to-SQL

Updated 6 July 2026
  • CogniSQL-R1-Zero is a Text-to-SQL reinforcement learning framework that emphasizes execution correctness by directly optimizing SQL execution success.
  • It leverages a lightweight 7B Qwen/Qwen2.5-Coder model with PEFT to achieve up to 69.68% execution accuracy on the BIRD-dev benchmark.
  • The system employs Group Relative Policy Optimization and a structured reward design to replace complex multi-stage pipelines with a single, efficient model.

CogniSQL-R1-Zero is a Text-to-SQL reinforcement learning framework and model for translating natural-language questions into executable SQL over relational database schemas. Its defining design choice is to optimize execution correctness directly, using a lightweight reward centered on execution success and output-format compliance rather than intermediate supervision, hybrid multi-stage pipelines, or complex reward shaping. Built on Qwen/Qwen2.5-Coder-7B-Instruct, it is presented as a lightweight, execution-aligned RL model and reports 59.97% execution accuracy on BIRD-dev in single-sample generation, with 69.68% under best-of-6 test-time scaling (Gajjar et al., 8 Jul 2025).

1. Task definition and motivation

The problem setting is Text-to-SQL: mapping a natural-language question to an SQL query that is not merely syntactically valid, but semantically correct and executable against the target database. The work emphasizes that LLMs often generate SQL that appears plausible yet fails at execution time, especially under complex schema layouts, multi-join queries, ambiguous natural-language questions, and cases where database-specific schema semantics matter. The main benchmark is BIRD-SQL, whose training split contains 9,428 training examples spanning 95 databases and 37 domains (Gajjar et al., 8 Jul 2025).

The motivation for a lightweight RL approach is framed against four families of prior methods: supervised, instruction-tuned, hybrid multi-stage pipelines, and reward-shaped systems. The reported concerns are high compute cost, inference latency from multi-stage reasoning or multi-agent systems, fragile supervision from intermediate reasoning labels, poor generalization when SFT overfits to a reasoning style, and reward engineering complexity with associated reward-hacking risks. Several internal attempts are described before the final system: a hybrid reasoning-plus-generation pipeline, an agentic multi-agent pipeline, supervised finetuning on distilled 32B reasoning traces, self-generated-data SFT, and finally RL fine-tuning. The paper’s central thesis is that if the task objective is execution correctness, the model should optimize execution success directly.

This framing also clarifies what CogniSQL-R1-Zero is not. It is not primarily a reasoning-trace distillation system, nor an instruction-following SQL generator, nor a multi-model orchestration stack. It replaces a hybrid pipeline that used LLaMA 3.1 8B as a reasoning engine and CodeStral 22B for SQL generation—reported at about 75% execution accuracy on 200 sampled queries—with a single 7B model trained end-to-end with RL.

2. Model backbone, prompting, and systems configuration

CogniSQL-R1-Zero is based on Qwen/Qwen2.5-Coder-7B-Instruct, a 7B-parameter transformer decoder. Adaptation is done with PEFT / low-rank adapters rather than full fine-tuning, reducing memory usage. Training is run on 4 NVIDIA A100 GPUs, each with 40 GB VRAM, using DeepSpeed ZeRO-2, gradient accumulation, and VLLM for faster multi-sample evaluation (Gajjar et al., 8 Jul 2025).

The reported efficiency numbers are explicit. ZeRO-2 gives about a 2.96× speedup relative to a single-GPU setup for an epoch: single A100: ~18h 22m 35s versus 4× A100 with ZeRO-2: ~6h 12m 50s. This systems profile is integral to the paper’s claim that strong Text-to-SQL performance can be obtained under comparatively modest compute.

Each training prompt includes four elements: DDL statements with table/column descriptions, external knowledge, the natural-language question, and an enforced output format with the tags:

η=10−5\eta=10^{-5}9

Prompts longer than 3000 tokens are filtered out to fit a 5000-token context window. The structured prompt is intended to reduce ambiguity and to help the model associate schema elements with the question and the required output format. The paper later reports that prompt design materially affects both convergence and final accuracy, and that removing <reasoning> tags weakens reward propagation.

3. Reinforcement learning formulation and reward design

The optimization method is Group Relative Policy Optimization (GRPO). For each prompt, the model samples a group of candidate SQL outputs and uses the best candidate’s reward to drive policy improvement. The reported hyperparameters are group size G=6G=6, sampling temperature T=0.9T=0.9, learning rate η=10−5\eta=10^{-5}, KL penalty β=0.001\beta=0.001, and clip ratio ϵ=0.2\epsilon=0.2 (Gajjar et al., 8 Jul 2025).

The reward design contains four components. The first is the format reward RfR_f, which requires exact compliance with the prescribed tag structure:

Rf(o)={1,if o conforms to ⟨reasoning⟩⟨/reasoning⟩⟨answer⟩⟨/answer⟩, 0,otherwise.R_f(o)= \begin{cases} 1, & \text{if } o \text{ conforms to } \langle\text{reasoning}\rangle\langle/\text{reasoning}\rangle\langle\text{answer}\rangle\langle/\text{answer}\rangle,\ 0, & \text{otherwise}. \end{cases}

The second is the soft format reward RsfR_{sf}, which gives partial credit when the basic tag structure matches a regex:

Rsf(o)={0.5,if basic tag structure matches regex, 0,otherwise.R_{sf}(o)= \begin{cases} 0.5, & \text{if basic tag structure matches regex},\ 0, & \text{otherwise}. \end{cases}

The third and dominant term is the correctness reward RcR_c, defined by executing the generated SQL and comparing its result to the ground truth:

T=0.9T=0.90

Execution errors or timeouts also receive zero reward. The fourth term is a length reward T=0.9T=0.91, which penalizes overly long outputs:

T=0.9T=0.92

The total reward is

T=0.9T=0.93

with the explicit design choice that

T=0.9T=0.94

so that execution correctness dominates. In ablations, the reported weighting emphasizes correctness over formatting, with T=0.9T=0.95, T=0.9T=0.96, and T=0.9T=0.97; equal weighting led to models that produced well-formed but incorrect SQL.

The group objective is defined through the maximum reward in the sampled set:

T=0.9T=0.98

and the expected GRPO objective is

T=0.9T=0.99

The clipped surrogate objective is written as

η=10−5\eta=10^{-5}0

where η=10−5\eta=10^{-5}1 is the probability ratio between current and old policy, η=10−5\eta=10^{-5}2 is a fixed reference policy, η=10−5\eta=10^{-5}3 is the advantage estimate, and η=10−5\eta=10^{-5}4 is the group baseline. The paper’s rationale for GRPO is that it avoids a separate value critic, reduces memory overhead, stabilizes training via group baselines, and is suitable for sparse rewards.

4. Training workflow and released datasets

Two training variants are described. The final system is Pure-RL / R1-Zero: no supervised warm-up, direct GRPO training on Qwen2.5-Coder-7B-Instruct, six candidates sampled per prompt, reward computation, and updates using the group-relative advantage. The alternative is Cold-start + RL, which first performs a short supervised phase on 500 random BIRD examples for 3,000 steps, then switches to GRPO RL. The cold-start variant improves early stability but ends up slightly below the pure RL model. Evaluation is performed on BIRD-dev every 1,000 RL steps, with early stopping after no improvement over 3 evals. Convergence occurs at about 34K RL steps for pure RL and 30K steps for the cold-start variant (Gajjar et al., 8 Jul 2025).

The paper releases two datasets intended to support efficient and interpretable Text-to-SQL research. The first is a Positive-Sampling Corpus of 36,356 examples. It is constructed from the 9,428 BIRD training prompts by sampling 6 candidate SQLs per prompt from Qwen-7B-Coder at temperature 0.9, executing them, and retaining only correct ones. The result is 36,356 high-precision SQL examples, each paired with a reasoning trace or chain of thought. The stated significance is that these are execution-verified positive examples, useful for alignment-driven RL, usable with any base LLM, and closer to the intended execution objective than conventional supervision.

The second release is a set of QWQ-32B reasoning traces, reported as 5,024 examples produced by prompting a 32B QWQ model to generate step-by-step reasoning followed by SQL, with only execution-matching outputs retained. One section later reports that filtering leaves 4,928 reasoning-SQL pairs. The paper presents these traces as useful for explicit stepwise reasoning supervision, interpretability, and both supervised and RL fine-tuning. A plausible implication is that the discrepancy between 5,024 and 4,928 reflects successive filtering stages rather than a conceptual inconsistency.

5. Empirical performance on BIRD-dev

The primary metric is execution accuracy (Ex%) on BIRD-dev. The headline result is 59.97% execution accuracy in single-sample generation. In the post-training comparison, No post-training (Qwen2.5-7B-Coder) achieves 52.02, 1-step RL (Rejection Sampling) reaches 57.04, and CogniSQL-R1-Zero reaches 59.97 (Gajjar et al., 8 Jul 2025).

Setting Single-sample Ex% Best-of-6 Ex%
No post-training (Qwen2.5-7B-Coder) 52.02 67.25
1-step RL (Rejection Sampling) 57.04 69.00
CogniSQL-R1-Zero 59.97 69.68

Best-of-6 test-time scaling substantially increases performance: 67.25% for the untrained baseline, 69.00% for 1-step RL, and 69.68% for CogniSQL-R1-Zero. The paper describes this as one of its most practical findings, quantifying the best-of-6 gain as about +9.71% absolute over single-sample performance.

The reported baseline comparisons are unusually broad. Under 10B parameters, CogniSQL-R1-Zero at 59.97 exceeds Think2SQL-7B: 56.1, SFT CodeS-7B: 57.17, and Qwen2.5-Coder-7B-Instruct: 50.9. In the 10B–30B range, it exceeds Codestral-22B: 52.7, Qwen2.5-14B-Instruct: 56.7, and SFT CodeS-15B: 58.47. Among 30B and above / unknown size, it exceeds GPT-4 Baseline: 46.35, Mistral Baseline: 53.52, DeepSeek Baseline: 56.13, and SuperSQL: 58.50. The paper therefore characterizes the result as a 7B RL-trained model outperforming much larger systems, including GPT-4, Mistral 123B, and DeepSeek-Coder 236B, on BIRD-dev execution accuracy.

6. Ablations, interpretation, limitations, and relation to R1-Zero-style work

The ablations are used to argue that execution-aligned RL, rather than reasoning-style imitation alone, drives the reported gains. A particularly strong result is the comparison between SFT and RL: a baseline around 52%, SFT on distilled traces dropping to about 46%, self-generated-data SFT reaching about 57.3%, and RL reaching 59.97% (Gajjar et al., 8 Jul 2025). This directly supports the paper’s claim that supervised finetuning can overfit to supervision style and fail to optimize the actual end metric.

Several additional design findings are reported. Prompt structure matters: adding schema DDL, external knowledge, and explicit reasoning/answer tags helps convergence and accuracy, and removing <reasoning> tags weakens reward propagation. Hyperparameter trade-offs matter: among group sizes η=10−5\eta=10^{-5}5 and temperatures η=10−5\eta=10^{-5}6, the best tradeoff is η=10−5\eta=10^{-5}7 and η=10−5\eta=10^{-5}8; too large a group increases GPU stalls, while higher temperature increases invalid SQL. KL penalty scheduling improves accuracy from 58.4% to 59.97%, an about +1.6% absolute gain. For PEFT, ranks 16, 32, 64, 128 were tested, with rank 64 identified as the best tradeoff because it fit in memory and converged efficiently.

The reported failure modes are concentrated in complex multi-join queries, nested subqueries, and a small fraction of malformed SQL or runtime errors. The limitations section is correspondingly narrow and concrete: the method is evaluated primarily on BIRD-dev, so broader cross-dataset generalization is not fully demonstrated; remaining errors cluster in hard multi-join and nested-subquery cases; best-of-6 inference improves accuracy but can increase latency by up to 6×; and the reward remains relatively simple, so more fine-grained execution rewards may help on harder cases.

A common misconception would be that CogniSQL-R1-Zero is simply a formatting trick or a chain-of-thought imitation system. The ablations argue against both interpretations. Equal reward weighting produced better-formatted but incorrect SQL, and distilled-trace SFT underperformed RL. The paper’s interpretation is that training objective alignment matters more than raw size for Text-to-SQL. In a broader research context, Table-R1-Zero is described as highly relevant and arguably a direct conceptual predecessor: it applies RLVR with GRPO and verifiable rewards to table reasoning rather than SQL generation, showing that an R1-Zero style recipe can work for table-grounded structured reasoning with a 7B-scale open LLM (Yang et al., 29 May 2025). This suggests that CogniSQL-R1-Zero belongs to a broader class of structured-reasoning systems in which verifiable rewards, strict output formats, and compact backbones are sufficient to induce strong task-aligned behavior without frontier-scale inference models.

Definition Search Book Streamline Icon: https://streamlinehq.com
References (2)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to CogniSQL-R1-Zero.