Single-Database Rewards Are Hackable: Counterfactual Execution for Trustworthy Text-to-SQL RL
Abstract
A counterfactual-database reward for reinforcement learning text-to-SQL agents reduces full payment to buggy queries and reward hacks, though training with its mean form did not improve in-domain accuracy in a controlled GRPO comparison.
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
Community
RL rewards for text-to-SQL usually check a query's result on one database, so a wrong query can get full reward when the data happen to hide its bug. We also run the final query on a few hidden, code-generated copies of the database.
- Buggy queries paid in full: 29.5% -> 16.8%
- Reward hacks paid: 54.1% -> 1.9%
- Correct queries rejected: 0 of 2,847
- Found an exploitable SQL reward in AgentTune (WHERE 1 = 1 + always "yes"); patched upstream
Honest null: in a 3-seed GRPO comparison on Tiny Aya Global (3.35B), the stricter reward did not improve in-domain accuracy (8.4% vs 11.7%) but gained 1.6 points on Spider, and one seed flips both signs. Single-seed reward comparisons can mislead.
Try the reward on your own SQL in the demo Space. Adapters, data and code are linked above.
This is an automated message from the Librarian Bot. I found the following papers similar to this paper.
The following papers were recommended by the Semantic Scholar API
- Finding Side-Effect Loopholes in AppWorld and WorkArena Verifiers (2026)
- Know Your Context Bank: Repairing Inconsistency and Measuring Generalization in Context-Aware Text-to-SQL (2026)
- Which Loopholes Get Found? Predicting Reward Hacking of LLM Judges Before RL Training (2026)
- Does a Governed Confidence Score Know When a Text-to-SQL Answer Is Right? An Exploratory Study on BIRD and a Pre-registered Confirmation on Spider (2026)
- Honesty Is a Race: Predicting When Verifiable-Reward RL Teaches a Model to Bluff (2026)
- Who Verifies the Verifier? Co-Evolving Inspectable Graders with Self-Improving Agents (2026)
- Calibrated Decision Rewards: Training Language Models with a Judge That Knows How Sure It Is (2026)
Please give a thumbs up to this comment if you found it helpful!
If you want recommendations for any Paper on Hugging Face checkout this Space
You can directly ask Librarian Bot for paper recommendations by tagging it in a comment: @librarian-bot recommend
Get this paper in your agent:
hf papers read 2611.34363 Don't have the latest CLI?
curl -LsSf https://hf.co/cli/install.sh | bash