cs.LGNov 25, 2026

Single-Database Rewards Are Hackable: Counterfactual Execution for Trustworthy Text-to-SQL RL

Authors: Shreshth Rai, Rishii Kumar Singh, Aksh Aggarwal

Organizations: Artificial Intelligence and Machine Learning Society (AIMS-DTU) Delhi Technological University, New Delhi, India

Abstract

Reinforcement learning (RL) for text-to-SQL agents pays a query when its result matches the reference on one database. However, a wrong query can match by luck when the data lack the rows that expose its bug. We study a counterfactual-database (CF) reward that also runs the final query on a few hidden, code-generated copies of the database and pays only if all results match (strict form) or by the share matched (mean form). On 1,302 synthetic audit questions, the strict form lowers the share of buggy queries paid in full from 29.5% to 16.8% and of reward hacks from 54.1% to 1.9%, rejecting 0 of 2,847 correct queries; copies from a family-blind generator do about as well. In a controlled GRPO comparison on a 3.35B model with three seeds per arm, training on the mean form did not improve in-domain accuracy (8.4% vs 11.7%), because the two rewards disagreed on only 5-7% of rollouts; on Spider it gained 1.6 points. One seed reverses both signs, so single-seed reward comparisons mislead. Code: https://github.com/RishiiGamer2201/counterfactual-sql-rewards ; data, models, demo: https://huggingface.co/counterfactual-sql

Figures & tables

Appendix figures & tables7 assets

Supplementary material from the paper’s appendix.

Appendix

Explore similar work

CardsList
  1. ReToolSQL: Agentic Reinforcement Learning for Robust Text-to-SQL

    Aug 28, 2026Pratik Kakkar, Chandra Dhir, Ravi Shankar +2Text-to-SQLExecution-Guided Text-to-SQL

  2. Reward Blindness: A Theoretical Framework for Diagnosing Reinforcement Learning Reward Limitations in Text-to-SQL

    Nov 23, 2026Lakshmi Muraleedharan Nair, Shiqi Huang, Fangyu Lo +2Reward Design for RLReinforcement Learning

  3. SERL-SQL: Selective Hindsight Distillation for Text-to-SQL Reinforcement Agentic Learning

    Aug 1, 2026Tao Liu, Tao Feng, Xiangheng Li +9Reinforcement LearningText-to-SQL