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

Shreshth Rai, Rishii Kumar Singh, Aksh Aggarwal

arXiv:2611.34363 · 2026-11-29 공개 · arXiv · PDF

reinforcement-learning model-training reward-hacking text-to-sql counterfactual-database synthetic-audit grpo-comparison spider-benchmark

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

한국어 요약

한 줄 요약

CF 보상은 단일 데이터베이스 기반 RL에서의 보상 해킹을 감소시키며, 신뢰성 있는 Text-to-SQL 에이전트 학습에 기여한다.

핵심 기여도

핵심 아이디어

기존 Text-to-SQL RL은 단일 데이터베이스에서 쿼리 결과가 참조 결과와 일치하면 보상을 지급하지만, 이는 데이터가 오류를 드러내는 행을 포함하지 않을 때 잘못된 쿼리가 우연히 통과될 수 있다. 이를 해결하기 위해, **CF 보상**은 생성된 몇 개의 **counterfactual 데이터베이스**에서 최종 쿼리를 실행하고, 모든 결과가 일치해야 보상을 지급한다(엄격형) 또는 일치 비율에 따라 지급(평균형)한다. 이는 쿼리가 데이터의 작은 부분만 참조하는 경우에도 오류를 감지할 수 있도록 한다.

CF 보상은 **가상의 복제 데이터베이스**를 사용하여 학습 중에도 에이전트가 보지 못한 데이터에서의 성능을 평가함으로써, 보상 해킹을 줄이고 신뢰성을 높인다. 특히, **가족-맹 생성기**(family-blind generator)로 생성된 복제본도 유사한 성능을 보임.

기술적 접근법

주요 결과

의의 및 한계

CF 보상은 기존 보상 방식의 구멍을 줄이고, 학습 중에도 신뢰성을 유지하는 새로운 평가 기준을 제시한다. 특히, 합성 데이터베이스를 사용하여 보상 해킹을 감지하는 방식은 기존 시스템(예: AgentTune, SkyRL-SQL)의 보상 구멍을 드러내는 데 기여한다.

그러나, CF 보상은 학습 과정에서 도메인 내 정확도를 크게 개선하지 못했으며, 일부 시드에서는 오히려 성능이 저하되는 경우도 발생했다. 이는 보상 변경이 학습에 미치는 영향이 제한적일 수 있음을 시사한다. 또한, **복제 데이터베이스 생성**이 추가적인 컴퓨팅 비용을 유발할 수 있다.

실용적 활용

CF 보상은 금융, 의료, 비즈니스 분석 등에서 SQL 쿼리의 신뢰성을 요구하는 상황에 적용 가능하다. 특히, 학습 중에도 보상 해킹을 방지하면서 정확한 쿼리를 유도할 수 있어, **LLM 기반 자동 보고 시스템**이나 **데이터 기반 의사결정 지원 시스템**에 유용하다.