Enhancing text-to-SQL capabilities of small language models via schema context enrichment and self-correction
Translating natural language into SQL is essential for intuitive database access, yet open-source small language models (SLMs) still lag behind larger systems when faced with complex schemas and tight context windows. This paper introduces a two-phase workflow designed to enhance the Text-to-SQL capabilities of SLMs. Phase 1 (offline) transforms the database schema into a graph, partitions it with Louvain community detection, and enriches each component in a cluster with metadata, relationships, and sample rows. Phase 2 (at runtime) selects the relevant tables, generates SQL queries, and iteratively refines the SQL through an execution-driven feedback loop until the query executes successfully. Evaluated on the Spider test set, our pipeline raises Qwen-2.5-Coder-14B to 86.2% Execution Accuracy (EX), surpassing its zero-shot baseline and outperforming all contemporary SLM + ICL approaches and narrowing the gap to GPT-4-based systems all while running on consumer-grade hardware. Ablation studies confirm that both schema enrichment and self-correction contribute significantly to the improvement. The study concludes that this workflow provides a practical methodology for deploying resource-efficient open-source SLMs in Text-to-SQL applications, effectively mitigating common challenges. An open-source implementation is released to support further research.
Authors
- Nguyễn Đình Thuân (ORCID: https://orcid.org/0000-0002-7762-1505)
- Nguyen Minh Nhut
- Le Gia Kiet
- Le Quoc Khanh
Institutions
- University Of Information Technology (MM)
- Hermes Microvision (United States) (US)
Publication Details
- Journal
- CTU Journal of Innovation and Sustainable Development
- Published
- 2025-10-16
- DOI
- https://doi.org/10.22144/ctujoisd.2025.058
- Primary Topic
- Semantic Web and Ontologies
- Type
- article
- Field-Weighted Citation Impact
- 0.00