LLMs double count in text-to-SQL, and so does some of BIRD's gold

A single-author preprint shows how SQL joins silently inflate totals, finds the error in a slice of the BIRD benchmark's answer key, and shows that telling LLM agents what each number is recorded per cuts such errors by about a quarter.

6 min readIIIOpen sourcePreprint, not peer reviewed
Save
A still life on warm paper with a paper parcel tied with string to two wooden blocks next to two stacked coins, the top one deep blue.AI illustration
Illustration: AI generated

What the study shows

Text-to-SQL systems turn a plain question into a database query. The paper studies one classic failure, called fan-out. A join, which combines two tables, can repeat rows. A shipping fee stored once per order then appears once per order line. A SUM or COUNT over those rows counts it twice, but the query runs and returns a believable number.

The author, from the analytics company Incorta, frames this as one condition. A total is right only if each item appears once at its own level of detail, which the paper calls its grain. A schema does not show either the grain or how much a join repeats rows. Both can be measured from the data.

First, the author built an audit that runs probe queries on the data to test whether the rows a total reads repeat. It finds that 4.2% of the answer key on the dev set of BIRD, a common text-to-SQL benchmark, is distorted by fan-out. As an outside check, BIRD's own later cleaned release changed 44% of the answers the audit flagged, against 16% of unflagged ones. That revision was made without the audit.

Second, eight LLM agents answered questions while querying the database through a tool, across 38,232 runs. They received different kinds of evidence computed from the data. Plain dependency labels such as "each order can have many lines" helped little beyond basic column counts. Grain-aware evidence, which states each measure's grain and how many times a join repeats each row, cut fan-out errors on BIRD from 18.4% of runs to about 13%. The cut held on 183 questions not used to design the evidence, and without LLM judges doing the scoring.

Third, accuracy rose only about 3 points. The authors report two reasons. Most remaining errors are not fan-out. And BIRD's hints, written for the old answers, often tell the model to use the over-counting formula. The paper is a preprint and has not been peer reviewed.

Our reading

In our reading, the most useful finding is not the error cut but the diagnosis. The useful fact is not "this join can repeat rows". It is "this fee repeats about 3.5 times per order, so a sum counts it that often". Labels that only warn of repetition did little. Labels that name the measure and the multiplier did most of the work.

A concrete case: a finance assistant asked for total shipping fees per customer segment over an order-line table. Without help, a model sums the fee on every line. With the grain stated, it is told plainly that each fee sits on several rows. That is the kind of silent error that ends up in a board report.

The benchmark finding matters as much. If the answer key over-counts, a model that avoids the trap is scored as wrong. The check against BIRD's independent revision gives the audit some outside support, though a changed answer is not always a fan-out fix.

Free membership

Read the rest of this story

Membership is free. You get every article in full, and can save stories and follow topics.

We send a sign-in link, no password needed. Already a member? Sign in

Readiness assessment

III
Open source
LevelStatusEvidence
I  Lab onlyMetResearch prototype with a worked theory (grain condition), an audit and an evidence generator, tested in controlled experiments.
II  BenchmarkedMetResults are reported on the public BIRD benchmark (train, dev, Mini-Dev) and on the authors' GrainTraps suite, with comparisons against no-evidence and statistics baselines and significance tests.
III  Open sourceMetThe paper states code, data and benchmarks (BIRD-FanOut, GrainTraps, the audit, evidence code, column roles) are released at github.com/ahmed-mahran/misqal. Not checked by us; licence not stated in the paper.
IV  In productionNot yetNo documented use in production by a named organisation. The author is at Incorta but the paper reports no deployment.

What would move it up
Documented use of the audit or grain-aware evidence in a named organisation's live text-to-SQL system, with before and after error rates. Evidence that the gains hold on other databases, SQL dialects and full-schema settings would also help. Human-checked labels and the planned query-level facts (how the model's own joins repeat rows) would strengthen it.

The study

Ahmed M. Mahran. Mind the Trap As LLMs Guess the Data Model: Grain-Aware Guards Against Fan-out in Text-to-SQL and Its Benchmarks. arXiv, 21 November 2026. Read the paper

Preprint, not peer reviewed · Licence CC BY NC ND 4.0

Notes

  1. Mahran, A. M. Mind the Trap As LLMs Guess the Data Model: Grain-Aware Guards Against Fan-out in Text-to-SQL and Its Benchmarks. arXiv preprint, November 2026, not peer reviewed. Source
  2. Code, the audit, BIRD-FanOut (486 questions) and GrainTraps (59 questions), as stated in the paper. Not checked by us; licence not stated in the paper. Source
  3. Exact figures: fan-out errors on 229 distorted BIRD train questions were 18.4% with no evidence, 17.0% with statistics, 13.6% with Grain-FD and 13.1% with Grain-FD (tool). On 183 held-out questions: 16.1%, 15.1%, 12.4% and 12.2%. Accuracy rose from 60.3% to 63.3% and 63.2%.
  4. Validation: BIRD's cleaned dev release (2025-11-06) changed 36 of 82 answers with a definite fan-out flag (44%) and 217 of 1,397 unflagged ones (16%). Source
  5. GrainTraps grain errors: 17.4% with no evidence, 12.8% with statistics, 8.3% with Grain-FD and 7.7% with Grain-FD (tool).

Edited and signed by

Stefan PerdalEditor and publisher142 stories edited

Stefan read the study, set the readiness level and approved this story. An AI system found the paper and wrote the first draft.

How this was made

An AI model read the study and wrote this article in the structure Science Underway uses. An editor reviewed it and approved it for publication. Check the original study before you rely on the details.

More on Code