RSL-SQL: Robust Schema Linking in Text-to-SQL Generation

Zhenbiao Cao, Yuanlei Zheng, Zhihao Fan, Xiaojin Zhang, Wei Chen, Xiang BaiarXiv 2024

Abstract

Text-to-SQL generation aims to translate natural language questions into SQL statements. In Text-to-SQL based on large language models, schema linking is a widely adopted strategy to streamline the input for LLMs by selecting only relevant schema elements, therefore reducing noise and computational overhead. However, schema linking faces risks that require caution, including the potential omission of necessary elements and disruption of database structural integrity. To address these challenges, we propose a novel framework called RSL-SQL that combines bidirectional schema linking, contextual information augmentation, binary selection strategy, and multi-turn self-correction. We improve the recall of pattern linking using forward and backward pruning methods, achieving a strict recall of 94% while reducing the number of input columns by 83%. Furthermore, it hedges the risk by voting between a full mode and a simplified mode enhanced with contextual information. Experiments on the BIRD and Spider benchmarks demonstrate that our approach achieves SOTA execution accuracy among open-source solutions, with 67.2% on BIRD and 87.9% on Spider using GPT-4o. Furthermore, our approach outperforms a series of GPT-4 based Text-to-SQL systems when adopting DeepSeek (much cheaper) with same intact prompts. Extensive analysis and ablation studies confirm the effectiveness of each component in our framework.

Introduction

Large Language Models (LLMs) have significantly advanced Text-to-SQL systems, yet they often struggle with "schema noise" in large-scale industrial databases. Providing a full schema with hundreds of tables and thousands of columns is not only computationally expensive but also introduces confusion, leading to incorrect queries. Schema linking—the process of pruning the database description to only relevant components—is the standard solution.

However, schema linking is a double-edged sword. Aggressive pruning can lead to the omission of necessary columns (Risk 1), while a simplified schema might lack the structural context required for complex joins or resolving naming ambiguities (Risk 2). RSL-SQL addresses this trade-off by framing schema linking as a balance between positive gain (noise reduction) and negative impact (information loss).

Methodology

The RSL-SQL framework employs a four-stage modular pipeline to maximize schema linking benefits while mitigating associated risks.

1. Bidirectional Schema Linking (BSL)

To ensure high recall, RSL-SQL uses both forward and backward linking. Forward linking involves the LLM selecting columns directly. Backward linking generates a preliminary SQL query from the full schema and then parses it to identify the columns actually utilized. This combination achieves a 94% recall rate while reducing input columns by 83%.

2. Contextual Information Augmentation (CIA)

Beyond simple column names, the system generates "hints" using an LLM. These include likely SQL keywords (e.g., GROUP BY), filter conditions, and semantic column descriptions, helping the model understand the data's underlying meaning.

Preliminary SQL generation and Contextual Information Augmentation steps.

3. Binary Selection Strategy (BSS)

This "risk-hedging" core generates two candidate queries: one based on the full, noisy schema and another based on the pruned, simplified schema. An LLM judge evaluates the execution results of both to select the query that best aligns with the user's intent.

4. Multi-Turn Self-Correction (MTSC)

If the selected SQL fails to execute or returns an empty result, the system enters an iterative feedback loop. Error messages are fed back to the LLM to refine the query until a valid result is produced.

Binary Selection Strategy and Multi-Turn Self-Correction steps.

Experimental Evaluation

RSL-SQL was evaluated on two major benchmarks: BIRD, known for complex queries and "dirty" data, and Spider, the industry standard for multi-table tasks.

  • State-of-the-Art Performance: RSL-SQL achieved 67.21% execution accuracy on the BIRD development set using GPT-4o, a record for open-source solutions. On Spider, it reached 87.9% accuracy.
  • Cost-Efficiency: Remarkably, the framework allowed the DeepSeek model (215x cheaper than GPT-4) to achieve 63.56% accuracy on BIRD, outperforming several GPT-4-based systems. This highlights that robust workflow design can compensate for using less powerful models.

Key Insights

  • Backward Linking is Essential: Identifying columns used in a draft query catches essential elements that models might miss during explicit selection.
  • Framework over Model Power: The success with DeepSeek suggests that prompt engineering and structured workflows are as critical as the underlying LLM's raw power.

Limitations and Conclusion

RSL-SQL's reliance on execution feedback requires a live database environment, which may not be feasible in all production settings. Additionally, semantic ambiguities in simplified schemas remain a challenge. Future work will focus on optimizing token consumption during self-correction and exploring more sophisticated voting mechanisms between candidate queries.

Overall, RSL-SQL provides a robust, cost-effective framework for high-accuracy Text-to-SQL generation by intelligently managing the risks of schema linking.

Summary updated

BibTeX
@misc{cao2024rsl,
  author = {Zhenbiao Cao and Yuanlei Zheng and Zhihao Fan and Xiaojin Zhang and Wei Chen and Xiang Bai},
  title = {{RSL-SQL: Robust Schema Linking in Text-to-SQL Generation}},
  year = {2024},
  eprint = {2411.00073},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.00073},
}
Figure