NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

ReEx-SQL: Reasoning with Execution-Aware Reinforcement Learning for Text-to-SQL

Yaxun Dai, Wenxuan Xie, Xialie Zhuang, Tianyu Yang, Ziyi Liu, Haiqin Yang, Yiying Yang, Yuhang Zhao, Pingfu Chao, Wenhao Jiang

TL;DR

ReEx-SQL transforms Text-to-SQL generation from a static "one-shot" guess into an interactive, execution-aware reasoning process. By allowing a 7B-scale LLM to execute intermediate queries and see real database feedback during its "thought" process, the framework achieves state-of-the-art accuracy while cutting inference time by over 50% through clever tree-structured decoding.

What Problem Does This Paper Address?

Translating natural language into SQL (Text-to-SQL) is notoriously difficult because it requires precise alignment between human intent, complex database schemas, and rigid SQL logic.

Current approaches typically fall into two camps:

  1. Standard Reasoning: The model "thinks" (Chain-of-Thought) and then spits out a query. If it hallucinates a column name or gets the join logic wrong, it has no way of knowing until the process is over.
  2. Post-hoc Correction: The model generates a query, tries to run it, sees an error, and then tries to fix it. This is often too late; a fundamental misunderstanding of the schema early in the process can lead to "fixing" a query that was doomed from the start.

The authors identify a "feedback gap": models lack the ability to interact with the environment (the database) while they are reasoning.

Methods

The authors introduce ReEx-SQL (Reasoning with Execution-Aware Reinforcement Learning), which features three main innovations:

  • Stepwise Execution Rollout: The model uses structured markup tags (<think>, <intermediate_sql>, <result>, and <final_sql>). During generation, the model can pause, write an "exploratory" SQL query, receive the actual execution results (or error logs) from the database, and then continue its reasoning based on that live data.
  • Execution-Aware RL (GRPO): To train this behavior, they use Grouped Reinforcement Policy Optimization (GRPO). They designed a composite reward function that doesn't just look at the final answer. It rewards the model for correct formatting, successful execution, matching schema entities, and—crucially—an exploration reward that encourages the model to interact meaningfully with the database rather than taking the shortest path.
  • Tree-Structured Decoding: Instead of generating multiple full queries from scratch (which is slow), ReEx-SQL uses a tree structure. Multiple reasoning paths can branch out from a single interaction step. This allows the model to explore different hypotheses efficiently, sharing the "root" reasoning and significantly reducing redundant computation.

Datasets

The framework was evaluated on the most rigorous Text-to-SQL benchmarks:

  • Spider: The standard cross-domain benchmark.
  • BIRD: A large-scale, "real-world" dataset with massive databases and complex queries.
  • Robustness Variants: The authors tested on Spider-Syn (using synonyms), Spider-Realistic (removing explicit column hints), and Spider-DK (requiring domain knowledge) to ensure the model wasn't just pattern-matching.

Key Insights and Ideas

  • Execution as a Compass, Not Just a Grade: The "aha moment" here is that execution feedback is more valuable during the search than at the end. If a model sees that an intermediate query returns "0 rows," it can immediately realize its WHERE clause is too restrictive and pivot.
  • The Efficiency of Branching: Most high-performing SQL models use "self-consistency" (generating 16+ queries and voting). By using a tree structure, ReEx-SQL gets the benefit of multiple candidates without the linear cost of generating 16 full sequences.
  • Small Models, Big Results: ReEx-SQL-7B (based on Qwen2.5-Coder) outperforms much larger proprietary models. This suggests that how a model reasons is often more important than the raw number of parameters it has.

Key Results

  • Accuracy: Achieved 88.8% on Spider and 64.9% on BIRD (at the 7B scale), outperforming standard reasoning baselines by ~2.7%.
  • Robustness: Set a new leading performance on Spider-Realistic (85.2%), proving the model can handle ambiguous human questions by "testing" its assumptions against the database.
  • Speed: The tree-structured decoding reduced inference time by 51.9% on the BIRD development set compared to traditional linear decoding.
  • Error Reduction: On the BIRD set, syntax errors dropped from 4.5% to 1.9%, as the model caught its own mistakes during the exploratory phase.

Limitations and Future Work

  • Database Dependency: ReEx-SQL requires active access to the database during the inference/decoding phase. In privacy-sensitive or offline environments, this could be a dealbreaker.
  • Future Directions: The authors suggest developing "lightweight execution simulators" or fallback mechanisms for when a live database isn't available. They also aim to explore even more advanced tree-search strategies to further expand the reasoning space.

Summary updated

BibTeX
@inproceedings{dai2026reex,
  author = {Yaxun Dai and Wenxuan Xie and Xialie Zhuang and Tianyu Yang and Ziyi Liu and Haiqin Yang and Yiying Yang and Yuhang Zhao and Pingfu Chao and Wenhao Jiang},
  title = {{ReEx-SQL: Reasoning with Execution-Aware Reinforcement Learning for Text-to-SQL}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  doi = {10.18653/v1/2026.acl-long.35},
}
Figure