Manuscript Offprint

arXiv:2608.22772

SPOC-SQL: Stage-wise Preference Optimization for Controllable Text-to-SQL

Yingnan Chen, Chun Ding, Tianshi Xu, Xu Yang, Si Wu

Yingnan Chen†, Chun Ding†, Tianshi Xu, Xu Yang*, and Si Wu

South China University of Technology, Guangzhou, Guangdong 510006, P.R. China

chen.m0rem@gmail.com, csdingchun@mail.scut.edu.cn,

{xtshi,yxu8}@grgbanking.com, cswusi@scut.edu.cn

† Joint first authors. * Corresponding author.

Abstract. Text-to-SQL aims to translate natural language questions into executable SQL queries over relational databases, requiring multi-stage structured reasoning over database schemas and query constraints. However, existing methods treat this task as single-step generation, where models optimize entire SQL sequences without targeted feedback at key decision points and lack support for interacting with and controlling the intermediate generation process. To address this issue, we propose SPOC-SQL, which decomposes Text-to-SQL into four sequential subtasks following standard SQL execution logic and designs stage-specific optimization strategies for the model to learn key decisions. Specifically, we propose the implementation of fine-grained preference optimisation at key decision points across SQL stages, with the objective of enhancing structured decision-making during query construction. Furthermore, a structured decomposition strategy is designed, facilitating stage-wise intervention and correction through explicit intermediate representations. This results in more controllable and reliable SQL generation. Experiments demonstrate that incorporating stage-wise human knowledge consistently improves performance, validating the effectiveness of stage perception controllable generation.

Keywords: Text-to-SQL · Interactive Querying · Preference Learning

1 Introduction

Text-to-SQL (T2S) is the process of translating natural language questions into SQL queries that function on relational databases. T2S tasks frequently require handling multi-table joins, nested subqueries, and complex conditions [17], thereby forming a multi-step decision-making process similar to multi-turn QA scenarios [3]. Modeling this process accurately is challenging due to the complex relationships in the database schema and the semantic complexities involved.

Existing methods generate SQL sequences by jointly encoding questions and database schemas. Examples include RAT-SQL[15], which employs relation-aware attention, BRIDGE[11], which utilizes tagged sequence encoding, and RESDSQL[10], which applies decoupled schema linking. However, these methods typically treat the entire SQL sequence as the optimization objective and learn it holistically without stage-level modeling, due to the scarcity of high-quality multi-turn T2S data. Specifically, when the model assigns equal importance to both key interaction steps that drive task progress and irrelevant conversational

Y. Chen et al.

Figure

Fig. 1: The workflow of SPOC-SQL. (1) The task parsing function F\mathcal{F} decomposes single-turn queries into multi-turn sequences with stage-specific subrequirements. (2) LoRA fine-tuning combined with preference-based optimization to enhance decision capability through fine-grained policy optimization. (3) Evaluation of multi-turn QA capabilities. (4) At inference, F\mathcal{F} decomposes user requirements into sub-tasks for iterative confirmation, generating the final SQL.

content, the signals required for effective decision-making are diluted. This approach hinders the model's ability to master core decisions that advance the task and restricts its capacity to develop essential interaction strategies [2]. Furthermore, the absence of structured modeling impedes interpretability, making it harder to trace errors to specific reasoning stages. Limited interpretability also constrains user engagement with intermediate query components, resulting in a reliance on either complete acceptance of the generated SQL or only coarse-grained modifications.

To address this issue, we propose SPOC-SQL, which decomposes T2S into four sequential subtasks aligned with standard SQL execution logic and employs stage-wise optimization strategies to enable the model to learn key decisions. Specifically, SPOC-SQL decomposes T2S into structured subtasks corresponding to SQL execution stages, enabling progressive decision-making rather than single-step generation. Single-turn instances are decomposed into sequential substages to construct multi-turn QA samples. Based on this dataset, we propose Preference-based Multi-turn QA Decision Optimization (PMDO), which builds preference pairs at key decision points across subtasks. Preferred samples correspond to correct intermediate decisions derived from the gold SQL execution process, while non-preferred samples are automatically generated through prompt-guided controlled perturbations using the LLM [5]. Specifically, the model is prompted to intentionally modify critical intermediate reasoning elements, including selecting irrelevant columns, introducing incorrect filtering conditions [21], mismatching aggregation operations, and applying improper sorting constraints, while preserving the overall query context and linguistic plausibility. Additionally, PMDO integrates LoRA [8] with DPO [14], enabling efficient stage-level preference learning and improving decision discrimination. We further design a Requirement Decomposition and Interaction Module (RDIM), which decomposes queries into stage-specific subtasks. Intermediate results are exposed for verification or correction, and the final SQL is synthesized from validated outputs, thereby improving interpretability and controllability. The primary contributions of our work are summarized as follows:

  • Different from existing methods that approach Text-to-SQL as a single-step sequence generation task, we propose SPOC-SQL, a framework that models the task as a stage-wise structured decision process. Stage perception strategies are integrated into both training and inference, which facilitates unified fine-grained preference optimization and controllable generation.

  • To enhance decision accuracy on core subtasks, we design a stage-level preference optimization strategy, PMDO, which extends DPO supervision from the sequence level to key decision points across distinct SQL logical stages.

  • We propose RDIM to enable stage-wise verification and correction during inference, endowing the SQL generation process with explicit interpretability and user-driven intervention capabilities.

References (22)

  • GPT-4 Technical Report
  • Text-vision guided latent prediction for high-fidelity blind face restoration
  • IP-KGQA: Intent-aware prompt learning for knowledge graph question answering
  • Structure-grounded pretraining for Text-to-SQL
  • LLM-Inpainter: LLM-adapted feature prediction with fine-grained mask-aware reinforcement for high-fidelity face image inpainting
  • C3: Zero-shot Text-to-SQL with ChatGPT (opens arXiv in a new tab)
  • Text-to-SQL empowered by large language models: A benchmark evaluation
  • LoRA: Low-rank adaptation of large language models
  • MCS-SQL: Leveraging multiple prompts and multiple-choice selection for Text-to-SQL generation
  • RESDSQL: Decoupling schema linking and skeleton parsing for Text-to-SQL
  • Bridging textual and tabular data for cross-domain Text-to-SQL semantic parsing
  • DeepSeek-V3 Technical Report
  • DIN-SQL: Decomposed in-context learning of Text-to-SQL with self-correction
  • Direct preference optimization: Your language model is secretly a reward model
  • RAT-SQL: Relation-aware schema encoding and linking for Text-to-SQL parsers
  • MAC-SQL: A multi-agent collaborative framework for Text-to-SQL
  • Fine-grained conditional inpainting diffusion for component-aware face makeup rendering
  • Qwen3 Technical Report
  • Spider: A large-scale human-labeled dataset for complex and cross-domain semantic parsing and Text-to-SQL
  • ACT-SQL: In-context learning for Text-to-SQL with automatically generated chain-of-thought
  • Class-conditional image synthesis with intra-class relation preservation
  • Classbooth: Boost class semantics with bidirectional feature fusion in text-to-image diffusion models