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

Dialect-SQL: An Adaptive Framework for Bridging the Dialect Gap in Text-to-SQL

Jie Shi, Xuetao Cao, Bo Xu, Jiaqing Liang, Yanghua Xiao, Jia Chen, Yanchun Wang, Wei Wang2025

Introduction

While Text-to-SQL research has advanced significantly, current benchmarks and models suffer from a pervasive "SQLite bias." Popular datasets like Spider and BIRD primarily utilize SQLite, leading researchers to optimize models for its specific syntax. However, real-world applications demand compatibility with a diverse array of database systems, including PostgreSQL, SQL Server, Oracle, and MySQL.

Each of these systems employs a unique "dialect" with subtle but critical differences in identifiers and functions. For instance, while SQLite uses no quotes for identifiers, PostgreSQL requires double quotes, and SQL Server uses square brackets. These discrepancies create a "dialect gap" where models trained on one system fail to generalize to others. Dialect-SQL is introduced as a framework to bridge this gap by using Object-Relational Mapping (ORM) code as a universal intermediate language.

High-level comparison between traditional dialect-specific approaches and the proposed dialect-adaptive Dialect-SQL framework.

Methodology: ORM as an Interlingua

The core innovation of Dialect-SQL is the decoupling of query logic from database-specific syntax. Instead of generating raw SQL directly, the framework teaches Large Language Models (LLMs) to write Python-based SQLAlchemy code. Python is a high-resource language that LLMs already understand deeply, and SQLAlchemy is a mature tool designed specifically for cross-database compatibility.

The framework operates in two distinct stages:

1. Offline Stage: Bootstrapping ORM Code Synthesis

To overcome the lack of massive Text-to-ORM datasets, the authors employed a bootstrapping approach. Starting with only five manually written examples, an LLM was used to iteratively generate ORM code for existing Text-to-SQL datasets. This code was verified by executing it and comparing the results against "gold" SQL outputs. Successfully validated pairs were then added to a "demonstration pool."

2. Online Stage: Dialect-Adaptive Generation

When processing a user query, the system retrieves relevant examples from the demonstration pool. The LLM generates ORM code (SQLAlchemy), which is then converted into the target database's specific dialect using a code interpreter or transpiler. This offloads the burden of syntax translation from the LLM to a specialized engine.

The two-stage workflow of Dialect-SQL, illustrating the offline bootstrapping of the demonstration pool and the online generation process.

Experimental Setup and Results

The framework was evaluated on the Spider and BIRD benchmarks. To test dialect adaptability, the authors adapted the BIRD dataset to run across five different database engines: SQLite, PostgreSQL, SQL Server, Oracle, and MySQL.

Key Findings

  • Superior Adaptability: Dialect-SQL demonstrated remarkable stability across different systems. While direct SQL generation using Llama-3.1-70B saw an accuracy drop of nearly 38% when switching from SQLite to PostgreSQL, Dialect-SQL maintained a near-flat performance curve with only a 1.53% drop.
  • Logic over Syntax: By targeting a single ORM representation, the LLM only needs to master one logical expression (e.g., func.max()). This proves more effective than using SQL-to-SQL transpilers, which require a perfect source query to function correctly.
  • Execution Efficiency: Although ORM code is more verbose than SQL, Dialect-SQL often exhibits lower latency because it is more likely to produce executable code on the first attempt, significantly reducing the need for iterative self-correction loops.

Conclusion

Dialect-SQL suggests that the most effective way to interact with diverse database environments is not to train models on every possible dialect, but to utilize a well-understood "interlingua." By leveraging the pre-existing programming strengths of LLMs through ORM code, the framework successfully bridges the dialect gap, offering a robust and scalable solution for real-world Text-to-SQL applications.

Summary updated

BibTeX
@misc{shi2025dialect,
  author = {Jie Shi and Xuetao Cao and Bo Xu and Jiaqing Liang and Yanghua Xiao and Jia Chen and Yanchun Wang and Wei Wang},
  title = {{Dialect-SQL: An Adaptive Framework for Bridging the Dialect Gap in Text-to-SQL}},
  year = {2025},
  doi = {10.18653/v1/2025.emnlp-main.178},
}
Figure