Large language models facilitate the generation of electronic health record phenotyping algorithms

Chao Yan, Henry H. Ong, Monika E. Grabowska, Matthew S. Krantz, Wu-Chen Su, Alyson L. Dickson, Josh F. Peterson, QiPing Feng, Dan M. Roden, C. Michael Stein, Vern Eric Kerchberger, Bradley A. Malin, Wei-Qi Wei

TL;DR

Researchers evaluated whether Large Language Models (LLMs) can automate the creation of "phenotyping algorithms"—the complex SQL queries used to identify patients with specific conditions in electronic health records (EHR). While GPT-4 and GPT-3.5 excelled at identifying relevant clinical concepts and drafting executable code, they still struggle with the complex logical nesting required for high-accuracy medical research, necessitating a "human-in-the-loop" approach.

What Problem Does This Paper Address?

In medical research, "phenotyping" is the process of turning messy, raw EHR data into a clean list of patients who actually have a specific disease. Currently, this is a massive bottleneck. Developing a single validated algorithm (e.g., "Who truly has Type 2 Diabetes?") requires months of work by clinical experts and informatics specialists who must manually review literature, identify relevant ICD codes, medications, and lab values, and then translate that knowledge into database queries.

Because this process is so labor-intensive, it limits the scalability of observational research. This paper investigates whether LLMs can expedite this by acting as an "automated architect" for these algorithms, translating clinical knowledge directly into executable SQL code.

Methods

The authors tested four prominent LLMs: ChatGPT-4, ChatGPT-3.5, Claude 2, and Bard (using the version available in October 2023). They tasked these models with generating SQL queries for three common conditions: Type 2 Diabetes (T2DM), dementia, and hypothyroidism.

The study employed two distinct prompting strategies:

  1. $\alpha$-prompting: A two-step process using Chain-of-Thought (CoT). First, the LLM generates a pseudocode "plan" listing criteria and logic. Second, it converts that plan into a SQL query.
  2. $\beta$-prompting: A self-refinement strategy where the LLM reviews five of its own previously generated algorithms, identifies errors or omissions, and produces a final, "improved" version.

The queries were designed to adhere to the OMOP Common Data Model (CDM), a global standard for EHR data structure, ensuring the results could theoretically be used across different hospital systems.

An architectural overview of the study pipeline, showing the prompting and evaluation stages.

Datasets

The generated algorithms were implemented and tested against a real-world dataset from Vanderbilt University Medical Center (VUMC), consisting of a research cohort of 84,821 patients. To measure success, the LLM-generated results were compared against "gold standard" algorithms from the eMERGE (Electronic Medical Records and Genomics) network, which are clinician-validated and widely used in the field.

Key Insights and Ideas

  • The "Clinical Encyclopedia" vs. "Junior Programmer" Gap: LLMs were remarkably good at identifying relevant clinical "ingredients"—the right medications (like Metformin for diabetes) and the correct ICD-10 codes. However, they struggled with the "recipe"—the complex logical operators (AND/OR/NOT) needed to combine those ingredients into a precise cohort.
  • Model Performance Disparity: There was a significant performance gap between models. ChatGPT-4 and 3.5 significantly outperformed Claude 2 and Bard in following instructions and producing executable SQL. Claude 2 often used abstract concept codes without labels, while Bard frequently hallucinated database columns that don't exist in the OMOP standard.
  • Logic is the Final Frontier: Most LLM errors were logical. For example, a model might require a patient to have every symptom on a list (too restrictive) or any single code without exclusions (too broad).
  • Self-Refinement Limits: Interestingly, the $\beta$-prompting (self-refinement) strategy did not significantly improve expert evaluation scores over the simpler $\alpha$-prompting. This suggests that if a model lacks the underlying logical framework for a task, simply asking it to "think again" has diminishing returns.

Key Results

The quantitative performance varied wildly depending on the disease and the model:

  • Dementia (GPT-4): Achieved a very high Positive Predictive Value (PPV) of 96.3%, meaning almost everyone it identified truly had dementia. However, it had a low recall (24.4%), missing many cases because its logic was too restrictive.
  • Hypothyroidism: Both GPT models achieved near-perfect recall (99.9%), but at the cost of very low PPV (~10%). They were essentially "casting too wide a net."
  • T2DM (GPT-3.5): The algorithm failed completely (0% recall) due to a logical error involving "LEFT JOINs" on non-existent values, highlighting the fragility of LLM-generated code.
  • Expert Scores: On a 1-3 scale, GPT-4 led with an average score of 2.57, followed by GPT-3.5 at 2.43. Claude 2 (1.91) and Bard (1.20) lagged significantly behind.

Limitations and Future Work

The authors acknowledge several hurdles. First, the study used the basic web-based chat interfaces; using APIs with adjusted parameters (like "temperature") might yield more stable results. Second, the study only looked at three common diseases; phenotyping rare diseases—where the LLM has less training data to draw from—remains an open challenge.

Future work will likely focus on prompt engineering to improve logical nesting and exploring newer models like Gemini or specialized medical LLMs. The ultimate goal isn't to replace the human expert, but to provide them with a "high-quality first draft" that cuts the development time from months to days.

Summary updated

BibTeX
@article{yan2024large,
  author = {Chao Yan and Henry H. Ong and Monika E. Grabowska and Matthew S. Krantz and Wu-Chen Su and Alyson L. Dickson and Josh F. Peterson and QiPing Feng and Dan M. Roden and C. Michael Stein and Vern Eric Kerchberger and Bradley A. Malin and Wei-Qi Wei},
  title = {{Large language models facilitate the generation of electronic health record phenotyping algorithms}},
  journal = {J. Am. Medical Informatics Assoc.},
  year = {2024},
  doi = {10.1093/jamia/ocae072},
}
Figure