Skip to content
Senghak Rou
All projects

Artificial Intelligence · Oct 2025 – May 2026

Conversational Text-to-SQL

An assistant translates business questions into read-only SQL. A 100-question baseline study exposed a practical failure: a query can run successfully and still return the wrong result.

Status
CompletedConcluded in May 2026. The final pipeline was not re-benchmarked.
Setting
Team project (4)ENSAE statistical project (StatApp), 2025–2026
My role
Rebuilt the team's first prototype as the LangGraph pipeline; wrote the correction memory, repair loop, example retrieval, guardrails and tests.
Methods and tools
Python · LangGraph · LangChain · SQLite · Streamlit · Plotly · Ollama · pytest

16 %

Execution accuracy of the baseline model on the team's 100-question benchmark

95 % Wilson interval: 10.1–24.4 %

40 % → 0 %

Accuracy from the easiest to the hardest of four difficulty levels

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 accuracy16 % (95 % Wilson interval 10.1–24.4)
Easiest → hardest level40 % → 0 %
Accuracy independent of difficulty? (χ2\chi^2, 3 df)No: χ2=15.31\chi^2 = 15.31, p=0.0016p = 0.0016
Wrong queries that still ran66 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.

010203040506070Execution accuracy (%)Level 1 — simpleLevel 1 — simple: 10 of 25 correct (40%), 95% interval 23.4–59.3%40.0%Level 2 — intermediateLevel 2 — intermediate: 4 of 35 correct (11.4%), 95% interval 4.5–26%11.4%Level 3 — advancedLevel 3 — advanced: 2 of 25 correct (8%), 95% interval 2.2–25%8.0%Level 4 — expert0.0%
Data table
LevelQuestionsCorrectAccuracy95 % interval
Level 1 — simple251040%23.4–59.3%
Level 2 — intermediate35411.4%4.5–26%
Level 3 — advanced2528%2.2–25%
Level 4 — expert1500%0–20.4%
Figure 1 · Experimental resultAccuracy falls from 40 % on simple questions to none on expert ones. The intervals are wide (only 15 to 35 questions per level), but the χ² test rejects independence from difficulty.Source: Team report (March 2026), appendix Table 1. The table prints n = 35 for level 3; its 8 % and interval match 2 of 25, and the levels then sum to 100.

The assistant

Text-to-SQL assistant: the LangGraph flow A question first goes to a context resolver, which may send a chart follow-up to the visualisation agent or answer chat and clarification directly. Rule-based guardrails decline out-of-scope requests. Expert-corrected SQL is reused when a similar question exists; otherwise an LLM SQL agent writes a query from the schema and three retrieved examples. The query is validated and run on a read-only SQLite connection; on failure an error agent repairs it, at most three times. An analysis agent writes the answer. question + conversation state context resolver guardrails rule-based scope check expert corrections no match SQL agent (LLM) writes one SELECT validate + run read-only SQLite analysis agent → answer chart? viz agent re-plots last result similar question (match ≥ 0.55): reuse its SQL reply directly clarify or decline chat out of scope schema 3 examples error agent (LLM) error repaired SQL at most 3
Figure 2 · SchematicThe LangGraph flow, as wired in the code. Teal steps are deterministic; blue steps call the language model.

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

References

  1. Yu, T. et al. (2018). Spider: a large-scale human-labeled dataset for complex and cross-domain semantic parsing and text-to-SQL. EMNLP.
  2. Wilson, E. B. (1927). Probable inference, the law of succession, and statistical inference. JASA 22, 209–212.
  3. Albert, A. and Anderson, J. A. (1984). On the existence of maximum likelihood estimates in logistic regression models. Biometrika 71(1), 1–10.
Oct – Nov 2026Completed

VisualDoc AI

Ask a question about a PDF and inspect the page behind the answer. VisualDoc reads page images, searches text and checks quoted evidence so a reader can trace a number back to its table.

Artificial Intelligence · Individual · Python, ColQwen2, PyMuPDF