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

ReFoRCE: A Text-to-SQL Agent with Self-Refinement, Format Restriction, and Column Exploration

Minghang Deng, Ashwin Ramachandran, Canwen Xu, Lanxiang Hu, Zhewei Yao, Anupam Datta, Hao Zhang

TL;DR

Existing Text-to-SQL systems stumble when deployed on enterprise databases featuring thousands of columns, nested JSON fields, and vendor-specific SQL dialects. ReFoRCE is an agentic framework that solves this by coupling table schema compression, upfront output format enforcement, and proactive column exploration with an execution-driven self-refinement loop. Powered by OpenAI's o1-preview, ReFoRCE sets a new state of the art on the challenging Spider 2.0 benchmark, boosting execution accuracy to over 30–31%.

What Problem Does This Paper Address?

While standard Text-to-SQL models achieve over 90% accuracy on academic benchmarks like Spider 1.0, they degrade drastically in enterprise settings. Realistic enterprise databases feature:

  • Massive schemas spanning hundreds of tables and thousands of columns (often exceeding LLM context windows with DDLs over 50 MB).
  • Complex structures, including nested JSON columns and dialect-specific functions (e.g., Snowflake vs. BigQuery).
  • Ambiguous user questions requiring iterative discovery and data transformation.

On the real-world Spider 2.0 benchmark, existing prompting and agent frameworks (like Spider-Agent) plateaued around 20–23% execution accuracy. They frequently succumb to long-context attention loss, get trapped in endless loops fixing syntax errors, or hallucinate schemas.

Methods

ReFoRCE breaks Text-to-SQL generation into structured, controlled subtasks rather than relying on unstructured agent exploration:

[Compress Table DDLs] ➔ [Lock Expected Format] ➔ [Explore Columns via SQL] ➔ [Iterative Self-Refinement & CTEs] ➔ [Parallel Voting]
  1. Table Information Compression: Real databases frequently contain redundant partitioned tables (e.g., daily tables like GA_SESSIONS_YYYYMMDD). ReFoRCE uses pattern matching to retain a single representative DDL file while condensing the rest into table name lists, preventing prompt bloat.
  2. Expected Answer Format Restriction: In long-context regimes, LLMs often lose track of output requirements. Before querying, ReFoRCE generates a strict CSV-style template defining column names, data types, and row constraints (e.g., enforcing a single row for superlative queries).
  3. Iterative Column Exploration: Instead of guessing schemas or relying on unrepresentative static samples, the agent generates and executes targeted exploratory SQL queries (e.g., using SELECT DISTINCT, fuzzy matching %str%, or LATERAL FLATTEN for JSON). An internal error-recovery routine dynamically fixes syntax bugs across query batches.
  4. Self-Refinement & Consistency Checks: Generated queries execute against the live database. The agent refines queries using execution feedback, terminating only when:
  5. Self-consistency is reached (the same non-empty, valid answer table is obtained twice across iterations).
  6. Max iterations or consecutive empty results are hit (a conservative rule to avoid hallucinated false positives).
  7. Common Table Expression (CTE) Breakdown: When a query yields empty or failed results, the agent decomposes the query into modular CTE blocks, executing each intermediate CTE step-by-step to isolate where logic fails.
  8. Parallelized Voting: ReFoRCE launches multiple independent exploration/refinement runs in parallel (3 threads) and applies majority voting over the final execution outputs.

Datasets

The authors evaluate on the Spider 2.0 benchmark (547 realistic enterprise problems across 150+ databases, averaging 800 columns per database and ~150-token complex SQL queries):

  • Spider 2.0-Snow: Evaluates queries targeting the Snowflake SQL dialect exclusively.
  • Spider 2.0-Lite: Contains queries evaluated across three dialects: Snowflake, Google BigQuery, and SQLite.

Key Insights and Ideas

  • Format locking prevents "instruction drift": Long prompts cause LLMs to forget output formatting rules. Generating and grounding the expected table format before solving the task acts as an anchor during self-correction.
  • Active schema probing beats static sample rows: Static sample rows are often too long for nested columns or too narrow to show edge cases. Generating small, targeted exploratory queries directly reveals data distributions and dialects without overloading the context.
  • Strict consistency filters noise: Enterprise SQL queries often fail silently by returning empty rows. Treating empty results as failures and requiring the agent to independently reproduce identical tabular outputs twice eliminates lucky guesses and hallucinated queries.

Key Results

Evaluated on Execution Accuracy (EX) using o1-preview:

Method Backbone Model EX on Spider 2.0-Snow EX on Spider 2.0-Lite
ReFoRCE (Ours) o1-preview 31.26% 30.35%
Spider-Agent o1-preview 23.58% 23.03%
Spider-Agent GPT-4o 12.98% 13.16%
DAIL-SQL GPT-4o 2.20% 5.68%
CHESS GPT-4o 1.28% 3.84%
DIN-SQL GPT-4o 0.00% 1.46%

ReFoRCE outperforms the previous state-of-the-art framework (Spider-Agent) by roughly +7 to 8 percentage points using the exact same reasoning backbone (o1-preview). Standard GPT-4o prompting baselines fall completely flat (<6%), demonstrating the necessity of structured agentic workflows in enterprise settings.

Limitations and Future Work

  • Lossy Schema Compression: Merging tables by prefix/suffix heuristics can drop subtle column discrepancies present in schema variations.
  • Local Optima in Exploration: The initial column exploration relies on simple heuristics that can get trapped in sub-optimal search paths when column descriptions are ambiguous.
  • Pre-processing Focus: ReFoRCE primarily engineers the workflow and execution loop around the LLM rather than boosting the base model's mathematical and multi-step reasoning capabilities.
  • Future Directions: Incorporating search algorithms like Monte Carlo Tree Search (MCTS), Process Reward Models (PRMs), and reinforcement learning (e.g., DeepSeek-R1-style training) to tackle ambiguous column linking and complex analytics.

Summary updated

BibTeX
@inproceedings{deng2025reforce,
  author = {Minghang Deng and Ashwin Ramachandran and Canwen Xu and Lanxiang Hu and Zhewei Yao and Anupam Datta and Hao Zhang},
  title = {{ReFoRCE: A Text-to-SQL Agent with Self-Refinement, Format Restriction, and Column Exploration}},
  booktitle = {VerifAI @ ICLR},
  year = {2025},
  url = {https://openreview.net/forum?id=OuFIfDBwQd},
}
Figure