TL;DR
Reward-SQL introduces CoCTE, a divide-and-conquer reasoning framework that breaks complex Text-to-SQL tasks into a sequence of executable Common Table Expressions (CTEs). By pairing this execution-aware generation with a Process Reward Model (PRM) during reinforcement learning, it achieves state-of-the-art performance for 8B-parameter models, matching or beating models 100x its size.
What Problem Does This Paper Address?
Translating natural language questions into SQL queries (Text-to-SQL) is highly challenging when queries involve multi-table joins, aggregations, and nested structures. While reinforcement learning (RL) has boosted LLM performance in this domain, current approaches suffer from two primary flaws:
- Lack of Stepwise Execution Awareness: Models typically generate a massive, complex SQL query in a single pass without interacting with the database. If a table join or filter condition is wrong early on, the error cascades, and the model only finds out after the final query fails.
- Sparse Outcome Rewards: Traditional RL relies on an "all-or-nothing" binary reward based on the final execution correctness. This makes credit assignment incredibly difficult; the model receives no granular feedback on which specific reasoning step caused the failure.
Methods
To solve these issues, the authors propose CoCTE (Chain of Common Table Expressions) and implement it via a three-stage framework called Reward-SQL.
- CoCTE Reasoning: Instead of generating a monolithic query, the model breaks the problem down into a sequence of short, modular, and executable subqueries using SQL
WITHclauses (CTEs). Each intermediate view is executed against the database, providing immediate feedback to ground the model's reasoning. - Model Initialization: The policy model (Qwen3-8B) undergoes Supervised Fine-Tuning (SFT) on a synthesized corpus of valid CoCTE trajectories generated by a teacher model (DeepSeek-V3).
- Process Reward Model (PRM) Design: The authors build a PRM that scores intermediate trajectories. It combines a Trajectory Score Model (trained using automated labels from Monte Carlo Tree Search) with an Inverse Entropy Weighting mechanism. The inverse entropy penalizes redundant or uninformative steps by measuring token-level uncertainty.
- Process-Supervised RL & Inference: The PRM is integrated into Grouped Reinforcement Policy Optimization (GRPO) alongside the final outcome reward, stabilizing training. During inference, the PRM guides Best-of-N sampling to select the highest-quality reasoning path.
Datasets
The framework was trained and evaluated using several prominent benchmarks:
- Standard Cross-Domain Evaluation: BIRD (industrial-scale, text/numerical attributes) and Spider (complex multi-table queries).
- Robustness OOD (Out-of-Distribution): Spider-DK, Spider-Syn, and Spider-Realistic to test robustness against linguistic variations and synonym substitutions.
- Cross-Domain OOD: ScienceBenchmark and EHRSQL (clinical databases) to evaluate performance on entirely unseen schemas and specialized terminology.
Key Insights and Ideas
- SQL as a Modular Build: Emulating how human database engineers write code—by building and verifying intermediate views progressively—drastically reduces structural errors.
- Entropy as a Quality Metric: The authors discovered that when a model generates redundant or useless steps, its token-level prediction uncertainty (entropy) spikes. Normalizing and inverting this entropy provides an elegant, automated way to reward efficient reasoning rather than just syntactically correct code.
- Dense Rewards Stabilize RL: Introducing step-level process rewards alongside final outcome rewards mitigates gradient variance, preventing the wild performance fluctuations common in late-stage RL training.
Key Results
- State-of-the-Art Performance: Reward-SQL (built on Qwen3-8B) achieved an execution accuracy of 70.3% on the BIRD development set using Best-of-32 sampling. This outperforms all comparable 7-8B open-source baselines and achieves competitive or superior results compared to massive closed-source models like GPT-4.
- Targeted Error Reduction: Compared to a standard GRPO baseline, Reward-SQL reduced table selection errors by 42.6%, column selection errors by 27.2%, and complex
GROUP BYerrors by a staggering 82.4%.
- Robustness: On robustness-level OOD tasks (like Spider-Syn), Reward-SQL achieved SOTA performance among 7-8B models, proving that execution-aware process training builds resilience against linguistic noise.
Limitations and Future Work
- Cross-Domain Schema Overfitting: When evaluated on entirely unseen domains with highly specialized terminology (like the clinical data in EHRSQL), performance dropped across all post-trained 7-8B models. The post-training process pushes the model to overfit to the training domain's schema style, highlighting a trade-off between specialization and general cross-domain transfer.
- Execution Latency: Generating and executing multiple intermediate CTEs introduces a minor runtime overhead (~9.5% slower than optimized, flattened expert queries). The authors note that future work will explore rule-based CTE transpilers to flatten queries for production deployment, as well as cost-aware reward modeling to optimize execution efficiency.
Summary updated