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

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

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

TL;DR

HarnessSQL is a new post-training framework that bridges the "train-deploy mismatch" for database agents by training them directly within the interactive execution environments they use at inference time. By combining full-trajectory supervised fine-tuning with execution-reward reinforcement learning, it enables compact 8B and 14B models to outperform much larger 32B models on complex, multi-turn Text-to-SQL benchmarks.

What Problem Does This Paper Address?

Traditional Text-to-SQL models are trained like translators: they take a natural language question and a static schema, then spit out a single SQL query. However, real-world database tasks are rarely "one-shot." In practice, a data engineer or analyst interacts with a live database—inspecting tables, running probe queries to understand values, diagnosing syntax errors, and iteratively refining their approach.

The authors identify a critical train-deploy mismatch. Most models are trained on static pairs of (Question, SQL), but at deployment, they are expected to act as agents within an execution harness. This harness introduces new observations (error messages, query results) and actions (tool calls) that the model never saw during training. As a result, even powerful models can become "brittle" when faced with the feedback loops of a real database environment.

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.

Methods

The core idea of HarnessSQL is "harness-native" training. Instead of training on static data, the authors train the model inside the loop. The framework consists of three main pillars:

  1. Executable SQL Sandboxes: The researchers built isolated, containerized database environments. These sandboxes provide authentic schema information and runtime feedback while protecting the underlying system.
  2. A Specialized SQL Harness: Rather than using a generic agent interface, they designed a minimal, four-tool contract:
  3. sql_list_tables: To discover what's available.
  4. sql_schema: To inspect specific table DDLs and sample values.
  5. sql_exec: To run trial queries and get feedback.
  6. sql_submit: To provide the final answer.
  7. Two-Stage Harness-Native Training:
  8. SFT (Interaction Cold Start): They used high-capacity "teacher" models to generate thousands of successful, multi-turn interaction trajectories within the harness. The student model is then trained on these full sequences.
  9. RL (Execution-Driven Optimization): After SFT, the model undergoes Reinforcement Learning (using the DAPO algorithm) where it receives rewards based on whether its final submitted query actually produces the correct result in the sandbox.
Figure 2: Overview of HARNESSSQL, our harness-native post-training framework for interactive SQL agents. (a) Databases and hidden execution oracles are encapsulated into isolated, containerized sandboxes, where a SQL-specific harness mediates agent–environment interaction through four actions: table discovery (sql list tables), schema inspection (sql schema), query execution (sql exec), and submission (sql submit). The harness exposes schemas, query results, and execution errors while enforcing interaction and execution constraints. Harness-native SFT provides an interaction cold start from verified multi-turn trajectories, after which harness-native RL further optimizes the policy through online sandbox interaction and execution-based rewards. (b) An example trajectory illustrates the resulting workflow: the agent discovers tables, inspects the schema, executes a query, observes an execution error, revises its solution, and submits the verified result.

Datasets

The authors synthesized a training corpus from 79 databases originating from Spider 2.0-Lite and Spider 2.0-DBT. For evaluation, they used:

  • Spider 2.0-SQLite: The primary in-domain benchmark featuring complex, real-world enterprise schemas.
  • BIRD-Interact Mini: An out-of-distribution (OOD) benchmark requiring dialogue with a user simulator.
  • LiveSQLBench Base-Lite SQLite: An OOD benchmark with continually updated real-world tasks to test generalization and robustness against data contamination.

Key Insights and Ideas

  • The Harness is Part of the Policy: Training a model on static data and then giving it tools at inference time actually hurts performance compared to native training. The model needs to learn the "language" of the harness—how to interpret its specific error messages and how to manage its own context over multiple turns.
  • Full Trajectories > Individual Turns: The authors found that training on the entire interaction history as a single sequence (Full-trajectory SFT) significantly outperforms breaking the interaction into isolated turn-level samples. This helps the agent learn long-horizon dependencies.
  • Context is King for Agents: Agentic workflows are context-heavy. Increasing the context window from 8K to 32K tokens led to massive performance gains, as it allowed the agent to "remember" previous execution failures and successful schema probes.
Figure 3: Effect of multi-turn trajectory organiza- tion for SFT.

Key Results

HarnessSQL achieved dramatic improvements in execution accuracy for compact, open-weight models:

  • Qwen3-8B: Jumped from 15.5% to 45.2% on Spider 2.0-SQLite.
  • Qwen3-14B: Jumped from 22.2% to 54.8%.
  • Beating the Giants: These 8B and 14B "harness-native" agents outperformed much larger 32B models (like Qwen2.5-Coder-32B and OmniSQL-32B) that were not trained with this interactive focus.
  • Generalization: The models showed strong transfer to OOD benchmarks, nearly tripling the performance of baselines on BIRD-Interact.
Table 1: Execution accuracy across in-domain (S2-SQLite) and out-of-distribution (BI-mini, LSB- SQLite) benchmarks (S2-SQLite: Spider 2.0-SQLite; BI-mini: BIRD-Interact Mini; LSB-SQLite: LiveSQLBench Base-Lite SQLite). Bold indicates the best, and underline indicates the second best.

Limitations and Future Work

  • Dialect Focus: The current study focuses primarily on SQLite. While SQLite is a standard for benchmarks, real-world enterprise environments use diverse dialects like PostgreSQL, Snowflake, and BigQuery, which have different syntax and metadata commands.
  • Model Scale: The authors noted that very small models still struggle with dialect-specific nuances and long-horizon reasoning.
  • Ongoing Work: The team is working on extending harness-native synthesis to more complex SQL dialects to close the performance gap across the broader database ecosystem.

Summary updated

BibTeX
@misc{yang2026harnesssql,
  author = {Haolin Yang and Jipeng Zhang and Jian Xie and Shuaishuai Gong and Sirui Han and Yike Guo},
  title = {{HarnessSQL: Harness-Native Training for SQL Agents in Realistic Database Environments}},
  year = {2026},
  eprint = {2610.12274},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2610.12274},
}
Figure