Distill-C: Enhanced NL2SQL via Distilled Customization with LLMs

Cong Duy Vu Hoang, Gioacchino Tangari, Clémence Lanfranchi, Dalu Guo, Paul Cayet, Steve Siu, Don Dharmasiri, Yuan-Fang Li, Long Duong, Damien Hilloulin, Rhicheek Patra, Sungpack Hong, Hassan Chafi

Abstract

The translation of natural language (NL) to SQL queries is a critical task for enterprise data accessibility. While large-scale language models (LLMs) demonstrate high accuracy, their deployment is often hindered by high latency and operational costs. Conversely, smaller models frequently struggle with the nuances of specialized database dialects and complex business logic. We present Distill-C (Distilled Customization), a framework that bridges this gap by transferring specialized reasoning from massive teacher models to lightweight student models. Through a modular synthesis pipeline and multi-step filtering, Distill-C achieves an average performance improvement of 36% across benchmarks, enabling 7B-parameter models to rival or surpass 70B+ parameter counterparts.

Introduction

Natural Language to SQL (NL2SQL) systems are increasingly vital for democratizing data access. However, a significant "performance-efficiency" gap persists. State-of-the-art models like GPT-4 or Llama-3-70B offer high accuracy but are resource-intensive. Smaller, open-source models (e.g., 7B-8B parameters) are efficient but often fail when confronted with real-world database complexities, such as OracleSQL-specific syntax, intricate date-time logic, and proprietary business rules. Existing knowledge distillation techniques typically focus on general capabilities; Distill-C addresses the need for customization in distillation to handle these domain-specific challenges.

The Distill-C Framework

Distill-C introduces a scalable pipeline for generating high-quality, customized synthetic data. The framework revolves around three primary customization scenarios:

  1. Reference Examples (AddRef): Utilizing a small set of customer-provided NL/SQL pairs to guide the teacher model in generating diverse, complex synthetic examples.
  2. Custom Instructions (LearnPrior): Incorporating specific business rules (e.g., specific date truncation logic) directly into the synthesis prompts to ensure dialect and style compliance.
  3. Error Feedback (FixIt): Identifying specific failure modes of a baseline model and generating targeted synthetic data to "patch" these weaknesses.
Overview of the Distill-C framework, illustrating the flow from customization information to synthesized SFT data and model finetuning.

Modular Synthesis and Multi-Step Filtering

The Distill-C pipeline decouples the generation of natural language questions from the generation of SQL queries. This modularity allows the system to leverage different LLM strengths—using one model for creative question phrasing and another for rigorous SQL logic.

To maintain high data quality, the synthesized pairs undergo a rigorous three-stage filtering process:

  • Pattern Matching: Filters out syntactically incorrect queries or those using the wrong SQL dialect.
  • Execution Validation: Ensures the SQL query executes successfully against a target database.
  • LLM-as-Juries: Employs an ensemble of strong LLMs to verify that the generated SQL accurately reflects the intent of the natural language question.

Experimental Results

The framework was evaluated on standard benchmarks (Spider 1.0, BIRD) and internal customer datasets. A key finding is that student models (7B/8B) fine-tuned on customized data can outperform the teacher models (70B+) that generated the data, suggesting that specialization is more critical than raw parameter count for enterprise tasks.

Accuracy on the Spider SQLite Dev Set, comparing base student models, FixIt-enhanced models, and teacher models across various SQL categories.

As shown in the evaluation results, the FixIt-enhanced models consistently narrow the gap with teacher models and, in several categories like "Set Operations" and "2x JOIN," significantly improve upon the base student model. Across three model families (CodeQwen, Llama-3, and Mistral), Distill-C delivered an average execution accuracy gain of 36%. On real-world internal benchmarks, the framework provided a 22.6% average improvement, with specific tasks like complex date-time logic seeing accuracy jumps from 80% to 97%.

Conclusion and Future Work

Distill-C demonstrates that specialization through customized distillation is a powerful alternative to increasing model size for enterprise NL2SQL tasks. By focusing on data quality and domain-specific logic, small models can achieve state-of-the-art performance. Future work will explore the application of Preference Alignment (DPO) and extending the framework to other specialized coding domains beyond SQL.

Summary updated

BibTeX
@inproceedings{hoang2025distill,
  author = {Cong Duy Vu Hoang and Gioacchino Tangari and Clémence Lanfranchi and Dalu Guo and Paul Cayet and Steve Siu and Don Dharmasiri and Yuan-Fang Li and Long Duong and Damien Hilloulin and Rhicheek Patra and Sungpack Hong and Hassan Chafi},
  title = {{Distill-C: Enhanced NL2SQL via Distilled Customization with LLMs}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.naacl-industry.64},
}
Figure