Benchmarking and Improving Text-to-SQL Generation under Ambiguity

Adithya Bhaskar, Tushar Tomar, Ashutosh Sathe, Sunita Sarawagi

Abstract

Research in Text-to-SQL conversion has been largely benchmarked against datasets where each text query corresponds to one correct SQL. However, natural language queries over real-life databases frequently involve significant ambiguity about the intended SQL due to overlapping schema names and multiple confusing relationship paths. To bridge this gap, we develop a novel benchmark called AmbiQT with over 3000 examples where each text is interpretable as two plausible SQLs due to lexical and/or structural ambiguity. When faced with ambiguity, an ideal top-k decoder should generate all valid interpretations for possible disambiguation by the user. We evaluate several Text-to-SQL systems and decoding algorithms, including those employing state-of-the-art LLMs, and find them to be far from this ideal. The primary reason is that the prevalent beam search algorithm and its variants treat SQL queries as a string and produce unhelpful token-level diversity in the top-k. We propose LogicalBeam, a new decoding algorithm that navigates the SQL logic space using a blend of plan-based template generation and constrained infilling. Counterfactually generated plans diversify templates while in-filling with a beam-search that branches solely on schema names provides value diversity. LogicalBeam is up to 2.5 times more effective than state-of-the-art models at generating all candidate SQLs in the top-k ranked outputs. It also enhances the top-5 Exact and Execution Match Accuracies on SPIDER and Kaggle DBQA.

Introduction

Converting natural language into SQL is a cornerstone of making data accessible to non-technical users. However, most research relies on datasets like SPIDER, where every question has exactly one "correct" SQL query. In the real world, language is messy. A question like "What is the capacity of the stadium?" might be ambiguous if the database has separate columns for seating and standing capacity.

Current state-of-the-art models, including Large Language Models (LLMs), tend to be "greedy," fixating on a single interpretation. Even when generating multiple options (top-k), standard decoding methods like beam search often produce trivial variations—such as changing a table alias—rather than exploring the different logical meanings a user might have intended. This "diversity illusion" prevents effective human-in-the-loop disambiguation.

The AmbiQT Benchmark

To address this, researchers from IIT Bombay and Princeton introduced AmbiQT, the first benchmark specifically designed to test how Text-to-SQL models handle ambiguous queries. AmbiQT contains over 3,000 examples where each natural language question is paired with two valid SQL interpretations.

Examples of the four types of ambiguity in the AmbiQT benchmark, showing how a single question can lead to two valid SQL interpretations.

The benchmark categorizes ambiguity into four types:

  • Column Ambiguity (C): Multiple columns fit the description (e.g., roll_number vs. admission_number).
  • Table Ambiguity (T): Multiple tables could be the source (e.g., artist vs. performer).
  • Join Ambiguity (J): Uncertainty about whether a JOIN is required to reach specific data.
  • Precomputed Aggregates (P): Confusion over whether to calculate a value (e.g., SUM(price)) or use a pre-calculated column (e.g., total_price).

LogicalBeam: Navigating the Logic Space

To improve diversity, the authors developed LogicalBeam, a decoding algorithm that moves away from token-level search to navigate the SQL logic space. It employs a two-stage process:

  1. Plan-based Template Generation: Instead of generating SQL directly, the model predicts a logical "plan" (e.g., "1 join, 2 selects"). The algorithm then counterfactually perturbs this plan to force the model to generate templates for different structures.
  2. Restricted Infilling: Once structural templates are created, the model fills in the schema elements (tables and columns). Crucially, the beam search branches only on schema names, ensuring that the top-k results represent meaningful logical alternatives.
The LogicalBeam algorithm workflow: from a natural language query to diverse SQL candidates via plan perturbation and constrained infilling.

Key Results

LogicalBeam demonstrates significant improvements across multiple metrics and datasets:

  • Coverage: It is 1.5x to 2.5x more effective than baseline models at ensuring both valid SQL interpretations appear in the top-5 results on AmbiQT.
  • Accuracy Boost: On the standard SPIDER dev split, LogicalBeam improved top-5 Execution Match accuracy by 3.1%.
  • Generalization: On the challenging Kaggle DBQA dataset, LogicalBeam increased top-5 accuracy from 26.5% to 35.4%, proving its utility in complex, real-world scenarios.

Conclusion

By separating logical structure from schema content, LogicalBeam forces models to explore the "logic space" rather than just the "string space." This approach significantly improves the ability of Text-to-SQL systems to handle the inherent ambiguity of natural language, paving the way for more reliable interactive data exploration tools.

Summary updated

BibTeX
@inproceedings{bhaskar2023benchmarking,
  author = {Adithya Bhaskar and Tushar Tomar and Ashutosh Sathe and Sunita Sarawagi},
  title = {{Benchmarking and Improving Text-to-SQL Generation under Ambiguity}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  url = {https://openreview.net/forum?id=9X2pBLHOwa},
}
Figure