Reliable Text-to-SQL in Resource-Constrained Settings with Small LLMs via Iterative Retry Workflows
Organizations: Data Lab, Generix Group, Paris, France
Abstract
Large Language Models (LLMs) have recently improved Text-to-SQL generation, but their computational cost can hinder deployment in resource-constrained settings. This paper evaluates the Text-to-SQL capabilities of small and medium open-source LLMs (1B-8B parameters) under a controlled inference budget, focusing on how model specialization and prompt formulation affect performance. Using the Spider benchmark, we compare multiple prompt representations and assess the accuracy of generated queries. Our results show that SQL-specialized models are consistently more reliable than general-purpose and chat-oriented models at small scales, and that performance can vary substantially depending on the prompt used. To reduce this variability without resorting to larger models, we introduce three lightweight inference workflows that automatically retry with alternative prompts and/or models when failures occur, including an optional syntax-correction step. These workflows significantly improve end-to-end success rates, with a trade-off in additional inference calls. These results demonstrate a practical path to stronger Text-to-SQL performance with small LLMs, by trading modest additional inference cost for higher reliability.
Figures & tables
| Type | Model ID | Alpaca Sft | Basic Prompt | Code Repr. | OpenAI Demo | Struct. Prompt | Text Repr. | Avg | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| EM | EX | EM | EX | EM | EX | EM | EX | EM | EX | EM | EX | EM | EX | ||
| Fund. | Llama-3-8B | 21.86 | 70.50 | 2.32 | 33.08 | 28.53 | 3.10 | 29.21 | 6.29 | 25.15 | 74.95 | 25.05 | 39.27 | 22.02 | 37.86 |
| Qwen2.5-7B | 31.43 | 87.81 | 4.45 | 27.66 | 39.27 | 43.42 | 37.91 | 30.37 | 37.23 | 83.08 | 37.91 | 90.43 | 31.37 | 60.46 | |
| Mistral-7B | 21.95 | 27.27 | 2.03 | 27.47 | 32.01 | 17.70 | 29.01 | 0.19 | 3.58 | 0.00 | 31.43 | 0.19 | 20.00 | 12.14 | |
| Llama-2-7B | 9.67 | 0.77 | 0.77 | 16.83 | 14.99 | 1.06 | 12.19 | 0.77 | 0.00 | 0.00 | 12.09 | 0.58 | 8.29 | 3.34 | |
| Deepseek-7B | 16.34 | 0.77 | 2.71 | 26.50 | 23.99 | 0.58 | 21.57 | 0.19 | 20.02 | 0.00 | 20.21 | 0.10 | 17.47 | 4.69 | |
| Algorithm | Repr | EX | EM |
|---|---|---|---|
| Prompt workflow (Prem-1B-SQL) | – | 97.20 | 41.30 |
| Prompt workflow (CodeS-1B-Spider) | – | 87.81 | 43.13 |
| Model and prompt workflow | – | 97.20 | 41.30 |
| Model workflow | Alpaca Sft | 76.69 | 7.83 |
| Basic Prompt | 58.99 | 16.34 | |
| Code Repr. | 62.96 | 23.89 |
Text-to-SQL
Text-to-SQL translates natural-language questions into executable database queries, linking user intent to schemas, values, and SQL logic.
See all 167 papers