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

Shreshth Rai, Rishii Kumar Singh, Aksh Aggarwal

Delhi Technological University

Published November 25, 2026 · on the feed November 26, 2026 · ▲ 4 · arXiv 2611.34363

LLM training & RLAgentsSafety, alignment & security Full code arXiv ↗Hugging Face ↗Weights ↗Dataset ↗

The 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

The Brief

1:58

A short podcast summary of the paper. Written and voiced by AI.

Transcript

Single-Database Rewards Are Hackable. Counterfactual Execution for Trustworthy Text-to-SQL RL. By Shreshth Rai and two others, from Delhi Technological University. Published on the twenty-fifth of November.

When reinforcement learning trains a text-to-SQL agent, the usual reward pays a query if its result matches the reference on one database. The claim here is that this reward can be hacked. A wrong query can match by luck, simply because the data lack the rows that would expose its bug. The authors study an alternative, a counterfactual-database reward. It also runs the final query on a few hidden, code-generated copies of the database. In its strict form it pays only if every result matches. In its mean form it pays by the share of results that match.

The audit uses one thousand three hundred and two synthetic questions. Under the strict form, the share of buggy queries paid in full falls from twenty-nine point five percent to sixteen point eight percent. The share of reward hacks paid falls from fifty-four point one percent to one point nine percent. Meanwhile it rejects none of the two thousand eight hundred and forty-seven correct queries. Copies produced by a family-blind generator do about as well.

Catching bad queries is one question. Whether training on the better reward produces a better model is another, and there the result is more limited. In a controlled GRPO comparison on a three point three five billion parameter model, with three seeds per arm, training on the mean form did not improve in-domain accuracy: the two arms landed at eight point four percent and eleven point seven percent. The reason given is that the two rewards disagreed on only five to seven percent of rollouts. On Spider, the mean form gained one point six points.

There is a further caution. One seed reverses both signs, which leads the authors to conclude that single-seed reward comparisons mislead.

Two separate claims sit side by side. As a judge of individual queries, the counterfactual reward is far harder to fool than a single database. As a training signal, it showed no in-domain gain, because it rarely disagreed with the reward it replaces, and a single seed would have been enough to suggest the opposite.

More with an account

Listen to every day’s papers

Daily playlists, deep dives, quests for the papers, and quizzes on their key terms.

Join free
KipQuest: the day’s AI research, as podcasts and quests. All papers Android app Privacy Contact Episodes are written and voiced by AI from each paper. Summaries can contain mistakes: the paper is the source.