Problem
Sber has more than 100 thousand BI users, and its R&D team wanted an assistant that writes SQL from a plain-language question. The team could not send table metadata or data to ChatGPT, and the open models of that time read Russian badly. A model also does not know which values a column holds (Muzhchina/Zhenshchina or Male/Female), so it writes wrong string constants. Two queries with the same logic can look completely different, so evaluation cannot compare strings.
Example from the article: a question names a city that is stored in Russian in the table. Translating the whole question to English puts the English city name into the SQL, and the query fails.
Solution in brief
The team compared models on two benchmarks by executing queries, with AST similarity as a tiebreaker. The biggest gain came from scanning the database for sample values per column, adding them to the prompt, and fine-tuning CodeLlama-13B on 15 thousand such prompts. That reached 60+% on easy and medium queries.
Questions this case answers
- How to get a locally hosted language model to write executable SQL over arbitrary unseen tables from questions in a non-English language
- How to evaluate generated SQL on arbitrary schemas without the benchmark leaking into the training data
- How to choose and measure an open-weights LLM for text-to-SQL on questions written in Russian
- How to make a text-to-SQL model pick the right string constants in unseen tables
Tools and methods
- SQLGlot — parses SQL into trees, validates generated queries, measures tree difference
- PAUQ and Vacancies benchmarks — Russian Spider translation and a database no model has likely seen
- Prompt with column statistics — DDL, sample column values and the question
- LoRA fine-tuning (Hugging Face PEFT) — adapts a 13B model to such prompts
- Apache Superset (SDP Analytics) — BI front end of the prototype
Google or a one-time email code. No password.