Nanyang Technological University

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

This project measures how much asking helps beyond retry, what it costs, and when other strategies do better.

Running example

A query that runs can still search the wrong field

BIRD Dev task 780superhero database

“List the powers of Hunter Zolomon.”

SELECT sp.power_name FROM superhero AS s JOIN hero_power AS hp ON hp.hero_id = s.id JOIN superpower AS sp ON sp.id = hp.power_id WHERE s.superhero_name = 'Hunter Zolomon'
0 rowsRuns successfully, but returns no rows

The stored row in table superhero

ColumnValue
id756
superhero_nameZoom
full_nameHunter Zolomon
The model sees the schema, not sampled rows.
An empty result can look like a valid answer.

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

SRA (Summarize, Review, Ask) reviews the question, columns, output and values, then asks one multiple-choice question.
Its experiments compare this with SQL-only retry and early stopping.

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

Attempt 5 rejected: failed

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

Retry is told when it fails, with no answer: a control for recovery with failure feedback.
Target-aware simulated answers, not real users.
Logged calls show what each method received.

Study 1 example, step 1 of 3

One answer about the name field corrects the filter

Replay of BIRD task 780: after the first query returns 0 rows, the clarification step asks which name field should be used, with options superhero_name only, full_name only, either, or other

Filter column

Beforesuperhero_name

Question: which name field?
Simulated answer: full_name only
Next query: 4 rows, accepted

Study 1 example, step 2 of 3

One answer about the name field corrects the filter

Replay of BIRD task 780: the simulated user replies B, full_name only

Filter column

Beforesuperhero_name

Question: which name field?
Simulated answer: full_name only
Next query: 4 rows, accepted

Study 1 example, step 3 of 3

One answer about the name field corrects the filter

Replay of BIRD task 780: the next query filters s.full_name and returns four powers, Super Speed, Intangibility, Time Travel and Time Manipulation

Filter column

Beforesuperhero_name
Afterfull_name

Question: which name field?
Simulated answer: full_name only
Next query: 4 rows, accepted

For comparison

Retry: 0 rows in all 5 attempts

Study 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)

0%50%100%

420 more tasks

solved than with retry

Over the initial query: retry +7 points, clarification +34.
Extra SQL attempts help; clarification produces a much larger gain.

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

0227454

p < 0.001

Exact McNemar test

Clarification − retry: 95% interval +25.03 to +29.73 points.
Holds after excluding dev tasks and Sphinteract rescoring.

Study 1 resources

Clarification roughly doubled the estimated cost per task

Mean per taskSQL-only recoveryClarification
Estimated cost (US cents)0.3020.589
SQL attempts, excluding repairs3.122.57
Model calls3.165.72
Tokens5,40413,808

Estimated at the recorded 2026 API rates. Tokens include reasoning and cached input.

Clarification reaches a correct query sooner, so it uses fewer SQL attempts.
Questions and simulated answers still add calls and tokens.

US$105.48 in total

All API charges for every study, including checks and reruns

Failure case

A question can miss the actual error

BIRD Dev task 1342student_club database“What was the cost for the ‘Posters’ on 2019/9/4?”

SQL-only recovery

AND expense_date = '2019/9/4'
Attempt 1: 0 rows
AND expense_date = '2019-09-04'
Attempt 2: 1 row, accepted

Reactive clarification

AND expense_date = '2019/9/4'
All 5 attempts identical: not solved

4 questions confirmed choices already made: expense date, description, cost per item, cost field.

The database stores 2019-09-04, and no question asked about the date format.

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

SQL
▶
stop

Proactive-only

Ask or proceed
▶
SQL
if rejected▶
SQLretries without asking

Reactive

SQL
if rejected▶
Ask
▶
SQLrepeat

Hybrid

Ask or proceed
▶
SQL
if rejected▶
Ask
▶
SQLrepeat

Reactive, early stop

SQL
if rejected▶
Ask
▶
SQLrepeat

▶

at “no ambiguity”: stop

Hybrid’s first question counts toward its 4 answers.
Each configuration changes timing, retry rules and limits together.

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%50%100%

+0.07 points

hybrid over reactive

95% interval −1.76 to +1.89: no clear gain.
Early stopping cuts answers (1.51 → 0.71) but loses 13.30 points: no ambiguity ≠ correct SQL.

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

0%50%100%
The fourth answer still solves 57 more tasks (+3.72 points).
Five attempts follows Sphinteract: the budget tested, not a proven optimum.

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

Budget: 12 coins plus 2 per annotated ambiguity, at most 60 actions.

Four controllers

Reference: chooses freely
Proactive: once, after schema retrieval
Reactive: can ask after a rejection
Hybrid: at both points

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)

0%50%100%

+7.08 points

reference over hybrid

Unlike BIRD (almost level), hybrid beats reactive by 9.17 points.
Several rules differ at once, so no single rule’s effect can be isolated.

Limitations

The next test needs real users and a realistic failure signal

What the experiments assume

What to test next

A hidden evaluator knows whether each query is correct.
▶
Failure feedback a deployed system could actually obtain.
The simulated user reads the target SQL before answering.
▶
Recovery with real user replies, and how hard the questions are to answer.
One model, and one run per study.
▶
More models and repeated runs.

Conclusion

Asking recovered far more tasks at about twice the cost

Question

Answer, with the evidence

1

Does asking help beyond retry?

Yes, by 27.38 points

437 vs 17 disagreements; 0.589 vs 0.302 US cents per task

2

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

3

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

Next: test with real users and a failure signal a deployed system can obtain.

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

At most 12 calls, 5 SQL attempts and 4 replies per conversation; tests cover each safeguard.

Demonstration

Live demonstration

1

Saved case

Replay Hunter Zolomon from the study records, with no model calls

2

Try your reply

Send a different answer to its clarification question and compare the new SQL

3

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

github.com/faqihxdev/ntu-fyp-interactive-text-to-sql

Backup: Study 1 details

Outcomes for the 872 initial failures, and robustness checks

Clarification solvedClarification failed
Retry solved9017
Retry failed437328

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 methodBIRDSphinteract rule
Initial attempt43.16%40.35%
SQL-only recovery50.13%46.94%
Reactive clarification77.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

ComparisonPoints [95% CI]DiscordantExact pHolm p
S1 clarification − retry+27.38 [+25.03, +29.73]437/171.37 × 10⁻¹⁰⁶n/a
S1 retry − initial+6.98 [+5.74, +8.28]107/01.23 × 10⁻³²n/a
S2 hybrid − reactive+0.07 [−1.76, +1.89]102/1011.00001.0000
S2 proactive-only − reactive−20.27 [−22.56, −17.99]29/3401.85 × 10⁻⁶⁸5.54 × 10⁻⁶⁸
S2 early stop − reactive−13.30 [−15.25, −11.34]30/2342.34 × 10⁻⁴⁰n/a
S3 hybrid − reactive+9.17 [+3.75, +14.58]35/130.00210.0042
S3 hybrid − reference−7.08 [−12.50, −2.08]13/300.01370.0137
S3 hybrid − proactive+8.33 [+3.33, +13.33]29/90.0017n/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 methodCallsInput tokens (k)Output tokens (k)US cents
S1 initial-attempt baseline1.011.040.380.068
S1 SQL-only recovery3.163.461.940.302
S1 reactive clarification5.7211.182.630.589
S2 proactive-only5.387.181.970.397
S2 reactive6.7010.842.560.574
S2 hybrid7.4112.492.690.552
S2 reactive, early stop4.286.661.740.373
S3 reference12.83156.408.584.858
S3 hybrid14.22113.4911.754.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

Summarize, Review, Ask questions
SQL-only retry as the comparison, plus early stopping
Shared initial SQL and equal generation limits
Target-aware simulated user; 4 answers, 5 SQL generations
Question and schema input, without sample values or hints

Added or changed here

All 1,534 BIRD Dev tasks under BIRD’s scorer, with a different model
Shared initial repair as well as the initial SQL
Paired task-level intervals, development-task exclusion, cost accounting
Proactive and hybrid controllers; the Mini‑Interact study

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

Live branch of the Hunter Zolomon case after sending the reply C. Either superhero_name or full_name: the generated SQL filters superhero_name or full_name, returns four rows and is marked BIRD match

Sent reply

C. Either
superhero_name
or full_name

One model request: the new SQL accepts either name field.
The saved record is unchanged.

Outcome

4 rows, BIRD match

Backup: recorded demonstration

Asking a new question about a chosen database

Custom conversation on the superhero database: after the follow-up, the query keeps Good-aligned heroes and returns Ymir, King Kong, Fin Fang Foom, Groot and Wolfsbane by height

New question

“Who are the tallest heroes?”

It answered at once: the two tallest, tied at 30,480 cm, including the villain Surtur.
A follow-up asked for Good-aligned heroes only, top five.

Outcome

5 rows: executed, not verified

Show slides on

The slides open on the display you pick. This window keeps the controls, and your mouse shows there as a cursor while it is over the slide.