TL;DR
While large language models (LLMs) are increasingly adept at translating natural language into SQL, verifying the correctness of their outputs at test-time remains a major bottleneck. This paper introduces GradeSQL, a framework that automates the creation of task-specific Outcome Reward Models (ORMs) to act as learned semantic verifiers. By replacing standard heuristic selection methods like Majority Voting with probabilistic scoring, GradeSQL consistently boosts execution accuracy, especially on highly complex queries.
What Problem Does This Paper Address?
Translating natural language questions into executable SQL queries (Text-to-SQL) is notoriously brittle. A single misplaced join or incorrect clause can lead to empty results or, worse, subtly incorrect data retrieval.
To mitigate this, practitioners often use test-time inference (TTI) strategies: they prompt an LLM to generate multiple candidate queries and then use a heuristic to pick the best one. Common heuristics include Execution-based Best-of-N (picking a query that executes without throwing an error) and Majority Voting (picking the most frequently generated query structure).
However, these heuristics are coarse proxies for actual semantic correctness. As you increase the number of generated candidates, these heuristic methods quickly saturate—they cannot distinguish between multiple queries that all execute successfully but compute entirely different things. This paper addresses the need for a learned, scalable verifier that understands the meaning behind the code.
Methods
The authors propose GradeSQL, a scalable framework designed to train an Outcome Reward Model (ORM) without requiring manual annotation. The framework operates in three distinct stages:
- Candidate Generation: Given a question and a database schema, a generator LLM uses stochastic decoding to produce a diverse pool of $N$ candidate SQL queries via Chain-of-Thought (CoT) prompting.
- Data Labeling: Each candidate query is executed on the target database. If its result set matches the ground-truth ("gold") query's result set, it is labeled
Correct. If it executes but yields different data, it is labeledIncorrect. Queries that throw execution errors are discarded. - Supervised Fine-Tuning (SFT): A base LLM is fine-tuned via LoRA as a binary autoregressive classifier. It learns to take the schema, question, and candidate query as input and predict the next token:
Yes(correct) orNo(incorrect).
At inference time, instead of making a hard binary choice, the ORM evaluates all new candidates and ranks them based on the soft probability of generating the Yes token. The highest-scoring query is selected as the final output.
Datasets
The approach was evaluated using two prominent cross-domain Text-to-SQL benchmarks:
- Spider: A widely used dataset for complex and cross-domain semantic parsing.
- BIRD: A newer, larger dataset featuring massive databases and highly challenging, real-world optimization and reasoning tasks.
Both datasets utilize disjoint databases across their training and evaluation splits to ensure the models genuinely generalize to unseen database structures.
Key Insights and Ideas
- Heuristics Saturate, ORMs Scale: Traditional methods like Majority Voting stop improving once the candidate pool size ($N$) grows large. In contrast, the ORM's performance continuously scales upward alongside $N$, tracking closer to the theoretical maximum performance ("Pass@N").
- Autoregressive Modeling Beats Direct Classification: Training the verifier to predict the next token (
Yes/No) using standard causal language modeling objectives yields significantly better verification performance than training it with a standard binary cross-entropy (BCE) classification head. - Dataset Balancing Saves Compute: Downsampling the training data to a strict 50/50 split of correct/incorrect queries drastically reduces the training set size (e.g., from 80k to 30k samples for BIRD) without degrading verification accuracy. In fact, it occasionally improves it.
- Cross-Family Robustness: ORMs train reliably across heterogeneous architectures. An ORM trained on a smaller model backbone (like Qwen2.5-7B or Llama-3-8B) generalizes effectively to verify outputs from entirely different or larger generator models.
Key Results
The authors evaluated GradeSQL across seven open-source LLM families, using OmniSQL-7B as the primary candidate generator.
- Accuracy Boosts: ORM-based selection consistently outperformed all baseline methods. It achieved absolute execution accuracy gains of up to +4.33% on BIRD and +2.10% on Spider compared to Majority Voting.
- Impact on Complexity: The benefits of the ORM are most pronounced on "Moderate" and "Challenging" queries, where semantic discrimination is toughest and where simple execution heuristics fail completely.
Limitations and Future Work
Despite its success, the authors note several limitations:
- Execution Equivalence Pitfalls: Relying on database execution results as a ground-truth label can occasionally reward "spurious matches"—queries that are logically incorrect but happen to return the same data subset given the current state of the database.
- Clean Benchmarks Only: The framework was validated on clean, well-structured academic benchmarks. Its robustness against real-world, noisy database schemas or ambiguous user questions remains unproven.
- Coarse-Grained Feedback: The current model uses a binary outcome reward. The authors point toward Process Reward Models (PRMs)—which evaluate intermediate reasoning steps or individual clauses within the SQL generation process—as a promising direction for richer verification signals.
Summary updated