Applying large, proprietary API-based language models to text-to-SQL tasks poses a significant industry challenge: reliance on massive, schema-heavy prompts results in prohibitive per-token API costs and high latency, hindering scalable production deployment. We present a specialized, self-hosted 8B-parameter model designed for a conversational bot in CriQ, a sister app to Dream11, India's largest fantasy sports platform with over 250 million users, that answers user queries about cricket statistics. Our novel two-phase supervised fine-tuning approach enables the model to internalize the entire database schema, eliminating the need for long-context prompts. This reduces input tokens by over 99%, from a 17k-token baseline to fewer than 100, and replaces costly external API calls with efficient local inference. The resulting system achieves 98.4% execution success and 92.5% semantic accuracy, substantially outperforming a prompt-engineered baseline using Google's Gemini Flash 2.0 (95.6% execution, 89.4% semantic accuracy). These results demonstrate a practical path toward high-precision, low-latency text-to-SQL applications using domain-specialized, self-hosted language models in large-scale production environments.
Figures & tables
Figure 1: Conceptual overview of the conversational AI feature. A user asks a question in natural language, and the system returns a data-driven answer by generating and executing a SQL query.
Figure 2: A visual comparison of the two paradigms : Left side : “The External API Paradigm”, where a large prompt is sent to a third-party, pay-per-token service. Right side : “The Internalized Paradigm”, showing a small prompt with just the question going to a fine-tuned, self-hosted model with the schema “baked in”.
Figure 3: The iterative process for generating the ground-truth dataset. User queries are processed by a self-hosted reasoning LLM to generate SQL. The query is executed, and if successful, the question-SQL pair is stored. If it fails, the prompt is updated with the error, and the process is retried up to a maximum number of attempts.
Model
Exec. Acc.
LLaMA 3 8B ( AI@Meta 2024 )
83.76%
CodeLLAMA 7B ( Roziere et al. 2023 )
84.98%
Qwen 2.5 7B ( Bai et al. 2023 )
88.61%
Qwen 3 8B ( Bai et al. 2023 )
92.61%
Table 1: Initial fine-tuning benchmark results. Based on its superior performance, the Qwen 3 8B model was selected for all subsequent iterations.
System
Prompt Tokens
Exec. Acc.
Initial Prototype
10k
82.0%
Prompt-Eng. Baseline
17k
95.6%
Table 2: Comparison of the initial prototype and the improved, prompt-engineered baseline. Both used the Gemini 2.0 Flash model via its third-party API.
Figure 4: An overview of the two-phase fine-tuning methodology. Phase 1 combines full-context examples with explicit schema memorization tasks to create a schema-aware LoRA adapter. Phase 2 continues training using this adapter but with a minimal prompt, forcing the model to rely on its internalized knowledge of the schema.
Figure 5: Performance comparison of the final deployed model against the prompt-engineered Gemini baseline. The left chart shows our model achieved higher execution success (98.4% vs 95.6%) and semantic accuracy (92.5% vs 89.4%). The right chart illustrates the dramatic ( >99% ) reduction in prompt token length.
Figure 6: Execution and semantic accuracy for different Qwen 3 model sizes fine-tuned with our two-phase methodology. The 8B parameter model shows the highest accuracy, justifying its selection.
Harbin Engineering University, Harbin, China · Harbin Institute of Technology, Harbin, China · Beijing University of Posts and Telecommunications, Beijing, China