Table of Contents
Fetching ...

Query Carefully: Detecting the Unanswerables in Text-to-SQL Tasks

Jasmin Saxer, Isabella Maria Aigner, Luise Linzmeier, Andreas Weiler, Kurt Stockinger

TL;DR

This work tackles the safety risks of text-to-SQL systems in the biomedical domain by introducing Query Carefully, a pipeline that combines LLM-based SQL generation with explicit unanswerable-input handling. It builds OncoMX-NAQ, a curated set of 80 no-answer questions across 8 categories to systematically evaluate abstention and detection, alongside the OncoMX (ScienceBenchmark) dataset for answerable queries. The study shows that balanced few-shot prompting—incorporating both answerable and unanswerable examples—yields strong unanswerable-detection performance (up to ~0.8 in NAQ detection) and robust result accuracy on structured, non-ambiguous categories, while highlighting challenges with missing-values and column ambiguity. A lightweight user interface enables transparent inspection of interim SQL, results, and abstentions, enhancing reliability for biomedical data access. Overall, the approach improves safety and reliability of text-to-SQL in sensitive domains by prioritizing abstention and explanation when questions fall outside recoverable scope.

Abstract

Text-to-SQL systems allow non-SQL experts to interact with relational databases using natural language. However, their tendency to generate executable SQL for ambiguous, out-of-scope, or unanswerable queries introduces a hidden risk, as outputs may be misinterpreted as correct. This risk is especially serious in biomedical contexts, where precision is critical. We therefore present Query Carefully, a pipeline that integrates LLM-based SQL generation with explicit detection and handling of unanswerable inputs. Building on the OncoMX component of ScienceBenchmark, we construct OncoMX-NAQ (No-Answer Questions), a set of 80 no-answer questions spanning 8 categories (non-SQL, out-of-schema/domain, and multiple ambiguity types). Our approach employs llama3.3:70b with schema-aware prompts, explicit No-Answer Rules (NAR), and few-shot examples drawn from both answerable and unanswerable questions. We evaluate SQL exact match, result accuracy, and unanswerable-detection accuracy. On the OncoMX dev split, few-shot prompting with answerable examples increases result accuracy, and adding unanswerable examples does not degrade performance. On OncoMX-NAQ, balanced prompting achieves the highest unanswerable-detection accuracy (0.8), with near-perfect results for structurally defined categories (non-SQL, missing columns, out-of-domain) but persistent challenges for missing-value queries (0.5) and column ambiguity (0.3). A lightweight user interface surfaces interim SQL, execution results, and abstentions, supporting transparent and reliable text-to-SQL in biomedical applications.

Query Carefully: Detecting the Unanswerables in Text-to-SQL Tasks

TL;DR

This work tackles the safety risks of text-to-SQL systems in the biomedical domain by introducing Query Carefully, a pipeline that combines LLM-based SQL generation with explicit unanswerable-input handling. It builds OncoMX-NAQ, a curated set of 80 no-answer questions across 8 categories to systematically evaluate abstention and detection, alongside the OncoMX (ScienceBenchmark) dataset for answerable queries. The study shows that balanced few-shot prompting—incorporating both answerable and unanswerable examples—yields strong unanswerable-detection performance (up to ~0.8 in NAQ detection) and robust result accuracy on structured, non-ambiguous categories, while highlighting challenges with missing-values and column ambiguity. A lightweight user interface enables transparent inspection of interim SQL, results, and abstentions, enhancing reliability for biomedical data access. Overall, the approach improves safety and reliability of text-to-SQL in sensitive domains by prioritizing abstention and explanation when questions fall outside recoverable scope.

Abstract

Text-to-SQL systems allow non-SQL experts to interact with relational databases using natural language. However, their tendency to generate executable SQL for ambiguous, out-of-scope, or unanswerable queries introduces a hidden risk, as outputs may be misinterpreted as correct. This risk is especially serious in biomedical contexts, where precision is critical. We therefore present Query Carefully, a pipeline that integrates LLM-based SQL generation with explicit detection and handling of unanswerable inputs. Building on the OncoMX component of ScienceBenchmark, we construct OncoMX-NAQ (No-Answer Questions), a set of 80 no-answer questions spanning 8 categories (non-SQL, out-of-schema/domain, and multiple ambiguity types). Our approach employs llama3.3:70b with schema-aware prompts, explicit No-Answer Rules (NAR), and few-shot examples drawn from both answerable and unanswerable questions. We evaluate SQL exact match, result accuracy, and unanswerable-detection accuracy. On the OncoMX dev split, few-shot prompting with answerable examples increases result accuracy, and adding unanswerable examples does not degrade performance. On OncoMX-NAQ, balanced prompting achieves the highest unanswerable-detection accuracy (0.8), with near-perfect results for structurally defined categories (non-SQL, missing columns, out-of-domain) but persistent challenges for missing-value queries (0.5) and column ambiguity (0.3). A lightweight user interface surfaces interim SQL, execution results, and abstentions, supporting transparent and reliable text-to-SQL in biomedical applications.
Paper Structure (28 sections, 5 figures)

This paper contains 28 sections, 5 figures.

Figures (5)

  • Figure 1: Query Carefully pipeline with user interface. NAQ: No-Answer-Questions.
  • Figure 2: Accuracy of different prompts on OncoMX Dev and OncoMX-NAQ dataset. The soft correct accuracy of OncoMX Dev is shown.
  • Figure 3: Different measurements of ScienceBenchmark (OncoMX dev) per prompt type. AQ: Answerable Questions, NAQ: No-Answer Questions.
  • Figure 4: Accuracy of detection of unanswerable questions divided by category and prompt. AQ: Answerable Questions, NAQ: No-Answer Questions.
  • Figure 5: Example of an unanswerable question on the user interface.