Overview
Business users need figures from relational databases but rarely write SQL. For the ENSAE statistical project (StatApp), our team of four, supervised by Amadou Diouf, built an assistant that answers such questions in plain language: it writes a query, checks it, runs it on a read-only connection and explains the result. The database (clients, case files, transactions) was provided for the project and is not public; this page shows none of its contents.
Measuring the baseline first
The team benchmarked a small local model (llama3.2 through Ollama) on 100 questions with
reference SQL, in four difficulty levels. A query counted as correct when it returned the same
result set as the reference, so equivalent queries written differently were accepted.
| Finding (team report, March 2026) | Value |
|---|---|
| Execution accuracy | 16 % (95 % Wilson interval 10.1–24.4) |
| Easiest → hardest level | 40 % → 0 % |
| Accuracy independent of difficulty? (, 3 df) | No: , |
| Wrong queries that still ran | 66 of 84 |
Most failures were semantic, not syntactic: the model usually wrote runnable SQL that
answered the wrong question, often with the wrong or invented columns. No query with a join, a
window function or a CASE expression was correct. That perfect separation makes ordinary
logistic regression unstable, so the team used an L2-penalised model and read it cautiously.
Baseline execution accuracy by difficulty level
llama3.2 on 100 questions; whiskers are Wilson 95 % intervals.
Data table
| Level | Questions | Correct | Accuracy | 95 % interval |
|---|---|---|---|---|
| Level 1 — simple | 25 | 10 | 40% | 23.4–59.3% |
| Level 2 — intermediate | 35 | 4 | 11.4% | 4.5–26% |
| Level 3 — advanced | 25 | 2 | 8% | 2.2–25% |
| Level 4 — expert | 15 | 0 | 0% | 0–20.4% |
The assistant
Each component answers a failure mode from the benchmark. The prompt gets only the relevant part
of the schema and three similar question–SQL examples. Expert-corrected queries are reused before
any new generation. The validator accepts a single SELECT and blocks listed keywords and
personal-data columns. That blocklist is not a security boundary: the stronger protection is the
read-only connection to a local copy of the data.
Limitations
- The final pipeline was not re-benchmarked. The 16 % measures the March 2026 baseline. The retrieval, repair and memory components came later, and their effect on accuracy is unmeasured.
- Small benchmark, one model. With 100 questions, per-level accuracies have wide intervals; the difficulty breakdown applies to this benchmark and model.
- Not runnable publicly, since the business data is not in the repository.
Individual contribution
Team of four. Bunrong Ban built the first working application (Streamlit interface, router and SQL agents, database layer and build script). Vítor Prata Zielinski wrote an early agent prototype and a usage guide. Montaha Ben Zaied explored lexical, vector and hybrid search on a separate team branch. The benchmark and its statistical analysis are the team's shared report.
My part, from the repository history: I rebuilt the application as the LangGraph pipeline with conversation state and the context resolver; added the expert-correction memory, the repair loop and the analysis and visualisation agents; implemented example retrieval, the guardrails and validator extensions; and wrote the test suite and architecture documentation.
References
- Yu, T. et al. (2018). Spider: a large-scale human-labeled dataset for complex and cross-domain semantic parsing and text-to-SQL. EMNLP.
- Wilson, E. B. (1927). Probable inference, the law of succession, and statistical inference. JASA 22, 209–212.
- Albert, A. and Anderson, J. A. (1984). On the existence of maximum likelihood estimates in logistic regression models. Biometrika 71(1), 1–10.