# Mind the Trap As LLMs Guess the Data Model: Grain-Aware Guards Against Fan-out in Text-to-SQL and Its Benchmarks

arXiv: https://arxiv.org/abs/2611.29009 · HTML: https://mlsanity.com/paper/2611.29009/

## Key facts

- No citing papers in the map yet (data through 24 Nov 2026).
- Builds on 19 of its 66 references that are in the map.
- Submitted 21 Nov 2026, announced 24 Nov 2026.

## Builds on (most cited first, 19 of 19)

- [Spider: A Large-Scale Human-Labeled Dataset for Complex and Cross-Domain Semantic Parsing and Text-to-SQL Task](https://mlsanity.com/paper/1809.08887/) (2018)
- [Can LLM Already Serve as A Database Interface? A BIg Bench for Large-Scale Database Grounded Text-to-SQLs](https://mlsanity.com/paper/2305.03111/) (2023)
- [GLM-5: from Vibe Coding to Agentic Engineering](https://mlsanity.com/paper/2602.15763/) (2026)
- [Semantic Evaluation for Text-to-SQL with Distilled Test Suites](https://mlsanity.com/paper/2010.02840/) (2020)
- [AMBROSIA: A Benchmark for Parsing Ambiguous Questions into Database Queries](https://mlsanity.com/paper/2406.19073/) (2024)
- [Benchmarking and Improving Text-to-SQL Generation under Ambiguity](https://mlsanity.com/paper/2310.13659/) (2023)
- [ReFoRCE: A Text-to-SQL Agent with Self-Refinement, Consensus Enforcement, and Column Exploration](https://mlsanity.com/paper/2502.00675/) (2025)
- [Understanding the Effects of Noise in Text-to-SQL: An Examination of the BIRD-Bench Benchmark](https://mlsanity.com/paper/2402.12243/) (2024)
- [Automatic Metadata Extraction for Text-to-SQL](https://mlsanity.com/paper/2505.19988/) (2025)
- [A Benchmark to Understand the Role of Knowledge Graphs on Large Language Model's Accuracy for Question Answering on Enterprise SQL Databases](https://mlsanity.com/paper/2311.07509/) (2023)
- [Pervasive Annotation Errors Break Text-to-SQL Benchmarks and Leaderboards](https://mlsanity.com/paper/2601.08778/) (2026)
- [SQLfuse: Enhancing Text-to-SQL Performance through Comprehensive LLM Synergy](https://mlsanity.com/paper/2407.14568/) (2024)
- [Grain Theory: Type-Level Granularity Correctness in Data Pipelines](https://mlsanity.com/paper/2601.00995/) (2026)
- [GROUND: Reducing Hallucinations in LLM-Based Enterprise Analytics Through Governed Semantic Definitions](https://mlsanity.com/paper/2608.26157/) (2026)
- [MCI-SQL: Text-to-SQL with Metadata-Complete Context and Intermediate Correction](https://mlsanity.com/paper/2603.13390/) (2026)
- [DexterSQL: Deep Schema Exploration and Rule-based Correction for Text-to-SQL Generation](https://mlsanity.com/paper/2608.11889/) (2026)
- [Disentangling Structure and Semantics: How Schema Representation Affects LLM-Based SQL Generation](https://mlsanity.com/paper/2608.20356/) (2026)
- [A Cost-Aware Agentic Architecture for NL-to-SQL over Nested Enterprise Schemas, with a New Benchmark](https://mlsanity.com/paper/2609.04641/) (2026)
- [ModularSQL: A Runtime Guardrail for the Multiplicity Blind Spot in Text-to-SQL](https://mlsanity.com/paper/2609.29573/) (2026)

## Abstract (arXiv)

Text-to-SQL systems built on large language models (LLMs) often aggregate over one-to-many and many-to-many joins, a classic trap: when the joined rows repeat an entity, a SUM or COUNT counts it more than once, yet the query runs and returns a plausible number. We characterize these fan-out errors by one condition on the relation an aggregate reads, which depends on two facts a schema does not show: each measure's grain, and how many rows a join on each key repeats. An audit that tests the condition on the data finds distorted gold answers for 4.2% of the dev questions of BIRD, a widely used benchmark, and BIRD's later, independent revision changed 44% of the answers the audit flags as definite fan-out, against 16% of unflagged ones. We release BIRD-FanOut, 486 BIRD questions with reviewed gold, and GrainTraps, synthetic questions that set this trap and related ones. Across eight LLM agents, functional dependencies (FDs) computed from the data help no more than per-column statistics on GrainTraps, but grain-aware FDs, which also state each measure's grain and the repetition per key, cut fan-out errors on BIRD from 18.4% of runs to about 13%, also on held-out questions and without LLM judges. Accuracy rises less, because most remaining errors are not fan-out and BIRD's hints often prescribe the over-count. Text-to-SQL models should be given the grain of the data, and benchmark gold should be audited on the data. Code, data and benchmarks are available at https://github.com/ahmed-mahran/misqal
