Pi-SQL: Enhancing Text-to-SQL with Fine-Grained Guidance from Pivot Programming Languages

Published in Findings of EMNLP 2025, 2025

TL;DR

Uses Python as a pivot intermediate representation to give Text-to-SQL fine-grained structural guidance — first generating Python programs that supply step-by-step guidelines, then producing SQL programs that follow each Python program’s guidance. Improves the best baseline by up to +3.20 execution accuracy and +4.55 reward-based valid efficiency.

Abstract

Text-to-SQL transforms the user queries from natural language to executable SQL programs, enabling non-experts to interact with complex databases. Existing prompt-based methods craft meticulous text guidelines and examples to facilitate SQL generation, but their accuracy is hindered by the large semantic gap between the texts and the low-resource SQL programs. In this work, we propose Pi-SQL, which incorporates the high-resource Python program as a pivot to bridge between the natural language query and SQL program. In particular, Pi-SQL first generates Python programs that provide fine-grained step-by-step guidelines in their code blocks or comments, and then produces an SQL program following the guidance of each Python program. The final SQL program matches the reference Python program’s query results and, through selection from candidates generated by different strategies, achieves superior execution speed, with a reward-based valid efficiency score up to 4.55 higher than the best-performing baseline. Extensive experiments demonstrate the effectiveness of Pi-SQL, which improves the execution accuracy of the best-performing baseline by up to 3.20.

BibTeX

Click to expand
@inproceedings{chi-etal-2025-pi,
    title = "Pi-{SQL}: Enhancing Text-to-{SQL} with Fine-Grained Guidance from Pivot Programming Languages",
    author = "Chi, Yongdong  and
      Wang, Hanqing  and
      Chen, Yun  and
      Yang, Yan  and
      Yang, Jian  and
      Yang, Zonghan  and
      Yan, Xiao  and
      Chen, Guanhua",
    editor = "Christodoulopoulos, Christos  and
      Chakraborty, Tanmoy  and
      Rose, Carolyn  and
      Peng, Violet",
    booktitle = "Findings of the Association for Computational Linguistics: EMNLP 2025",
    month = nov,
    year = "2025",
    address = "Suzhou, China",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2025.findings-emnlp.1369/",
    doi = "10.18653/v1/2025.findings-emnlp.1369",
    pages = "25120--25144"
}