Table of Contents
Fetching ...

Text-to-SQL as Dual-State Reasoning: Integrating Adaptive Context and Progressive Generation

Zhifeng Hao, Qibin Song, Ruichu Cai, Boyan Xu

TL;DR

DSR-SQL introduces a dual-state reasoning framework for enterprise-level Text-to-SQL, modeling the task as an interaction between an adaptive context state and a progressive generation state. The context state compresses and aligns schema and knowledge through Refinement, Adaptive Selection, and Schema-aware Alignment, while the generation state evolves SQL via feedback-guided Extend, Revise, Explore, and Finalize steps. In zero-shot settings, it achieves strong results on Spider 2.0-Snow (35.28% EX) and BIRD (up to 68.32% EX), outperforming several baselines without post-training or in-context exemplars. The work demonstrates that coupling context refinement with feedback-driven generation yields robust, scalable Text-to-SQL for complex enterprise schemas, with open-source code to follow.

Abstract

Recent divide-and-conquer reasoning approaches, particularly those based on Chain-of-Thought (CoT), have substantially improved the Text-to-SQL capabilities of Large Language Models (LLMs). However, when applied to complex enterprise databases, such methods struggle to maintain coherent reasoning due to limited context capacity, unreliable schema linking, and weak grounding in database semantics. To overcome these issues, we introduce DSR-SQL, a \textbf{D}ual-\textbf{S}tate \textbf{R}easoning framework that models Text-to-SQL as an interaction between an adaptive context state and a progressive generation state. The first constructs a compact, semantically faithful environment by refining large schemas and selecting relevant structures, while the second formalizes SQL synthesis as feedback-guided state transitions, enabling the model to self-correct and align with user intent. Without any post-training or in-context examples, DSR-SQL achieves competitive performance, reaching 35.28\% execution accuracy on Spider 2.0-Snow and 68.32\% on BIRD development set. Our implementation will be open-sourced at: https://github.com/DMIRLAB-Group/DSR-SQL.

Text-to-SQL as Dual-State Reasoning: Integrating Adaptive Context and Progressive Generation

TL;DR

DSR-SQL introduces a dual-state reasoning framework for enterprise-level Text-to-SQL, modeling the task as an interaction between an adaptive context state and a progressive generation state. The context state compresses and aligns schema and knowledge through Refinement, Adaptive Selection, and Schema-aware Alignment, while the generation state evolves SQL via feedback-guided Extend, Revise, Explore, and Finalize steps. In zero-shot settings, it achieves strong results on Spider 2.0-Snow (35.28% EX) and BIRD (up to 68.32% EX), outperforming several baselines without post-training or in-context exemplars. The work demonstrates that coupling context refinement with feedback-driven generation yields robust, scalable Text-to-SQL for complex enterprise schemas, with open-source code to follow.

Abstract

Recent divide-and-conquer reasoning approaches, particularly those based on Chain-of-Thought (CoT), have substantially improved the Text-to-SQL capabilities of Large Language Models (LLMs). However, when applied to complex enterprise databases, such methods struggle to maintain coherent reasoning due to limited context capacity, unreliable schema linking, and weak grounding in database semantics. To overcome these issues, we introduce DSR-SQL, a \textbf{D}ual-\textbf{S}tate \textbf{R}easoning framework that models Text-to-SQL as an interaction between an adaptive context state and a progressive generation state. The first constructs a compact, semantically faithful environment by refining large schemas and selecting relevant structures, while the second formalizes SQL synthesis as feedback-guided state transitions, enabling the model to self-correct and align with user intent. Without any post-training or in-context examples, DSR-SQL achieves competitive performance, reaching 35.28\% execution accuracy on Spider 2.0-Snow and 68.32\% on BIRD development set. Our implementation will be open-sourced at: https://github.com/DMIRLAB-Group/DSR-SQL.

Paper Structure

This paper contains 51 sections, 11 figures, 7 tables, 2 algorithms.

Figures (11)

  • Figure 1: A motivating example illustrating the need for dual-state reasoning. Panel (a) shows an enterprise-level Text-to-SQL query containing domain-specific terminology from quantitative trading, such as feeling-lucky strategy, momentum strategy, and long-side trades. The database, however, stores these entities in entirely different formats. Panel (c) demonstrates the failure of static, CoT-based divide-and-conquer reasoning, which splits the problem linguistically but remains unaware of the true schema, resulting in execution failure. In contrast, panel (b) shows DSR-SQL, which leverages execution feedback to revise intermediate states, probe the database when mismatches occur, and ultimately reach an “aha moment” that correctly aligns user intent with database structure.
  • Figure 2: Overview of the DSR-SQL framework for enterprise-level Text-to-SQL. DSR-SQL consists of four components: Schema and Knowledge Refinement to handle large-scale inputs, Adaptive Schema Selection to identify relevant tables, Schema-aware Alignment to bridge linguistic and database semantics, and Generation-State Evolution guided by execution feedback to iteratively align user intent with query logic.
  • Figure 3: Schema token counts (M-Schema format) for selected databases in Spider 2.0-Snow. The comparison shows the original schema size (orange), the size after Schema and Knowledge Refinement (green), and the average per-query size after Adaptive Schema Selection (blue-and-white striped).
  • Figure 4: Accuracy comparison of the SQL Generation module by generation path type on the Spider 2.0-Snow and BIRD dev datasets, with divide-and-conquer making use of the Schema-aware Alignment module.
  • Figure 5: Example of Table description
  • ...and 6 more figures