arXiv:2610.12274cs.CLOct 2026

Manuscript Offprint

arXiv:2610.12274

HarnessSQL: Harness-Native Training for SQL Agents in Realistic Database Environments

Haolin Yang, Jipeng Zhang, Jian Xie, Shuaishuai Gong, Sirui Han, Yike Guo

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Text-to-SQL models are commonly trained to map questions directly to static queries, whereas real-world database agents operate through stateful, multi-turn interaction with live databases—inspecting schemas, executing probe queries, diagnosing errors, and revising hypotheses. This creates a critical train–deploy mismatch, as the execution harness that mediates this interaction is introduced only at inference time. To bridge this gap, we propose HARNESSSQL, a harness-native post-training framework that preserves the full interaction structure throughout both supervised fine-tuning and reinforcement learning. HARNESSSQL builds isolated, executable database environments paired with hidden execution oracles, rolls out teachers directly inside the target SQL harness, and retains only verified trajectories for full-sequence SFT, followed by execution-reward RL. Across Spider 2.0-SQLite, HARNESSSQL dramatically boosts the execution accuracy of compact models, raising Qwen3-8B from 15.5% to 45.2% and Qwen3-14B from 22.2% to 54.8%, while transferring effectively to out-of-distribution interactive benchmarks such as BIRD-Interact and LiveSQLBench. Our findings demonstrate that training database agents directly within their execution harness is essential for mastering complex, long-horizon database workflows. Code is released at https://github.com/YangHaolin0526/HarnessSQL

1 INTRODUCTION

Figure

Figure 1: From one-shot Text-to-SQL to harness-interactive database agents. A stable sandbox and structured SQL harness enable iterative exploration, execution feedback, revision, and submission.

Text-to-SQL has traditionally been formulated as a direct mapping from a natural-language question and database schema to an executable SQL query (Yu et al., 2018; Li et al., 2023). This abstraction

∗^{*}Equal contribution.

†^{\dagger}Corresponding authors.

has enabled substantial progress, but it increasingly diverges from how modern systems solve realistic database tasks. Benchmarks such as Spider2.0(Lei et al., 2025) place agents in large, unfamiliar database environments where the information required to solve a task cannot always be captured in a static prompt. An agent may need to inspect tables, examine schemas and values, execute intermediate queries, diagnose errors, and revise its solution over multiple turns. Recent systems have consequently begun to treat Text-to-SQL as an interactive problem, using tools and execution feedback to reason over databases rather than generating a query in a single pass (Deng et al., 2025; Li et al., 2026). This shift raises a corresponding question: how should such SQL agents be trained?

Figure 1 illustrates why interactive SQL agents require more than simply adding tools at inference time. Even for a seemingly simple request such as “How many unique customers purchased in 2023?”, the agent may not know in advance which tables, keys, or values are relevant(Pham et al., 2026). It may first inspect the schema, issue a plausible query, encounter an execution error such as referencing a nonexistent user_id column, and then use the returned database state to revise its hypothesis before submitting a correct query. This process exposes three coupled challenges. First, the environment must be executable and reproducible: the agent needs access to authentic schemas, values, query results, and runtime errors rather than a static textual approximation. Second, the harness itself shapes the policy: which inspection and execution tools are available, what observations are exposed, and how submission and termination are defined determine the sequence of decisions the model can make. Third, the supervision must capture the interaction process rather than only the terminal SQL: a correct final query does not teach the model when to inspect the schema, how to interpret an execution failure, or how to recover from an incorrect intermediate hypothesis(Guo et al., 2026). Recent interactive SQL benchmarks and harness studies increasingly expose these requirements at evaluation time(Xu et al., 2025; Yao et al., 2026a), yet most SQL post-training still focuses on static question–SQL supervision or terminal execution correctness. This creates a fundamental train–deploy mismatch: models are trained to produce answers, but deployed as policies that must explore, execute, revise, and terminate through a concrete database harness.

To resolve these challenges, we introduce HARNESSSQL, a harness-native post-training framework that aligns the supervision of database agents directly with their runtime execution interface. HARNESSSQL consists of three core components: 1. Executable SQL Environment Construction. We instantiate isolated database sandboxes that provide authentic schemas, query execution, runtime feedback, and hidden executable verification, enabling agent trajectories to be generated and evaluated against real database states. 2. SQL-Specific Harness Adaptation. Rather than directly adopting a generic agent harness, we adapt its interaction interface and execution protocol to the characteristics of SQL tasks. The resulting harness exposes task-relevant observations and actions while reducing unnecessary interaction complexity, making teacher rollouts more reliable and the resulting trajectories easier for compact models to learn from. 3. Harness-Native Post-Training. We collect oracle-verified full interaction trajectories directly inside the adapted harness and use them for supervised fine-tuning, followed by execution-reward reinforcement learning in the same environment. This two-stage training process teaches the model not only to produce correct SQL, but also to acquire the complete interaction policy for exploration, execution, recovery, and submission.

Empirical results demonstrate that harness-native training substantially elevates compact models. On Spider 2.0-SQLite, HARNESSSQL improves Qwen3-8B execution accuracy from 15.5% to 45.2% and Qwen3-14B from 22.2% to 54.8% after SFT and RL. Furthermore, the learned policies transfer effectively to out-of-distribution interactive environments, reaching 9.0%/11.3% on BIRD-Interact Mini and 24.8%/28.5% on LiveSQLBench Base-Lite for 8B/14B models. Controlled comparisons confirm that harness-native post-training significantly outperforms conventional non-harness fine-tuning, highlighting the importance of aligning training with the deployment interaction interface.

Our contributions are threefold: (1) Problem Formulation: We identify a train–deploy mismatch in database agents and formulate interactive Text-to-SQL as long-horizon policy learning grounded in an executable harness, highlighting the coupled roles of environment, interaction interface, and trajectory-level supervision. (2) HARNESSSQL Framework: We develop a harness-native pipeline spanning sandbox environment construction, dedicated SQL harness design, and end-to-end full-trajectory post-training via SFT and execution-reward RL. (3) State-of-the-Art Compact Agents: We show that HARNESSSQL substantially improves 8B/14B open-weight models on Spider 2.0 and transfers to out-of-distribution interactive benchmarks, demonstrating the effectiveness of training database agents natively within their deployment environment.