Manuscript Offprint

arXiv:2611.02484

Benchmark of THReD: Evaluating an LLM Agent and Its Preprocessing Tools for Turning Electronic Health Records into AI-Ready Datasets

Javad Mohammad Alizadeh, Huanmei Wu

Abstract

Large language model (LLM) agents are increasingly built into data-analysis software, yet there is little evidence on how reliably they carry out the preprocessing of clinical data, or on whether the deterministic tools they invoke produce correct and reproducible output. We report a benchmark of THReD, a web-based system that turns electronic health record (EHR) extracts into AI-ready datasets through a chat agent whose proposed steps run only after the user confirms them. The agent benchmark contains 141 tasks, derived from 100 templates and grouped into seven categories: single-tool, multi-step and goal-level requests, failure recovery, requests that call for no action, variations of the table schema, and instructions injected into the data. Tasks run on synthetic tables calibrated to a regional health information exchange, and success is decided by checks on the data each episode produces rather than on the tools it calls. Over 2,550 episodes with Claude Haiku 5.5 in four context configurations, the deployed agent completed 92.7% (95% CI 88.1–96.4) of tasks on its first answer, abstained correctly on every advice request, recovered from every injected fault, and never proposed an action requested by text planted in the data. Without the data profile, first-attempt completion fell to 58.0%; goal-level requests remained the hardest category (80.6%). Six further experiments examine the preprocessing tools on real records of two chronic-disease cohorts and on synthetic data at scale. In masked reconstruction, 91–92% of inferred patient classes and 99.7–99.8% of inferred vital-sign labels were correct; a dictionary builder that combines curated dictionaries with LLM suggestions mapped 99.0% of 2,208 raw category variants correctly; all 2,176 replays of 128 saved pipelines reproduced byte-identical files under pinned dependencies; differences across demographic subgroups in the accuracy of inferred values disappeared within facility and lookup key; and the rule that keeps one encounter per patient and day changed 90-day emergency revisit rates by up to 3.2 percentage points without shifting any subgroup's share of the cohort by more than one point. Processing time grew roughly in proportion to the data up to 5.5 million records, while the prompt sent to the model stayed at about 13 thousand tokens.

Keywords: electronic health records; data preprocessing; LLM agents; tool use; benchmark; prompt injection; reproducibility; algorithmic fairness

1 Introduction

Secondary use of electronic health records (EHRs) for research and machine learning depends on a long chain of preprocessing: removing duplicated and implausible records, harmonizing the many

∗^{*}Corresponding author: javad.m.alizadeh@temple.edu spellings of the same category, converting codes and units, filling values that can be recovered from context, and building the cohort and the variables an analysis needs. Each of these steps is a source of error and of undocumented analytic choices [1-4]. Preprocessing is usually written as study-specific scripts [5], and machine learning for health has repeatedly been found difficult to reproduce, in part because the data preparation behind a result is rarely shared in executable form [6-8].

Large language models (LLMs) can now plan and call external tools [9-11], and several systems apply them to data wrangling and data science [12-14]. An agent that cleans clinical data, however, carries specific risks. A wrong step changes the data silently and propagates into every downstream estimate; text inside the records can act as an instruction to the model [15]; sending records to an external model raises privacy concerns; and preprocessing rules that work well on average may err more often for some patient groups [16, 17]. Assessing such an agent therefore requires more than a score for tool selection. It requires evidence that the agent completes realistic tasks, refrains from acting when it should, recovers from failures, resists instructions hidden in the data, and that the tools it drives produce output that is correct, reproducible and equitable.

Existing agent benchmarks measure generic tool use and multi-turn interaction [18-21], and data-science benchmarks score the code a model writes on general-purpose data [22-24]. None evaluates a deployed clinical preprocessing agent end to end, under its real confirmation workflow, while also validating the inference, mapping and replay components on which its output depends.

This paper reports such an evaluation for THReD, a web-based system that turns EHR extracts into AI-ready datasets [25]. In THReD a researcher can apply each operation from the interface or ask a chat agent, which proposes the operations as tool calls that run only after the researcher confirms them. Every applied step is logged and can be saved and replayed. Our contributions are:

  1. An agent benchmark for clinical data preprocessing. 141 tasks in seven categories, each with an expert reference pipeline and outcome checks evaluated on the resulting data, run through the deployed system's own chat functions and confirmation gate, with a fixed simulated researcher for follow-up turns (Sections 4 and 5).

  2. A context ablation that isolates the contribution of the data profile, the operation history and read-only lookups to the agent's competence (Section 5.2).

  3. Validation of two value-producing components on real EHR data: masked reconstruction for rule-based inference of missing values, and an expert-annotated reference for LLM-assisted category mapping (Sections 6.1 and 6.2).

  4. Evidence on scale, reproducibility and equity: processing time and prompt size up to 5.5 million records, byte-level replay of saved pipelines across processes and environments, preprocessing errors by demographic subgroup, and the sensitivity of the cohort to the same-day consolidation rule (Sections 6.3–6.6).

The code, task definitions, per-episode results and aggregate experiment results are released with a technical report [26].

References (42)