PARSQL: Enhancing Text-to-SQL through SQL Parsing and Reasoning

Yaxun Dai, Haiqin Yang, Hao Mou, Pingfu ChaoACL 2025

Introduction

Translating natural language (NL) questions into structured SQL queries is a cornerstone of modern data interaction. While Large Language Models (LLMs) like GPT-4 demonstrate high proficiency in these tasks, their deployment is often hindered by high latency and operational costs. Small Language Models (SLMs) offer a more efficient alternative but frequently struggle with the "semantic gap"—the disconnect between flexible human language and the rigid logic of SQL.

Specifically, SLMs often fail to capture "implicit constraints." For instance, a user asking for the "largest land area" implies both a descending sort (ORDER BY area DESC) and a single result limit (LIMIT 1). Standard fine-tuning often results in models that produce syntactically valid SQL but omit these critical logical nuances. PARSQL is a novel framework designed to bridge this gap by decomposing complex queries and training models on an auxiliary reasoning task.

PARSQL correctly identifies implicit constraints (like ordering and limits) that other models neglect, providing a step-by-step reason for its logic.

The PARSQL Framework

PARSQL introduces a multi-stage approach to Text-to-SQL that emphasizes structural understanding over simple pattern matching. The framework consists of three primary pillars: the PARSer, data augmentation through multi-task learning, and reasoning-based SQL selection.

1. PARSer (SQL Parser)

At the heart of the system is PARSer, a custom tool that decomposes complex SQL queries into Abstract Syntax Trees (ASTs). By identifying individual constraints (e.g., specific WHERE clauses or aggregation functions), PARSer can generate "sub-SQLs." These are simplified versions of the target query that allow the model to learn the fundamental building blocks of SQL logic in isolation.

2. Data Augmentation & Multi-task Learning

To strengthen the model's reasoning capabilities, the authors employ two training strategies:

  • Augmented New Pairs: Using the sub-SQLs generated by PARSer, the framework creates a library of simpler question-SQL pairs. This ensures the model is exposed to a wide variety of logical structures during training.
  • NL2Reason Task: Instead of training the model solely to output SQL, PARSQL introduces an auxiliary task where the model must generate a step-by-step "reason" for its query (e.g., "First, filter the table by year, then calculate the average horsepower"). This acts as a form of internal Chain-of-Thought, forcing the model to map NL nuances to specific SQL operations.
The PARSQL pipeline: Training data is processed by PARSer to create sub-SQLs and reasoning paths, which are then used for data augmentation and multi-task learning.

3. Reasoning-based SQL Selection

During inference, the model generates multiple candidate SQL queries along with their corresponding reasons. To ensure the most logical query is chosen, PARSQL uses a rule-based engine to translate the candidate SQL back into a natural language explanation. It then calculates the N-gram similarity between this rule-based explanation and the model's generated reason. The candidate with the highest similarity score is selected, providing a robust self-correction mechanism.

Experimental Results

The researchers evaluated PARSQL on the BIRD and Spider benchmarks, which are the industry standards for cross-domain Text-to-SQL tasks.

  • State-of-the-Art Performance: PARSQL-3B achieved an Execution Accuracy (EX) of 56.98% on the BIRD development set. This performance not only sets a new record for 3B-parameter models but also rivals the accuracy of much larger 7B-parameter models.
  • Constraint Sensitivity: In specialized evaluations, PARSQL showed a 5.83% improvement in correctly identifying and implementing specific query constraints compared to standard fine-tuned models. This confirms that the reasoning task successfully helps the model capture implicit logic.
  • Robustness: The framework demonstrated superior performance on robustness variants like Spider-DK and Spider-Realistic, proving that it relies on logical understanding rather than memorizing dataset-specific patterns.

Conclusion and Future Work

PARSQL demonstrates that by incorporating structural parsing and auxiliary reasoning tasks, Small Language Models can achieve performance levels previously reserved for much larger architectures. This makes high-quality Text-to-SQL more accessible and efficient for real-world applications.

While the current implementation is optimized for SQLite, future work aims to expand the rule-based reasoning templates to support a broader range of SQL dialects like PostgreSQL and BigQuery. Additionally, the authors suggest that the AST-based reasoning approach could be extended to other code generation tasks beyond SQL.

Summary updated

BibTeX
@inproceedings{dai2025parsql,
  author = {Yaxun Dai and Haiqin Yang and Hao Mou and Pingfu Chao},
  title = {{PARSQL: Enhancing Text-to-SQL through SQL Parsing and Reasoning}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure