NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

EHRSQL: A Practical Text-to-SQL Benchmark for Electronic Health Records

Gyubok Lee, Hyeonji Hwang, Seongsu Bae, Yeonsu Kwon, Woncheol Shin, Seongjun Yang, Minjoon Seo, Jong-Yeup Kim, Edward Choi

Introduction

EHRSQL is a new, large-scale text-to-SQL benchmark designed to bridge the gap between academic research and the messy reality of healthcare data. By collecting questions from over 200 hospital staff and linking them to massive databases like MIMIC-III and eICU, the authors introduce a dataset that demands complex temporal reasoning and "trustworthy" behavior—requiring models to admit when a question is unanswerable.

What Problem Does This Paper Address?

While text-to-SQL systems (which translate natural language into database queries) have improved significantly, they often fail in specialized fields like healthcare. Existing medical datasets are either too simple, relying on repetitive templates, or they don't reflect the actual needs of hospital staff.

In a real hospital, a nurse might ask about a patient's "last arterial blood pressure," or an administrator might need the "five-year survival rate" for a specific diagnosis. These questions are complex, highly time-sensitive, and often require joining information across many tables. Furthermore, a clinical AI must be trustworthy: if a user asks a question the database can't answer (e.g., "What are the side effects of this drug?" when the DB only contains patient records), the model should refuse to answer rather than hallucinating a query.

Methods

The authors took a "human-in-the-loop" approach to dataset construction:

  1. The Poll: They surveyed 222 hospital staff (physicians, nurses, insurance teams) at a university hospital to collect 1,742 real-world questions.
  2. Templatization: These questions were turned into 230 general templates with "slots" (e.g., [patient_id], [drug_name]).
  3. Time Modeling: They developed a systematic "time template" to handle absolute (e.g., "in 2022"), relative (e.g., "last year"), and interval-based (e.g., "since discharge") expressions.
  4. Nested SQL Annotation: Unlike standard datasets that rely heavily on JOIN operations, the authors used nested subqueries. This is a practical choice for massive EHR databases (like MIMIC-III, which has tables with 300M+ rows) where joining everything is computationally inefficient.
Example of a complex EHR question translated into a nested SQL query.
  1. Trustworthiness Thresholding: To handle unanswerable questions, they implemented an uncertainty estimation method. If the model's "confidence" (measured by the entropy of its output) is too low, it triggers a refusal.

Datasets

The benchmark is linked to two major open-source Electronic Health Record (EHR) databases:

  • MIMIC-III: A massive database of de-identified health data from intensive care unit patients.
  • eICU: A multi-center database containing data from over 200,000 ICU admissions.
  • EHRSQL (The Benchmark): Contains 24,411 question-SQL pairs. It includes a specific "unanswerable" category derived from the original hospital poll.

Key Insights and Ideas

  • The Complexity Gap: EHRSQL queries are significantly more complex than previous benchmarks. On average, a query in EHRSQL spans 13.5 tables, compared to just 5 in MIMICSQL.
  • Time is a First-Class Citizen: In healthcare, the when is as important as the what. The authors found that 93.2% of their queries involve at least one time-related column, far higher than general-domain datasets like Spider (~12.7%).
  • Efficiency over Elegance: The decision to use nested queries instead of JOINs reflects a "production-first" mindset. In a database with hundreds of millions of rows, a standard JOIN might time out, whereas a nested subquery targeting specific IDs is much faster.
  • Knowing "I Don't Know": By including questions that are "Beyond DB Schema" or "Require External Knowledge," the authors force models to move beyond simple pattern matching and toward reliable decision support.
A trustworthy text-to-SQL model must distinguish between answerable queries and unanswerable questions, returning null when confidence is low.

Key Results

The authors tested baseline models (T5-base) and found that:

  • Answerability: Without any thresholding, models struggle to distinguish between answerable and unanswerable questions. However, using a percentile-based threshold on the model's entropy significantly improved the $F1_{ans}$ score to over 90%.
  • Execution Accuracy: Even when the model correctly identifies a question as answerable, generating the correct SQL is hard. The best baseline achieved an execution accuracy ($P_{exe}$) of around 88-94% on the test set.
  • The Zero-Shot Challenge: They tested a state-of-the-art model (GAP) trained on general-domain data. It achieved only 4.7% accuracy on EHRSQL, despite getting 16.4% on the simpler MIMICSQL. This proves that EHRSQL is a much tougher and more realistic test of a model's capabilities.

Limitations and Future Work

  • Single-Site Origin: The seed questions came from one university hospital in Korea. While the staff is diverse, the "culture" of questioning might differ in other countries or hospital systems.
  • Medical Jargon: The paraphrasing process used general-domain tools, which might have smoothed over some of the highly specific medical shorthand used by clinicians.
  • Scaling to Unseen Schemas: Currently, the model is trained and tested on the same database schemas. A major future challenge is "cross-database" performance—training on one hospital's EHR and successfully querying a completely different one.

Summary updated

BibTeX
@inproceedings{lee2022ehrsql,
  author = {Gyubok Lee and Hyeonji Hwang and Seongsu Bae and Yeonsu Kwon and Woncheol Shin and Seongjun Yang and Minjoon Seo and Jong-Yeup Kim and Edward Choi},
  title = {{EHRSQL: A Practical Text-to-SQL Benchmark for Electronic Health Records}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=8SQ9uLR4bxW},
}
Figure