Generating SQL Queries with Local Models

Fyodor Pakhurov, Nastya Izyumova3 Feb 2026

Problem

An internal analyst bot answers ad hoc questions in natural language: it writes SQL, runs it and explains the number. The proof of concept used a popular hosted LLM and synthetic data. A security team would not approve sending real company data to an outside model, so an open-weight model inside the company perimeter was needed. No single model fitting one A100 matched the hosted one on both text and SQL.

Example from the article: a user asks how many curd snacks were ordered in St. Petersburg, and the bot must return the number within seconds.

Solution in brief

The team split the job between two open-weight models, one for text and one for SQL. They chose each model on their own hand-checked questions instead of public benchmarks and tuned prompts until the best SQL model matched the reference score. vLLM behind a Triton wrapper cut SQL generation to 3 seconds, and static FP8 quantization made the models fit on one A100.

Questions this case answers
  • How to replace a hosted LLM with a self-hosted open-weight model for question answering over data when the data may not leave the company and the model must fit on one GPU
  • How to compare candidate models for natural-language-to-SQL when public benchmark scores are unreliable and several SQL texts can be correct for one question
  • How to bring self-hosted LLM inference latency down to a few seconds under a fixed single-GPU memory budget
  • How to pick an open-weight LLM that answers business questions with SQL when company data cannot leave the perimeter?

Tools and methods

  • vLLM — inference server with continuous batching and Paged Attention
  • NVIDIA Triton — custom wrapper around vLLM in production
  • bitsandbytes — int8 dynamic quantization used in testing
  • DeepEval — LLM-judge metrics (LLM-as-Judge, AnswerRelevancy, custom correctness)
  • Gemma — chosen model family for text understanding and generation
  • Mistral — chosen model family for text-to-SQL
  • Static FP8_E4M3 quantization — offline weight quantization to fit one A100
Continue reading — it's free

Google or a one-time email code. No password.