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.
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:
- Executable SQL Sandboxes: The researchers built isolated, containerized database environments. These sandboxes provide authentic schema information and runtime feedback while protecting the underlying system.
- A Specialized SQL Harness: Rather than using a generic agent interface, they designed a minimal, four-tool contract:
sql_list_tables: To discover what's available.sql_schema: To inspect specific table DDLs and sample values.sql_exec: To run trial queries and get feedback.sql_submit: To provide the final answer.- Two-Stage Harness-Native Training:
- 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.
- 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.
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.
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.
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