Table of Contents
Fetching ...

Schema on the Inside: A Two-Phase Fine-Tuning Method for High-Efficiency Text-to-SQL at Scale

Chinmay Soni, Shivam Chourasia, Gaurav Kumar, Hitesh Kapoor

Abstract

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.

Schema on the Inside: A Two-Phase Fine-Tuning Method for High-Efficiency Text-to-SQL at Scale

Abstract

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.
Paper Structure (24 sections, 6 figures, 2 tables)

This paper contains 24 sections, 6 figures, 2 tables.

Figures (6)

  • 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.
  • 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.
  • ...and 1 more figures