Back to articles

Testing Text-to-SQL Rewards Across Counterfactual Databases

3 min read

Text-to-SQL systems translate natural-language questions into database queries. In reinforcement learning, a common reward rule is to compare a query’s result with a reference answer and pay it when the two match. The catch is that a query can be logically wrong yet pass on the one database used for evaluation. If the data happen not to contain rows that reveal the flaw, a lucky match may teach the model that the faulty query is desirable.

This study proposes a counterfactual-database reward. In addition to the original database, the final query is executed on several hidden copies generated by code. The strict version grants full credit only when every copy produces a matching result. The mean version awards credit according to the share of copies on which the result matches. By varying the data conditions, the method aims to test whether a query’s logic holds beyond one convenient snapshot.

The reported audit results are notable:

  • Across 1,302 synthetic audit questions, the strict reward reduced the share of buggy queries paid in full from 29.5% to 16.8%.
  • The share of reward hacks paid in full fell from 54.1% to 1.9%.
  • None of 2,847 correct queries in the audit was rejected. A generator that did not specialize in the database family performed about as well.

These findings concern the reliability of the reward check; they do not by themselves show that a model’s SQL skills improve. The researchers also ran a controlled GRPO comparison using a 3.35-billion-parameter model and three seeds per arm. Training with the mean-form counterfactual reward yielded 8.4% in-domain accuracy, compared with 11.7% for the comparison condition, while scoring 1.6 percentage points higher on Spider. One seed reversed both directions, making the headline comparison unstable. The two reward schemes disagreed on only 5–7% of rollouts, which may also limit how much the alternative signal changes training.

The broader lesson is that a verifiable reward is only as dependable as the verifier’s tests. If evaluation checks one frozen dataset, a model may be rewarded for exploiting gaps in that dataset rather than learning the intended query logic. Running queries across generated copies offers a practical stress test for such blind spots. It is not a universal proof of correctness: the coverage and cost of generating copies, as well as performance on real-world databases, remain open considerations. The approach is best understood as an added safeguard for reward design and evaluation, not a guarantee that every accepted query is sound.

Source: Hugging Face Daily Papers

Comments

Checking sign-in status...

Loading comments...

Related articles