Solid-SQL: Enhanced Schema-linking based In-context Learning for Robust Text-to-SQL

Geling Liu, Yunzhi Tan, Ruichao Zhong, Yuanzhen Xie, Lingchen Zhao, Qian Wang, Bo Hu, Zang Li

Abstract

Recently, large language models (LLMs) have significantly improved the performance of text-to-SQL systems. Nevertheless, many state-of-the-art (SOTA) approaches have overlooked the critical aspect of system robustness. Our experiments reveal that while LLM-driven methods excel on standard datasets, their accuracy is notably compromised when faced with adversarial perturbations. To address this challenge, we propose a robust text-to-SQL solution, called Solid-SQL, designed to integrate with various LLMs. We focus on the pre-processing stage, training a robust schema-linking model enhanced by LLM-based data augmentation. Additionally, we design a two-round, structural similarity-based example retrieval strategy for in-context learning. Our method achieves SOTA SQL execution accuracy levels of 82.1% and 58.9% on the general Spider and Bird benchmarks, respectively. Furthermore, experimental results show that Solid-SQL delivers an average improvement of 11.6% compared to baselines on the perturbed Spider-Syn, Spider-Realistic, and Dr. Spider benchmarks.

Introduction

While Large Language Models (LLMs) like GPT-4 have revolutionized the ability to turn natural language into SQL queries, they often lack robustness. In real-world scenarios, users rarely use exact database column names; they employ synonyms, omit details, or use complex sentence structures. Current state-of-the-art (SOTA) models frequently fail when faced with these "adversarial perturbations." For instance, if a user asks for "musicians" instead of "singers" (the actual table name), the system might break. Solid-SQL addresses this by focusing on the pre-processing stage—specifically schema selection and relevant example retrieval—as the key to building a resilient system.

Methodology

Solid-SQL introduces a robust three-stage pipeline: Pre-processing, Generation, and Post-processing. The core innovations include:

  1. Robust Schema Linking: A Llama3-8B model is fine-tuned to identify relevant tables and columns. To enhance robustness, the training data is augmented with thousands of LLM-generated variations using synonyms and structural changes.
  2. Two-Round Structural Retrieval: Instead of simple text similarity, Solid-SQL uses a two-step approach. In Round 1, it converts the question into a "skeleton" to find logically similar examples. In Round 2, it uses the structural "backbone" of the initial SQL output to refine the final query.
  3. Explicit Attention Mechanism: Rather than aggressive schema filtering, Solid-SQL retains the full schema but uses "focus on" instructions in the prompt to highlight likely candidates, allowing the LLM to recover if initial linking is slightly off.
The Solid-SQL architecture including schema linking training and the two-round generation pipeline.

Experimental Setup

The framework was evaluated on standard benchmarks like Spider and BIRD, as well as robustness-focused datasets: Spider-Syn (synonyms), Spider-Realistic (removed explicit names), and Dr. Spider (diagnostic perturbations).

Results and Discussion

Solid-SQL achieved state-of-the-art execution accuracy of 82.1% on Spider and 58.9% on BIRD. On perturbed benchmarks, it delivered an average improvement of 11.6% over baselines. The "skeleton" matching strategy proved significantly more resistant to noise than raw text similarity. By abstracting questions and SQL into skeletons, the system focuses on the logic of the query rather than specific words, which is much more resistant to noise.

Performance comparison of Solid-SQL against other methods across various LLMs and benchmarks.

Conclusion

The primary limitation of Solid-SQL is computational efficiency due to the two-round generation process, which increases latency and API costs. Future work will explore "early exit" conditions to skip the second round when confidence is high, optimizing the pipeline for lower latency without sacrificing robustness.

Summary updated

BibTeX
@inproceedings{liu2025solid,
  author = {Geling Liu and Yunzhi Tan and Ruichao Zhong and Yuanzhen Xie and Lingchen Zhao and Qian Wang and Bo Hu and Zang Li},
  title = {{Solid-SQL: Enhanced Schema-linking based In-context Learning for Robust Text-to-SQL}},
  booktitle = {International Conference on Computational Linguistics},
  year = {2025},
  url = {https://openreview.net/forum?id=BGJEFlL9QJ},
}
Figure