Final Year Project CCDS25-1205
Natural Language Interface to Databases Using LLMs
Evaluating Clarification and Recovery in Interactive Text-to-SQL
Muhammad Faqih Akmal
Supervisor: Assistant Professor Wang Qichen
Examiner: Associate Professor Vun Chan Hua, Nicholas
College of Computing and Data Science, 2026
The problem
When the first SQL query fails, should the system try again or ask the user?
Question
“List the powers of Hunter Zolomon.”
LLM writes SQL
From the question and schema
Database runs it
Rows or an error
Result is wrong
What happens next?
▼
▼
Retry
Generate another query
Ask
Clarify, then generate
Running example
A query that runs can still search the wrong field
“List the powers of Hunter Zolomon.”
The stored row in table superhero
| Column | Value |
|---|---|
| id | 756 |
| superhero_name | Zoom |
| full_name | Hunter Zolomon |
Previous work
Sphinteract is the closest prior method
MISP-SQL
Yao et al., 2019
Asks yes or no questions about uncertain choices while it builds the SQL.
PIIA
Li et al., 2020
Restates the SQL in English and clarifies unclear terms with multiple‑choice answers.
Sphinteract
Zhao et al., 2024
SQL rejected
SRA question
Answer, new SQL
The data
Two benchmarks of database questions with hidden answers
BIRD Dev
Studies 1 and 2
1,534
tasks
11
SQLite databases
Each task: a question, its database and a target SQL query. Examples: superhero, student_club, formula_1.
Mini-Interact
Study 3
240
tasks
26
SQLite databases
Requests with annotated ambiguities, a knowledge base to search, and the benchmark’s own evaluator.
The SQL-writing model sees
The question and the schema: tables, columns and keys
Hidden from it
Sample rows, BIRD’s hints and the target SQL, which only the evaluator and simulated user read
Study 1 method
Each rejection starts a new round, up to five attempts
1,534 BIRD Dev tasks, using GPT-5.6 Luna with high reasoning
Question, schema
No sample rows or hints
SQL attempt 1–5
Attempt 1 is shared
Evaluator
Matches the target?
Accepted: solved
The loop ends
▲
Next attempt
▼
Rejected
Simulated answer
Given to the model
Ask
One SRA question
Up to 4 answers; 1 repair per invalid query
Reactive clarification
The full loop
SQL-only recovery
Same loop without Ask and Answer; told only “rejected”
Initial-attempt baseline
Attempt 1 only
Study 1 method
The answer key stays outside the SQL generator
Has the answer key
Evaluator
Checks each result against the answer
Simulated user
Answers clarification questions
▼
“Rejected”, to
both methods
▼
Reply only, to
clarification
SQL generator: never sees the answer key
Question, schema, prior SQL, rejection and replies
Study 1 example, step 1 of 3
One answer about the name field corrects the filter
Filter column
Beforesuperhero_name
Study 1 example, step 2 of 3
One answer about the name field corrects the filter
Filter column
Beforesuperhero_name
Study 1 example, step 3 of 3
One answer about the name field corrects the filter
Filter column
Beforesuperhero_name
Afterfull_name
For comparison
Retry: 0 rows in all 5 attemptsStudy 1 results
Clarification beat retry by 27.38 percentage points
Tasks solved out of 1,534 under BIRD’s scorer, with simulated-user recovery
Initial-attempt baseline
43.16% (662)
SQL-only recovery
50.13% (769)
Reactive clarification
77.51% (1,189)
420 more tasks
solved than with retry
Study 1 results
Clarification won 437 of the 454 disagreements
Tasks solved by only one recovery method: 454 in total
Only clarification solved
437
Only retry solved
17
p < 0.001
Exact McNemar test
Study 1 resources
Clarification roughly doubled the estimated cost per task
| Mean per task | SQL-only recovery | Clarification |
|---|---|---|
| Estimated cost (US cents) | 0.302 | 0.589 |
| SQL attempts, excluding repairs | 3.12 | 2.57 |
| Model calls | 3.16 | 5.72 |
| Tokens | 5,404 | 13,808 |
Estimated at the recorded 2026 API rates. Tokens include reasoning and cached input.
US$105.48 in total
All API charges for every study, including checks and reruns
Failure case
A question can miss the actual error
SQL-only recovery
Reactive clarification
4 questions confirmed choices already made: expense date, description, cost per item, cost field.
Study 2 method
Five configurations differ in when they ask and stop
After each SQL, an accepted query ends the task. Each row shows what happens otherwise.
Initial-attempt baseline
SQLProactive-only
Ask or proceedReactive
SQLHybrid
Ask or proceedReactive, early stop
SQL▶
at “no ambiguity”: stop
Study 2 results
Hybrid and reactive scored similarly
Tasks solved out of 1,534; answers and calls are means per task
Answers
Calls
Initial-attempt baseline
44.65%
0
1.28
Proactive-only
58.02%
0.55
5.38
Reactive
78.29%
1.51
6.70
Hybrid
78.36%
1.68
7.41
Reactive, early stop
64.99%
0.71
4.28
+0.07 points
hybrid over reactive
Study 2 results, by round
Each answer recovered fewer tasks than the one before
Reactive clarification: tasks solved out of 1,534 after each answer
Gain
Attempt 1, no answers
44.65%
–
After answer 1
60.50%
+15.84
After answer 2
69.30%
+8.80
After answer 3
74.58%
+5.28
After answer 4
78.29%
+3.72
Study 3 method
In Mini-Interact, every action has a coin cost
240 tasks across 26 databases, the same model, and the benchmark authors’ evaluator
What each action costs, in coins
0.5 to 1
Retrieve schema or knowledge
1
Execute SQL to inspect values
2
Ask the simulated user
3
Submit an answer for scoring
Four controllers
Study 3 results
The flexible reference scored highest in Mini-Interact
Tasks solved out of 240 under the Mini-Interact evaluator
Reference
38.33% (92)
Hybrid
31.25% (75)
Proactive
22.92% (55)
Reactive
22.08% (53)
+7.08 points
reference over hybrid
Limitations
The next test needs real users and a realistic failure signal
What the experiments assume
What to test next
Conclusion
Asking recovered far more tasks at about twice the cost
Question
Answer, with the evidence
Does asking help beyond retry?
Yes, by 27.38 points
437 vs 17 disagreements; 0.589 vs 0.302 US cents per task
When should it ask, and when stop?
After a failure; don’t stop at “no ambiguity”
Asking earlier added 0.07 points; early stopping lost 13.30
What if the model chooses its actions?
The flexible reference scored highest
In Mini-Interact: 38.33%, vs 31.25% hybrid and 22.08% reactive
Implementation
The demonstrator separates saved evidence from new use
React interface
Browser, no API key
FastAPI server
Prompts and limits
▶
▶
Model API
Key kept on the server
SQLite databases
Read-only, 15-second limit
Three modes
Saved cases
Study records, no model calls
Try your reply
Branches up to that point; saved record unchanged
Try a question
Real replies; results unverified
Demonstration
Live demonstration
Saved case
Replay Hunter Zolomon from the study records, with no model calls
Try your reply
Send a different answer to its clarification question and compare the new SQL
Try a question
“Who are the tallest heroes?” Does “heroes” include villains?
Your turn
Ask your own question about one of the databases
Thank you
Questions are welcome.
Code and results
Backup: Study 1 details
Outcomes for the 872 initial failures, and robustness checks
| Clarification solved | Clarification failed | |
|---|---|---|
| Retry solved | 90 | 17 |
| Retry failed | 437 | 328 |
Recovered: retry 107 of 872 (12.3%); clarification 527 of 872 (60.4%). The 662 initial successes count for every method.
Without 120 development tasks
1,414 tasks remain; gain +28.08 points
Sphinteract-compatible rescoring
Initial 40.35%, retry 46.94%, clarification 72.69%; gain +25.75 points (saved queries only)
Exact McNemar test
437 vs 17 discordant tasks, p = 1.37 × 10⁻¹⁰⁶
Backup: scoring
How a query counts as correct
BIRD execution accuracy, used in both BIRD studies
Compares result rows as an unordered set: row order and duplicates are ignored, but column positions matter.
Sphinteract-compatible rescoring
Applied afterwards to the saved queries. It cannot create continuations that BIRD’s stopping decisions prevented.
| Study 1 method | BIRD | Sphinteract rule |
|---|---|---|
| Initial attempt | 43.16% | 40.35% |
| SQL-only recovery | 50.13% | 46.94% |
| Reactive clarification | 77.51% | 72.69% |
Study 2 reactive and hybrid both score 73.79% under the Sphinteract rule. Neither scorer is uniformly more lenient.
Backup: paired statistics
Selected paired comparisons with 95% intervals
| Comparison | Points [95% CI] | Discordant | Exact p | Holm p |
|---|---|---|---|---|
| S1 clarification − retry | +27.38 [+25.03, +29.73] | 437/17 | 1.37 × 10⁻¹⁰⁶ | n/a |
| S1 retry − initial | +6.98 [+5.74, +8.28] | 107/0 | 1.23 × 10⁻³² | n/a |
| S2 hybrid − reactive | +0.07 [−1.76, +1.89] | 102/101 | 1.0000 | 1.0000 |
| S2 proactive-only − reactive | −20.27 [−22.56, −17.99] | 29/340 | 1.85 × 10⁻⁶⁸ | 5.54 × 10⁻⁶⁸ |
| S2 early stop − reactive | −13.30 [−15.25, −11.34] | 30/234 | 2.34 × 10⁻⁴⁰ | n/a |
| S3 hybrid − reactive | +9.17 [+3.75, +14.58] | 35/13 | 0.0021 | 0.0042 |
| S3 hybrid − reference | −7.08 [−12.50, −2.08] | 13/30 | 0.0137 | 0.0137 |
| S3 hybrid − proactive | +8.33 [+3.33, +13.33] | 29/9 | 0.0017 | n/a |
S1 to S3: Studies 1 to 3. Discordant: tasks solved by only the first / only the second method. n/a: no Holm adjustment in the report. In Study 3, all four controllers fail on the same 129 of 240 tasks.
Backup: resources
Mean resource use per task in every study
| Study and method | Calls | Input tokens (k) | Output tokens (k) | US cents |
|---|---|---|---|---|
| S1 initial-attempt baseline | 1.01 | 1.04 | 0.38 | 0.068 |
| S1 SQL-only recovery | 3.16 | 3.46 | 1.94 | 0.302 |
| S1 reactive clarification | 5.72 | 11.18 | 2.63 | 0.589 |
| S2 proactive-only | 5.38 | 7.18 | 1.97 | 0.397 |
| S2 reactive | 6.70 | 10.84 | 2.56 | 0.574 |
| S2 hybrid | 7.41 | 12.49 | 2.69 | 0.552 |
| S2 reactive, early stop | 4.28 | 6.66 | 1.74 | 0.373 |
| S3 reference | 12.83 | 156.40 | 8.58 | 4.858 |
| S3 hybrid | 14.22 | 113.49 | 11.75 | 4.231 |
All API charges US$105.48: US$104.69 reconciled to run logs, US$0.79 unallocated.
Backup: relation to Sphinteract
What this project inherited, and what it added
Inherited from Sphinteract
Added or changed here
Published Sphinteract results use a different model and scorer, so they give context rather than a controlled comparison.
Backup: recorded demonstration
Trying another reply to a saved clarification
Sent reply
C. Either
superhero_name
or full_name
Outcome
4 rows, BIRD matchBackup: recorded demonstration
Asking a new question about a chosen database
New question
“Who are the tallest heroes?”
Outcome
5 rows: executed, not verified