ModularSQL: A Runtime Guardrail for the Multiplicity Blind Spot in Text-to-SQL
Organizations: University of Southern California · Northeastern University
Abstract
Text-to-SQL systems are increasingly deployed on production databases, where queries that pass benchmark evaluation can still produce results that distort downstream workflows. Standard set-based execution accuracy (Set-EX) collapses duplicate rows and can therefore miss multiplicity errors, including missing DISTINCT, inflated aggregates, and Cartesian-style join explosions. We call this the Multiplicity Blind Spot (MBS) and introduce Multiset-EX, a multiplicity-preserving evaluation criterion that exposes such failures. Across released DeepEye-SQL artifacts from three backbones (Qwen2.5-Coder-32B, Qwen3-Coder-30B-A3B, and Gemma-3-27B) on executable BIRD-Dev N=1532, we find a consistent 5.81--6.79 pp gap between Set-EX and Multiset-EX. The gap is not specific to DeepEye-SQL: it persists on released DAIL-SQL+GPT-4 (5.22 pp) and BIRD GPT-3.5-turbo (3.39 pp) predictions. We further introduce ModularSQL, a lightweight post-selection runtime guardrail that probes executed results for multiplicity anomalies and applies deterministic patches or low-cost LLM rescue only to flagged queries. Integrated with DeepEye-SQL using Qwen3-Coder, ModularSQL preserves Set-EX at 72.06% while improving Multiset-EX from 65.86% to 67.75% (+1.89 pp). It flags 77 high-risk anomalies, while adding only $0.0076 in total LLM cost and 120 ms amortized latency per query. Cross-pipeline evaluation shows that the candidate-free detector and deterministic patches also transfer to independently released prediction sets. Overall, these results show that benchmark accuracy does not necessarily imply execution-safe SQL, and that lightweight, multiplicity-aware runtime guardrails can narrow this gap with modest computational overhead.
Figures & tables
| Backbone | Set | Multi | Gap |
|---|---|---|---|
| Qwen2.5-Coder-32B | 69.91 | 64.10 | 5.81 |
| Qwen3-Coder-30B-A3B | 72.85 | 66.51 | 6.33 |
| Gemma-3-27B | 70.50 | 63.71 | 6.79 |
| Qwen3-Coder-30B-A3B (ours) | 72.06 | 65.86 | 6.20 |
| System | Set-EX | Mset-EX | Gap | Flagged | Patched Mset |
|---|---|---|---|---|---|
| DAIL-SQL+GPT-4 | 53.59 | 48.37 | 5.22 | 270 | 49.02 ( ) |
| BIRD GPT-3.5 (kg) | 35.90 | 32.51 | 3.39 | 555 | 33.03 ( ) |
| DeepEye-SQL (ours) | 72.06 | 65.86 | 6.20 | 77 | — |
| System | Set-EX (%) | Multiset-EX (%) | Multiset-EX |
|---|---|---|---|
| DeepEye reproduction | 72.06 | 65.86 | — |
| + P1 | 72.06 | 67.23 | |
| + P1 + P2 | 72.06 | 67.43 | |
| v1: P1+P2 Rescue | 72.06 | 67.17 | |
| v2: Rescue P1+P2 | 72.06 | 67.75 | |
| v2 variant: dup-ratio selector | 72.19 | 67.30 |
| Difficulty | Base | ModularSQL v2 | ||
|---|---|---|---|---|
| Simple | 925 | 71.57 | 73.19 | |
| Moderate | 463 | 60.48 | 62.20 | |
| Challenging | 144 | 46.53 | 50.69 |
Appendix figures & tables8 assets
Supplementary material from the paper’s appendix.
Appendix
| Fix | Break | Net | |
|---|---|---|---|
| 0.10 | 45 | 34 | |
| 0.30 | 44 | 26 | |
| 0.60 | 36 | 15 | |
| 0.80 | 30 | 8 | |
| 0.90 | 20 | 3 |
| Fires | Fix | Break | Net | |
|---|---|---|---|---|
| 0.10 | 5 | 3 | 0 | |
| 0.20 | 8 | 4 | 1 | |
| 0.30 | 12 | 4 | 4 | |
| 0.50 | 25 | 9 | 9 | |
| 0.80 | 45 | 15 | 18 |
| Pipeline stage | Multiset-EX | vs P1+P2 |
|---|---|---|
| DeepEye reproduction | 1009 | — |
| + P1 | 1030 | — |
| + P1 + P2 | 1033 | |
| v1 (P1+P2 Rescue) | 1029 | |
| v2 (Rescue P1+P2) | 1038 |
| Difficulty | Base | + P1 | + P1+P2 | v1 | v2 | |
|---|---|---|---|---|---|---|
| Simple | 925 | 662 | 671 | 673 | 671 | 677 |
| Moderate | 463 | 280 | 287 | 288 | 286 | 288 |
| Challenging | 144 | 67 | 72 | 72 | 72 | 73 |
| Total | 1532 | 1009 | 1030 | 1033 | 1029 | 1038 |
| Flagged by reason | P1 patch (Mset-EX) | |||||||
|---|---|---|---|---|---|---|---|---|
| System | Exec | Empty | Cart | Total | P1 | Fix | Brk | Net |
| DeepEye-SQL | 1 | 6 | 70 | 77 | 56 | 30 | 8 | |
| DAIL-SQL+GPT-4 | 96 | 100 | 74 | 270 | 49 | 22 | 12 | |
| GPT-3.5-turbo | 354 | 160 | 41 | 555 | 11 | 8 | 0 | |
| System | Base Set-EX | New Set-EX | Base Mset-EX | New Mset-EX |
|---|---|---|---|---|
| DAIL-SQL+GPT-4 | 53.59% | 53.59% | 48.37% | 49.02% |
| GPT-3.5-turbo | 35.90% | 35.90% | 32.51% | 33.03% |
| Precision | MBS recall | ||||||
|---|---|---|---|---|---|---|---|
| System | Flagged | TP | FP | MBS | Flagged | ||
| DeepEye-SQL | 77 | 65 | 12 | 0.844 | 95 | 36 | 0.379 |
| DAIL-SQL+GPT-4 | 271 | 256 | 15 | 0.945 | 80 | 34 | 0.425 |
| GPT-3.5-turbo | 555 | 550 | 5 | 0.991 | 52 | 18 | 0.346 |
| Trigger reason | DeepEye-SQL | DAIL-SQL+GPT-4 | GPT-3.5-turbo |
|---|---|---|---|
| exec_error | 1.000 (1/1) | 1.000 (97/97) | 1.000 (354/354) |
| empty_result | 1.000 (6/6) | 1.000 (100/100) | 1.000 (160/160) |
| cartesian_expl | 0.829 (58/70) | 0.797 (59/74) | 0.878 (36/41) |
Text-to-SQL
Text-to-SQL translates natural-language questions into executable database queries, linking user intent to schemas, values, and SQL logic.
See all 169 papers