ConceptioArchivearXiv CS
arXiv CSopen access

FeatEHR-LLM: Leveraging Large Language Models for Feature Engineering in Electronic Health Records

2026 · arxiv_cs
arXiv CS · Papers · License: Open Access · 2026
Open Source ↗Direct PDF ↓
neural-networks
machine learning, deep learning, neural networks

FeatEHR-LLM: Leveraging Large Language Models for Feature Engineering in Electronic Health Records

arXiv:2604.22534v1 [cs.LG] 24 Apr 2026

Hojjat Karami∗1 , David Atienza1 , Jean-Philippe Thiran1 , and Anisoara Ionescu1 1

École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland

Abstract Feature engineering for Electronic Health Records (EHR) is complicated by irregular observation intervals, variable measurement frequencies, and structural sparsity inherent to clinical time series. Existing automated methods either lack clinical domain awareness or assume clean, regularly sampled inputs, limiting their applicability to real-world EHR data. We present FeatEHR-LLM, a framework that leverages Large Language Models (LLMs) to generate clinically meaningful tabular features from irregularly sampled EHR time series. To limit patient privacy exposure, the LLM operates exclusively on dataset schemas and task descriptions rather than raw patient records. A tool-augmented generation mechanism equips the LLM with specialized routines for querying irregular temporal data, enabling it to produce executable feature-extraction code that explicitly handles uneven observation patterns and informative sparsity. FeatEHR-LLM supports both univariate and multivariate feature generation through an iterative, validation-in-the-loop pipeline. Evaluated on eight clinical prediction tasks across four ICU datasets, our framework achieves the highest mean AUROC on 7 out of 8 tasks, with improvements of up to 6 percentage points over strong baselines. Code is available at github.com/hojjatkarami/FeatEHR-LLM.

Keywords: Feature engineering; Electronic health records; Irregular time series; Large language models; Clinical prediction

1

Introduction

Electronic Health Records (EHRs) contain rich longitudinal data that capture patient health trajectories. Within these records, time series measurements, such as vital signs and laboratory results, form the backbone of clinical information. However, modeling this data is challenging because clinical time series are inherently irregularly sampled, manifesting as variable observation frequencies and event-driven measurements. The resulting gaps represent structural sparsity, with measurements recorded only when clinically indicated, rather than statistical missingness [1–3]. Despite these complexities, machine learning (ML) is increasingly leveraged to analyze EHRs for critical clinical decision support [4, 5]. To effectively utilize this complex temporal data, feature engineering remains fundamental. While modern deep learning (DL) models can process longitudinal sequences end-to-end, their widespread clinical deployment is often hindered by opacity, high data requirements, and heavy ∗

Corresponding author. [email protected]

1

computational footprints [6]. Consequently, explicit feature engineering remains critical. It is strictly necessary for interpretable, efficient tree-based models favored in clinical settings [7, 8]. Furthermore, explicitly engineered features can be injected into advanced DL architectures as static covariates, complementing learned representations to improve overall predictive performance and transparency [9, 10]. Historically, explicit feature engineering relied on costly manual collaboration with healthcare professionals, or transformation-based methods [8, 11, 12] that automate generation but lack clinical context and fundamentally struggle with irregular observation intervals. Recently, Large Language Models (LLMs) have emerged to bridge this gap. By leveraging vast domain knowledge, LLMs inject zero-shot clinical context, improving sample efficiency and generating transparent, rule-based features [13–15]. However, existing LLM-based frameworks focus primarily on static tabular data and assume clean, structured inputs. Applying them to longitudinal EHRs, with their complex temporal dependencies, context-exceeding sequence lengths, and structural sparsity, remains a significant, unaddressed challenge. To address these limitations, we introduce FeatEHR-LLM, a novel framework leveraging the clinical knowledge of LLMs to generate clinically motivated tabular features from irregularly sampled EHR time series. Crucially, FeatEHR-LLM addresses structural sparsity and variable frequencies by equipping the LLM with specialized programmatic tools to query and aggregate irregular temporal data. To reduce privacy exposure, the framework operates at the metadata level, exposing only the dataset schema and clinical task description to the LLM rather than raw patient-level records. The LLM generates executable feature-extraction code without direct access to sensitive patient records. During execution, FeatEHR-LLM transforms longitudinal measurements into engineered features that seamlessly integrate into standard ML pipelines. As illustrated in Figure 1, our framework executes both univariate and multivariate engineering to capture complex physiological interactions across multiple variables. The major contributions of this work are as follows: • We propose FeatEHR-LLM, an LLM-empowered feature generation framework designed for irregularly sampled EHR time series. By exposing only dataset schemas and clinical task descriptions rather than raw records, our approach reduces privacy exposure to the LLM. • We directly address irregular sampling via a tool-augmented generation mechanism. By equipping the LLM with specialized temporal data-reading tools, it writes feature-extraction code that explicitly handles structural sparsity and variable measurement frequencies. • We develop a multi-source feature generation mechanism integrating LLM knowledge, task context, and inter-feature interactions through univariate and multivariate engineering. This is paired with an iterative strategy and in-loop validation, allowing the LLM to adaptively refine the generated features. • We implement a robust feature-to-code translation pipeline with syntax and runtime verification. We evaluate FeatEHR-LLM on eight clinical tasks across four datasets, achieving the highest mean AUROC on 7 out of 8 tasks (improving up to 6% over baselines).

2

Related Works

In this section, we review feature engineering methods for tabular and time series data, with emphasis on approaches that generate explicit, inspectable features (including LLM-assisted pipelines). We intentionally exclude end-to-end learning-based representation methods (e.g., deep sequence encoders) 2

because they learn latent embeddings rather than explicit engineered features, and therefore belong to a different methodological paradigm and evaluation setting than the one targeted in this work. Transformation-Based Feature Engineering Transformation-based methods automate feature creation through predefined mathematical operations. For tabular data, frameworks like OpenFE [11], AutoFeat [12], and FETCH [16] successfully generate massive candidate spaces, relying on selection algorithms to filter for predictive utility. For time series, libraries extract temporal descriptors across statistical, spectral, and fractal domains (e.g., tsfresh [17], TSFEL [18], Kats [19], and Catch22 [20]). While effective at bulk generation, these methods suffer from two major limitations. First, they lack semantic awareness; they blindly apply mathematical transformations without understanding the domain context of the variables, often leading to a “curse of dimensionality” filled with redundant or clinically meaningless features. Second, they are overwhelmingly designed for regularly sampled signals. They fundamentally struggle with the highly irregular sampling rates, variable sequence lengths, and informative missingness that characterize clinical EHR time series, requiring ad-hoc imputation steps that can destroy underlying temporal patterns. LLM-Based Feature Engineering Recent work has leveraged Large Language Models (LLMs) to inject semantic domain knowledge into feature engineering. Current approaches generally formulate this as a code-generation or rule-synthesis task. Methods like CAAFE [13] and FeatLLM [21] generate human-readable transformations from dataset descriptions or few-shot examples, while others like LLM-FE [15], FeRG-LLM [22], OCTree [14], MedFeat [8], and FAMOSE [23] integrate iterative feedback mechanisms such as validation-driven refinement, evolutionary search, memory-guided selection, or ReAct-style reasoning-execution cycles to improve generated features [24]. Despite these advancements, synthesizing the current literature reveals that LLM-based feature engineering remains constrained to static, tabular data. Adapting these pipelines to time series, particularly EHR data, presents unresolved challenges. First, existing methods operate on row-wise schema descriptions and lack the temporal reasoning required to generate complex longitudinal aggregations (e.g., tracking a patient’s rolling health deterioration). Second, context window limits prevent LLMs from directly ingesting long, raw sequences of numerical time-series observations to derive patterns. Finally, existing LLM-generated code pipelines assume clean, structured inputs and are currently unequipped to autonomously write robust logic for the irregular intervals and missing values inherent to clinical data. Bridging this gap remains an open research challenge.

3

FeatEHR-LLM

3.1

Problem Formulation

We consider a supervised EHR prediction dataset D = {(xi , yi )}N i=1 , where xi = (ci , Ti ) denotes the input for patient i and yi is the target outcome (e.g., in-hospital mortality). Here, ci collects static covariates such as demographics, while Ti is an irregular multivariate time series containing physiological measurements and laboratory tests. We represent the temporal record of patient i as an ordered sequence i Ti = ((tik , {(v, xikv )}v∈Oik ))m k=1 ,

where tik ∈ R≥0 is the k-th observation time, Oik is the set of variables observed at that time, and xikv is the value of variable v. This notation makes the irregularity explicit: both the number of

3

FeatEHR- LLM 1) Feature Engineering

2) Feature Extraction For Each Patient

For Each Variable: time series Prompt

LLM

covariates

B functions

Tools

LLM Features Prompt

LLM

Executable Code

Extract Features

n questions

LLM Features For Each Question patient_id Prompt

LLM

B functions

f1

f2

...

1 2

Tools

...

Figure 1: Overview of FeatEHR-LLM. observation times mi and the set of observed variables Oik can vary across patients and across timestamps. (S) Let X denote the space of patient records xi = (ci , Ti ). For any subset of variables S, let Ti denote the restriction of Ti to measurements from variables in S. Our goal is to learn a feature map ϕ : X → Rd that converts each patient record into a fixed-length representation zi = ϕ(xi ) suitable for a downstream predictor. Let A denote the model-training procedure (LightGBM with hyperparameter search), and define hϕ = A(ϕ(Dtrain )). Given a validation split Dval , we compare feature maps through a task metric E (AUROC). We say that ϕ1 is better than ϕ2 if   E hϕ1 , ϕ1 (Dval ) > E hϕ2 , ϕ2 (Dval ) , where each hϕ is trained on the same split Dtrain . Our framework also supports combining multiple feature maps. Given K transformations ϕ1 , . . . , ϕK , we define the concatenated representation ϕcat (x) = [ϕ1 (x); ϕ2 (x); . . . ; ϕK (x)] , where [·; ·] denotes feature concatenation. This allows univariate and multivariate feature generators to contribute complementary information to the final predictor.

3.2

Univariate Feature Engineering

As illustrated in Figure 1, the univariate stage generates candidate features independently for each clinical variable. For a variable vi (e.g., heart rate or creatinine), we prompt the LLM with the task description together with lightweight metadata, including the variable name, unit, and summary statistics. The model then proposes B executable Python functions, each of which takes the time series of a single variable for one patient and returns a scalar feature. 4

These functions are intended to be patient-agnostic: once generated, the same function is applied to every patient record. For each univariate function f ∈ Funi , we denote by vf the variable used ({v })

to generate it, and evaluate it as f (Ti f ). We filter out invalid code by discarding functions that fail syntactic checks, and we retain the remaining candidates in a set Funi . The prompt may additionally include helper routines for querying irregular time series, which encourages the LLM to generate functions that are compatible with sparse and unevenly sampled measurements. Algorithm 1 summarizes the procedure, and concrete prompt and examples are provided in Figure 4. Algorithm 1 LLM-Based Univariate Feature Generation Require: Variables {v1 , . . . , vm }, task description T , LLM model, auxiliary tools, samples per prompt B Ensure: Set of valid generated feature functions Funi 1: Initialize Funi ← ∅ 2: for each variable vi in {v1 , . . . , vm } do 3: Extract metadata tuple (namei , uniti , statsi ) 4: Construct prompt pi ← CreatePrompt(T , (namei , uniti , statsi ), tools) 5: Generate B candidate functions: {f1 , . . . , fB } ← LLM(pi ) 6: for each fj in {f1 , . . . , fB } do 7: if fj is syntactically valid then 8: Funi ← Funi ∪ {fj } 9: end if 10: end for 11: end for 12: return Funi

3.3

Multivariate Feature Engineering

The multivariate stage targets interactions that cannot be captured by a single variable alone. Instead of prompting directly for code, we first ask the LLM to propose nq clinically motivated questions relevant to the prediction task, together with the subset of variables needed to answer each question. This step uses the model’s clinical prior knowledge to identify plausible cross-variable relationships before any feature code is generated. For each question-variable pair (qj , Vj ), we build a prompt containing the task description, the clinical question, and metadata for the variables in Vj . The LLM then produces B candidate Python functions that compute scalar features from the corresponding subset of the patient record. As in the univariate stage, invalid programs are discarded. The resulting collection forms the multivariate feature set Fmulti . For each multivariate function g ∈ Fmulti , we denote by Vg the variable subset (V ) associated with its originating question and evaluate it as g(Ti g ). Algorithm 2 provides a high-level view of this pipeline, and prompts and additional examples are given in Figure 5 and Figure 6.

5

Algorithm 2 LLM-Based Multivariate Feature Generation Require: Variables {v1 , . . . , vm }, task description T , LLM model, auxiliary tools, number of questions nq , samples per prompt B Ensure: Set of valid multivariate feature functions Fmulti 1: Initialize Fmulti ← ∅ nq 2: Generate clinically relevant question-variable pairs: Q = {(qj , Vj )}j=1 ← LLMGenerateQuestions(T , {(namei , uniti , statsi )}m , n ) i=1 q 3: for each pair (qj , Vj ) ∈ Q do 4: Extract metadata tuple (namek , unitk , statsk ) for each vk ∈ Vj 5: Construct prompt: pj ← CreateMultivariatePrompt(T , qj , Vj , tools) 6: Generate B candidate functions: {f1 , . . . , fB } ← LLM(pj ) 7: for each function fl ∈ {f1 , . . . , fB } do 8: if fl is syntactically valid and returns a scalar on valid input then 9: Fmulti ← Fmulti ∪ {fl } 10: end if 11: end for 12: end for 13: return Fmulti

3.4

Feature Extraction

We run Algorithms 1 and 2 for multiple rounds (nr ) to increase the diversity of the candidate function set. After generation, every valid function is executed on every patient record. For patient i, this yields the engineered representation h i h i ({v })  (V )  zi = ϕ(xi ) = f Ti f f ∈ Funi ⊕ g Ti g g ∈ Fmulti , where ⊕ denotes vector concatenation. Stacking these representations across the cohort gives the design matrix h i ⊤ Z = z1⊤ ; z2⊤ ; . . . ; zN ∈ RN ×d , which is then used to train a downstream predictor such as LightGBM. In this way, the LLM is responsible for proposing executable feature maps, while model fitting remains entirely within a standard supervised learning pipeline.

4

Experiments

4.1

Dataset

We leverage four publicly available ICU datasets encompassing eight prediction tasks. The PhysioNet 2012 Mortality Challenge (P12) comprises approximately 12,000 ICU admissions with 35 routinely measured time-series variables recorded during the first 48 h, labeled for in-hospital mortality [25]. The PhysioNet 2019 Sepsis Challenge (P19) focuses on early sepsis detection and includes 40,336 patient stays with 34 physiological time-dependent variables [26]. For MIMIC-III, we adopt the well-established preprocessing pipeline from mimic3-benchmarks [27] to extract the first 48 h of ICU data (41 variables) and predict in-hospital mortality (29,000 stays) [28]. From eICU-CRD [29], we use the FIDDLE preprocessing pipeline [30] to derive five tasks: in-hospital mortality at 48 h and 6

Table 1: Datasets details. Dataset

Size

n_ts

Prevalence(%)

P12 P19 MIMIC-III(IHM-48) EICU(IHM-48) EICU(ARF-12) EICU(Shock-12) EICU(ARF-48) EICU(Shock-48)

12k 40k 29k 77k 123k 145k 110k 136k

35 34 41 95 95 95 95 95

12.89 7.1 8.87 9.13 4.5 3.93 1.81 4.17

both acute respiratory failure (ARF) and shock prediction at 12 h and 48 h time horizons, covering between 110k and 145k ICU stays each with 95 variables. Table 1 summarizes the dataset sizes, number of time-series variables, and positive class prevalence.

4.2

Baselines

We evaluated FeatEHR-LLM against several state-of-the-art feature engineering approaches: • Baseline (BL): This baseline extracts four statistical features (mean, standard deviation, minimum, and maximum) from each time series variable. Such statistical summarization is commonly used in many EHR studies and serves as a simple yet effective reference point for comparison. • tsfresh (TF): This baseline leverages the tsfresh library [17], which automatically extracts a comprehensive set of time series features, including statistical measures, autocorrelations, and Fourier coefficients. As a well-established method for time series feature extraction, it provides a strong baseline. • OpenFE: OpenFE is a state-of-the-art feature engineering method for tabular data [11]. To adapt it for time series, it is applied to the BL features, which are first transformed into tabular format. • CAAFE and FeatLLM: These are recent LLM-based feature engineering methods. CAAFE [13] employs a context-aware pipeline to generate semantically meaningful features in the form of Python code, while FeatLLM [21] utilizes few-shot prompting to create human-readable binary feature rules from a small set of examples. Both methods are adapted for time series data by applying them to the BL features. • Zeroshot: This baseline uses the LLM in a zero-shot setting, where the LLM is asked to assign a risk score based on the task description and the time series data. Test size is set to 1000 samples to reduce inference costs in zeroshot setting. We used LightGBM [31] as the prediction model for all downstream tasks, as it is a widely used and effective model for tabular data. For each task, we use a fixed split with 20% held out as test data. The model is trained on the features generated by each method, and the performance is evaluated using Area Under the Receiver Operating Characteristic Curve (AUROC) as the primary metric. Confidence intervals were estimated via stratified bootstrap (nboot = 1000), sampling with replacement within each class to preserve class balance. Metrics were computed on each resample, and 95% confidence intervals were obtained from the empirical 2.5th and 97.5th percentiles. 7

4.3

Training Details

We use Gemini-2.0-Flash [32] as the backbone LLM, which offers a reasonable trade-off between performance and computational cost. The temperature is set to 1.0 to balance creativity and consistency. For function generation, we sample B = 5 candidate features per prompt and discard candidates with syntax errors. In multivariate feature generation, the number of questions is set to nq = 20. We further repeat both the univariate and multivariate feature generation procedures for nr = 5 rounds to increase the diversity of the generated features. For the downstream LightGBM classifier, we use grid search to tune the learning rate, number of estimators, maximum depth, and number of leaves.

5

Results

5.1

Performance Gains

Table 2: AUROC performance comparison across datasets and tasks. The best results are shown in bold, and the second-best are underlined. Subscript values indicate half-widths of the 95% bootstrap confidence intervals, i.e., (upper − lower)/2. (+) indicates that the features were added to the baseline feature set (BL).

Dataset

+FeatEHR-LLM

+FeatLLM

+CAAFE

+TF

+OpenFE

BL

85.91.9 92.11.3 94.11.0 83.80.9 78.51.2 77.51.2 84.11.5 86.81.0

84.62.0 86.01.6 90.41.4 82.11.0 76.91.2 76.21.2 78.32.0 84.51.0

84.32.0 86.31.5 90.41.4 82.21.0 77.01.3 76.11.2 78.92.0 84.61.0

85.62.0 90.11.4 92.61.2 82.01.0 78.21.2 76.51.2 84.61.6 86.00.9

85.01.9 88.61.4 91.21.3 81.71.0 76.21.4 75.91.2 77.12.0 84.41.1

83.62.0 86.41.5 91.01.3 81.80.9 76.91.3 76.41.2 78.02.1 84.71.0

P12 P19 MIMIC-III EICU(IHM-48) EICU(ARF-12) EICU(Shock-12) EICU(ARF-48) EICU(Shock-48)

Table 2 reports AUROC scores across eight benchmark tasks, comparing FeatEHR-LLM against strong baselines including OpenFE, FeatLLM, and CAAFE, all evaluated with the same base feature set (BL). FeatEHR-LLM achieves the highest mean AUROC on 7 out of 8 tasks. The gains are particularly pronounced in the P19 and MIMIC-III datasets, with improvements of 6 and 3.1 percentage points over the baseline, respectively. A similar trend appears across MIMIC-III, eICU, and PhysioNet tasks. Overall, FeatEHR-LLM is effective at synthesizing informative features from EHRs for clinical prediction tasks. Compare with zeroshot Table 3 shows the performance of our method, FeatEHR-LLM, compared to the zero-shot LLMs on three datasets: p12s, p19, and MIMIC-III. The results are presented in terms of Area Under the Receiver Operating Characteristic Curve (AUC) and F1 score. The numbers in parentheses indicate the standard deviation across five runs. Table 3: Comparison with zeroshot across 3 datasets. Test size is 1000 samples. Dataset

+FeatEHR-LLM

BL

FeatEHR-LLM

Zeroshot

P12 P19 MIMIC-III

86.91.9 92.51.2 95.60.7

84.82.1 85.51.6 93.31.0

85.82.0 92.71.3 93.61.0

73.14.1 62.26.6 88.23.2

8

5.2

Generalizability

We evaluate the generalizability of FeatEHR-LLM across three dimensions: dataset size, backbone language model, and downstream prediction architecture. Dataset Size Figure 2 shows the AUROC improvement from augmenting the baseline features (BL) with FeatEHR-LLM across varying dataset sizes (10%, 20%, 50%, and 100%). The results indicate that FeatEHR-LLM yields consistent performance improvements across all regimes, including under low-resource conditions. Notably, even with only 10% of the data, the feature augmentation provides a meaningful lift over the baseline, suggesting strong data efficiency and generalization under limited supervision.

10

Dataset EICU(ARF-12) EICU(ARF-48)

Gains in AUROC

5

EICU(IHM-48) EICU(Shock-12) EICU(Shock-48) MIMIC-III

2

P12 P19

1

0.5 1000

2

5

10k

2

5

100k

Size

Figure 2: Performance gain over baselines across different dataset sizes. The x-axis represents the dataset size, while the y-axis shows the performance gain in terms of AUROC.

Choice of LLM and Downstream Model Figure 3 reports the AUROC improvements obtained by adding FeatEHR-LLM to the baseline features (BL) across multiple downstream classifiers: LightGBM, XGBoost, and CatBoost, and across two LLMs: gemini and gpt-4o-mini. FeatEHR-LLM improves AUROC across the evaluated model settings, with the largest improvements observed for LightGBM. These results indicate compatibility of the generated features with diverse learning algorithms. Ablation Study Table 4 presents the results of our ablation study. Here, B=1 refers to generating only one feature per prompt, while B=5 means generating five features and using all of them. The best of B variant selects the single feature with the highest mutual information with the target variable from the set of B generated features. We observe that generating multiple features (B=5 ) generally improves performance over the other two methods. The variant single round indicates that we run the feature generation process only once (nr = 1) compared to the full method (multiple rounds, nr = 5). The results show that running multiple rounds of feature generation leads to better performance, suggesting that iterative refinement is beneficial for feature quality. 9

Model

LLM=gemini

10 5 2 1 0.5

catboost lightgbm xgboost

0.2 LLM=4o-mini

10 5 2 1 0.5 0.2

8) 2) 8) 2) 8) III F-1 RF-4 HM-4 ock-1 ock-4 MICR I A A M U( ICU( ICU(I U(Sh U(Sh EIC E E EIC EIC

2

P1

9

P1

Dataset

Figure 3: Performance gain over baselines across different dataset sizes. The x-axis represents the dataset size, while the y-axis shows the performance gain in terms of AUROC. FeatEHR-LLM achieves the highest mean AUROC among the listed ablation variants in 7 out of 8 tasks (with a tie in one task). The results indicate that removing the univariate feature generation step (w/o uni) leads to a larger performance drop than removing the multivariate step (w/o multi), suggesting that univariate feature generation contributes more strongly to overall performance in this setup. Table 4: Ablation study. AUROC performance comparison across datasets and tasks. The best results are shown in bold, and the second-best are underlined. Subscript values indicate half-widths of the 95% bootstrap confidence intervals, i.e., (upper − lower)/2. A (+) indicates that features were added to the baseline feature set (BL). Dataset P12 P19 MIMIC-III EICU(IHM-48) EICU(ARF-12) EICU(Shock-12) EICU(ARF-48) EICU(Shock-48)

6

FeatEHR-LLM (B=5)

best of B

B=1

single round

w/o multi

w/o uni

85.71.8 92.51.2 92.91.1 83.40.9 74.61.3 74.71.4 82.51.7 85.61.0

85.51.9 92.11.2 92.21.2 82.80.9 74.01.3 73.11.3 82.91.7 84.11.1

82.82.1 85.31.6 89.81.5 81.61.0 68.61.4 70.61.3 73.12.2 81.81.2

82.92.1 90.91.3 91.81.2 82.30.9 72.01.3 73.01.3 81.51.6 82.81.1

84.82.0 92.41.2 92.51.1 82.60.9 74.51.3 74.01.3 82.71.7 85.61.0

83.41.9 83.81.5 90.91.3 81.11.0 69.01.4 70.51.4 73.72.3 80.11.3

Discussion

Scope of irregularity The irregularity addressed by FeatEHR-LLM is the observational irregularity typical of EHR time series: variables are measured at nonuniform times, different variables are 10

observed at different timestamps, and the number of recorded observations varies across patients even within a fixed task-specific horizon [33, 34]. Our tool-augmented feature generation is designed to reason over these uneven observation patterns directly. However, the framework does not explicitly model statistical missingness mechanisms such as MCAR, MAR, or MNAR, nor does it infer why a clinician chose not to measure a variable [35, 36]. This distinction is important because, in our setting, absent measurements are treated primarily as structural sparsity in the observation process rather than as separately parameterized missing-data processes. Redundant features Generating multiple candidate feature extraction scripts per variable or clinical question yields a set of related features that often differ only slightly in thresholds or aggregation logic. Although this introduces redundancy, our ablation results suggest that these variants are beneficial rather than purely superfluous. In tree-based predictors such as gradient boosted decision trees, correlated features can still contribute complementary signal because they induce different partitions of the feature space and enable alternative splitting rules during training. Consequently, multiple threshold variants may capture distinct regions of the data distribution and facilitate the discovery of informative interactions with other variables. This behavior is consistent with prior work showing that tree ensembles distribute predictive importance across groups of correlated variables and can flexibly select among them when constructing decision trees [37]. More broadly, the machine learning literature has shown that diversity in feature representations can improve predictive performance by providing complementary views of the same underlying signal, an idea closely related to attribute bagging and representation ensembles [38]. Empirical studies of feature selection in tree ensembles further demonstrate that predictive importance is often spread across correlated feature groups, implying that removing such features too aggressively may eliminate useful alternative decision boundaries [39]. Together, these findings suggest that LLMgenerated feature variants can act as complementary representations of clinical signals, increasing the representational flexibility available to the downstream model. Computational cost Our framework increases computation during feature generation and extraction because it relies on multiple rounds and multiple candidate programs per prompt. The number of LLM calls scales with the number of variables, the number of multivariate questions, the number of rounds, and the number of samples per prompt. Nevertheless, compared with zero-shot or embedding-based approaches that require serializing each patient’s time series into text, our method is substantially more efficient at inference time from the LLM perspective. The LLM only receives metadata and the task description, which keeps the prompt short and makes generation independent of the number of patients. The main cost is therefore concentrated in feature proposal rather than patient-level prompting. Clinical interpretability A practical advantage of our approach is that the generated features are expressed as explicit, executable rules rather than opaque latent representations. This makes them easier to inspect than features produced by end-to-end representation learning methods [40]. However, interpretability should not be overstated: understandable code does not automatically imply clinical validity [41]. Moreover, because the features are proposed by an LLM, generation can still be affected by hallucination, and this risk may increase at higher sampling temperatures that favor diversity and creativity [42–44]. In the clinical setting, such plausible but incorrect feature definitions are particularly concerning because they may encode unsafe assumptions while remaining superficially interpretable [45]. For this reason, generated features should be validated empirically and reviewed by clinicians or domain experts before use, especially when they may 11

influence high-stakes decisions [42].

7

Conclusion

We presented FeatEHR-LLM, a framework that leverages LLMs to engineer clinically motivated tabular features from irregularly sampled EHR time series. By operating exclusively on dataset metadata rather than raw records, the framework limits patient privacy exposure while producing executable feature-extraction code through a tool-augmented mechanism designed to handle structural sparsity and variable observation frequencies. Multi-round univariate and multivariate generation, coupled with in-loop syntax and runtime validation, yields diverse and robust feature sets. Across eight clinical prediction tasks on four ICU datasets, FeatEHR-LLM achieves the highest mean AUROC on 7 out of 8 tasks, with gains of up to 6 percentage points over baselines. Generated features remain fully interpretable as executable code and integrate seamlessly into standard ML pipelines. Key limitations include the risk of LLM hallucinations in generated feature logic and the absence of explicit missing-data mechanism modeling, both of which warrant expert review before clinical deployment. Future work could extend the framework to additional EHR modalities and incorporate automated clinical validation feedback.

Acknowledgments This work was supported by the RealCare project, which has received funding from the European Union and by the Swiss State Secretariat for Education, Research and Innovation (SERI). Additionally, we would like to thank the EPFL IC Cluster for providing the computational resources used in this work.

A

Prompts and Examples

References [1] Marzyeh Ghassemi, Tristan Naumann, Peter Schulam, Andrew L. Beam, Irene Y. Chen, and Rajesh Ranganath. A Review of Challenges and Opportunities in Machine Learning for Health. AMIA Summits on Translational Science Proceedings, 2020:191–200, May 2020. ISSN 2153-4063. [2] Yizhao Zhou, Jiasheng Shi, Ronen Stein, Xiaokang Liu, Robert N Baldassano, Christopher B Forrest, Yong Chen, and Jing Huang. Missing data matter: An empirical evaluation of the impacts of missing EHR data in comparative effectiveness research. Journal of the American Medical Informatics Association, 30(7):1246–1256, July 2023. ISSN 1527-974X. doi: 10.1093/ jamia/ocad066. [3] Emily Getzen, Lyle Ungar, Danielle Mowery, Xiaoqian Jiang, and Qi Long. Mining for equitable health: Assessing the impact of missing data in electronic health records. Journal of Biomedical Informatics, 139:104269, March 2023. ISSN 1532-0464. doi: 10.1016/j.jbi.2022.104269. [4] Zhao Chen, Ning Liang, Haili Zhang, Huizhen Li, Yijiu Yang, Xingyu Zong, Yaxin Chen, Yanping Wang, and Nannan Shi. Harnessing the power of clinical decision support systems: Challenges and opportunities. Open Heart, 10(2), November 2023. ISSN 2053-3624. doi: 10.1136/openhrt-2023-002432.

12

[5] Jiancheng Ye, Donna Woods, Neil Jordan, and Justin Starren. The role of artificial intelligence for the application of integrating electronic health records and patient-generated data in clinical decision support. AMIA Summits on Translational Science Proceedings, 2024:459–467, May 2024. ISSN 2153-4063. [6] Helen Coupland, Neil Scheidwasser, Alexandros Katsiferis, Megan Davies, Seth Flaxman, Naja Hulvej Rod, Swapnil Mishra, Samir Bhatt, and H. Juliette T. Unwin. Exploring the potential and limitations of deep learning and explainable AI for longitudinal life course analysis. BMC Public Health, 25(1):1520, April 2025. ISSN 1471-2458. doi: 10.1186/s12889-025-22705-4. [7] Mehak Arora, Hassan Mortagy, Nathan Dwarshuis, Jeffrey Wang, Philip Yang, Andre L Holder, Swati Gupta, and Rishikesan Kamaleswaran. Improving clinical decision support through interpretable machine learning and error handling in electronic health records. Journal of the American Medical Informatics Association, 33(1):123–132, January 2026. ISSN 1527-974X. doi: 10.1093/jamia/ocaf058. [8] Zizheng Zhang, Yiming Li, Justin Xu, Jinyu Wang, Rui Wang, Lei Song, Jiang Bian, David W. Eyre, and Jingjing Fu. MedFeat: Model-Aware and Explainability-Driven Feature Engineering with LLMs for Clinical Tabular Prediction, February 2026. [9] Bryan Lim and Stefan Zohren. Time-series forecasting with deep learning: A survey. Philosophical Transactions. Series A, Mathematical, Physical, and Engineering Sciences, 379(2194):20200209, April 2021. ISSN 1471-2962. doi: 10.1098/rsta.2020.0209. [10] Gaoyong Lu, Yang Ou, Zhihong Wang, Yingnan Qu, Yingsheng Xia, Dibin Tang, Igor Kotenko, and Wei Li. A Survey of Deep Learning for Time Series Forecasting: Theories, Datasets, and State-of-the-Art Techniques. Computers, Materials & Continua, 85(2):2403–2441, 2025. ISSN 1546-2218, 1546-2226. doi: 10.32604/cmc.2025.068024. [11] Tianping Zhang, Zheyu Zhang, Zhiyuan Fan, Haoyan Luo, Fengyuan Liu, Qian Liu, Wei Cao, and Jian Li. OpenFE: Automated Feature Generation with Expert-level Performance, June 2023. [12] Franziska Horn, Robert Pack, and Michael Rieger. The autofeat Python Library for Automated Feature Engineering and Selection, February 2020. [13] Noah Hollmann, Samuel Müller, and Frank Hutter. Large Language Models for Automated Data Science: Introducing CAAFE for Context-Aware Automated Feature Engineering, September 2023. [14] Jaehyun Nam, Kyuyoung Kim, Seunghyuk Oh, Jihoon Tack, Jaehyung Kim, and Jinwoo Shin. Optimized Feature Generation for Tabular Data via LLMs with Decision Tree Reasoning, November 2024. [15] Nikhil Abhyankar, Parshin Shojaee, and Chandan K. Reddy. LLM-FE: Automated Feature Engineering for Tabular Data with LLMs as Evolutionary Optimizers, March 2025. [16] Liyao Li, Haobo Wang, Liangyu Zha, Qingyi Huang, Sai Wu, Gang Chen, and Junbo Zhao. Learning a Data-Driven Policy Network for Pre-Training Automated Feature Engineering. In The Eleventh International Conference on Learning Representations, September 2022.

13

[17] Maximilian Christ, Nils Braun, Julius Neuffer, and Andreas W. Kempa-Liehr. Time Series FeatuRe Extraction on basis of Scalable Hypothesis tests (tsfresh – A Python package). Neurocomputing, 307:72–77, September 2018. ISSN 0925-2312. doi: 10.1016/j.neucom.2018.03.067. [18] Jonas Van Der Donckt, Jeroen Van Der Donckt, Emiel Deprost, and Sofie Van Hoecke. Tsflex: Flexible time series processing & feature extraction, December 2021. [19] Xiaodong Jiang, Sudeep Srivastava, Sourav Chatterjee, Yang Yu, Jeffrey Handler, Peiyi Zhang, Rohan Bopardikar, Dawei Li, Yanjun Lin, Uttam Thakore, Michael Brundage, Ginger Holt, Caner Komurlu, Rakshita Nagalla, Zhichao Wang, Hechao Sun, Peng Gao, Wei Cheung, Jun Gao, Qi Wang, Marius Guerard, Morteza Kazemi, Yulin Chen, Chong Zhou, Sean Lee, Nikolay Laptev, Tihamér Levendovszky, Jake Taylor, Huijun Qian, Jian Zhang, Aida Shoydokova, Trisha Singh, Chengjun Zhu, Zeynep Baz, Christoph Bergmeir, Di Yu, Ahmet Koylan, Kun Jiang, Ploy Temiyasathit, and Emre Yurtbay. Kats, March 2022. [20] Carl H. Lubba, Sarab S. Sethi, Philip Knaute, Simon R. Schultz, Ben D. Fulcher, and Nick S. Jones. Catch22: CAnonical Time-series CHaracteristics, January 2019. [21] Sungwon Han, Jinsung Yoon, Sercan O. Arik, and Tomas Pfister. Large Language Models Can Automatically Engineer Features for Few-Shot Tabular Learning, May 2024. [22] Jeonghyun Ko, Gyeongyun Park, Donghoon Lee, and Kyunam Lee. FeRG-LLM : Feature Engineering by Reason Generation Large Language Models, March 2025. [23] Keith Burghardt, Jienan Liu, Sadman Sakib, Yuning Hao, and Bo Li. FAMOSE: A ReAct Approach to Automated Feature Discovery, February 2026. [24] Shunyu Yao, Jeffrey Zhao, Dian Yu, Nan Du, Izhak Shafran, Karthik Narasimhan, and Yuan Cao. ReAct: Synergizing Reasoning and Acting in Language Models, March 2023. [25] Ikaro Silva, George Moody, Daniel J Scott, Leo A Celi, and Roger G Mark. Predicting InHospital Mortality of ICU Patients: The PhysioNet/Computing in Cardiology Challenge 2012. page 4. [26] Matthew A. Reyna, Christopher S. Josef, Russell Jeter, Supreeth P. Shashikumar, M. Brandon Westover, Shamim Nemati, Gari D. Clifford, and Ashish Sharma. Early Prediction of Sepsis From Clinical Data: The PhysioNet/Computing in Cardiology Challenge 2019. Critical Care Medicine, 48(2):210–217, February 2020. ISSN 0090-3493. doi: 10.1097/CCM.0000000000004145. [27] Shirly Wang, Matthew B. A. McDermott, Geeticka Chauhan, Marzyeh Ghassemi, Michael C. Hughes, and Tristan Naumann. MIMIC-Extract: A data extraction, preprocessing, and representation pipeline for MIMIC-III. In Proceedings of the ACM Conference on Health, Inference, and Learning, pages 222–235, Toronto Ontario Canada, April 2020. ACM. ISBN 978-1-4503-7046-2. doi: 10.1145/3368555.3384469. [28] Alistair E. W. Johnson, Tom J. Pollard, Lu Shen, Li-wei H. Lehman, Mengling Feng, Mohammad Ghassemi, Benjamin Moody, Peter Szolovits, Leo Anthony Celi, and Roger G. Mark. MIMIC-III, a freely accessible critical care database. Scientific Data, 3(1):160035, May 2016. ISSN 2052-4463. doi: 10.1038/sdata.2016.35. [29] Tom J. Pollard, Alistair E. W. Johnson, Jesse D. Raffa, Leo A. Celi, Roger G. Mark, and Omar Badawi. The eICU Collaborative Research Database, a freely available multi-center database 14

for critical care research. Scientific Data, 5(1):180178, September 2018. ISSN 2052-4463. doi: 10.1038/sdata.2018.178. [30] Shengpu Tang, Parmida Davarmanesh, Yanmeng Song, Danai Koutra, Michael W Sjoding, and Jenna Wiens. Democratizing EHR analyses with FIDDLE: A flexible data-driven preprocessing pipeline for structured clinical data. Journal of the American Medical Informatics Association, 27(12):1921–1934, December 2020. ISSN 1527-974X. doi: 10.1093/jamia/ocaa139. [31] Guolin Ke, Qi Meng, Thomas Finley, Taifeng Wang, Wei Chen, Weidong Ma, Qiwei Ye, and Tie-Yan Liu. LightGBM: A Highly Efficient Gradient Boosting Decision Tree. In Advances in Neural Information Processing Systems, volume 30. Curran Associates, Inc., 2017. [32] Gemini 2.5 Flash. https://deepmind.google/models/gemini/flash/. [33] Zachary C. Lipton, David C. Kale, Charles Elkan, and Randall Wetzel. Learning to Diagnose with LSTM Recurrent Neural Networks, March 2017. [34] Satya Narayan Shukla and Benjamin M. Marlin. Multi-Time Attention Networks for Irregularly Sampled Time Series, June 2021. [35] Roderick J. A. Little and Donald B. Rubin. Statistical Analysis with Missing Data. John Wiley & Sons, April 2019. ISBN 978-0-470-52679-8. [36] Denis Agniel, Isaac S. Kohane, and Griffin M. Weber. Biases in electronic health record data due to processes within the healthcare system: Retrospective observational study. BMJ, 361: k1479, April 2018. ISSN 1756-1833. doi: 10.1136/bmj.k1479. [37] Scott M. Lundberg, Gabriel G. Erion, and Su-In Lee. Consistent Individualized Feature Attribution for Tree Ensembles, March 2019. [38] Robert Bryll, Ricardo Gutierrez-Osuna, and Francis Quek. Attribute bagging: Improving accuracy of classifier ensembles by using random feature subsets. Pattern Recognition, 36(6): 1291–1302, June 2003. ISSN 0031-3203. doi: 10.1016/S0031-3203(02)00121-8. [39] Brian Liu, Miaolan Xie, and Madeleine Udell. ControlBurn: Feature Selection by Sparse Forests. In Proceedings of the 27th ACM SIGKDD Conference on Knowledge Discovery & Data Mining, pages 1045–1054, August 2021. doi: 10.1145/3447548.3467387. [40] Maria Frasca, Davide La Torre, Gabriella Pravettoni, and Ilaria Cutica. Explainable and interpretable artificial intelligence in medicine: A systematic bibliometric review. Discover Artificial Intelligence, 4(1):15, February 2024. ISSN 2731-0809. doi: 10.1007/s44163-024-00114-7. [41] Radwa Elshawi, Mouaz H. Al-Mallah, and Sherif Sakr. On the interpretability of machine learning-based model for predicting hypertension. BMC Medical Informatics and Decision Making, 19(1):146, July 2019. ISSN 1472-6947. doi: 10.1186/s12911-019-0874-0. [42] Juexiao Zhou, Haoyang Li, Siyuan Chen, Zhangtianyi Chen, Zhongyi Han, and Xin Gao. Large language models in biomedicine and healthcare. npj Artificial Intelligence, 1(1):44, December 2025. ISSN 3005-1460. doi: 10.1038/s44387-025-00047-1. [43] Yubin Kim, Hyewon Jeong, Shan Chen, Shuyue Stella Li, Chanwoo Park, Mingyu Lu, Kumail Alhamoud, Jimin Mun, Cristina Grau, Minseok Jung, Rodrigo Gameiro, Lizhou Fan, Eugene Park, Tristan Lin, Joonsik Yoon, Wonjin Yoon, Maarten Sap, Yulia Tsvetkov, Paul Liang, Xuhai 15

Xu, Xin Liu, Chunjong Park, Hyeonhoon Lee, Hae Won Park, Daniel McDuff, Samir Tulebaev, and Cynthia Breazeal. Medical Hallucinations in Foundation Models and Their Impact on Healthcare, November 2025. [44] Dimitri Roustan and François Bastardot. The Clinicians’ Guide to Large Language Models: A General Perspective With a Focus on Hallucinations. Interactive Journal of Medical Research, 14(1):e59823, January 2025. doi: 10.2196/59823. [45] Lisa Pilgram, Samer El Kababji, Dan Liu, and Khaled El Emam. Magnitude and Impact of Hallucinations in Tabular Synthetic Health Data on Prognostic Machine Learning Models: Validation Study. Journal of Medical Internet Research, 27(1):e77893, August 2025. doi: 10.2196/77893.

16

### Your t as k i s t o { TASK} . You ar e gi v en ac c es s t o t he pat i ent ' s * { v ar _name} * t i me s er i es dat a and t he uni t i s ( { v ar _uni t } ) . Des i gn * { B} * * * c l i ni c al l y r el ev ant * * f unc t i on( s ) f or t he v ar i abl e bel ow: * * Var i abl e: * * { pr ompt _v ar i abl e} ### Requi r ement s : <{ i ns t r uc t i ons } > - The f unc t i ons mus t * * go bey ond bas i c s t at i s t i c s * * ( e. g. , av oi d mean, mi n, max , medi an, s t d, v ar i anc e) . - Eac h f unc t i on s houl d r ef l ec t * * c l i ni c al r eas oni ng* * and pr ov i de i ns i ght s r el ev ant t o t he t as k . - For * * eac h f unc t i on* * , pr ov i de t he f ol l owi ng: 1. * * Cl i ni c al Rat i onal e* * : Ex pl ai n why t hi s ques t i on/ f unc t i on i s c l i ni c al l y r el ev ant . 2. * * Py t hon Code* * : - Func t i on names s houl d be s nak e_c as e and c l ear l y r ef l ec t t he c l i ni c al l ogi c t hey c apt ur e ( e. g. , has _hy pot ens i on_epi s ode, number _of _s pi k es _abov e_t hr es hol d) . - * * Mus t * * Ret ur n a * * numer i c al * * v al ue ( f l oat , i nt , or bool ean) . Nev er r et ur n s t r i ng, NaNs , or None. I f no v al i d meas ur ement s ar e av ai l abl e, t he f unc t i on mus t r et ur n a def aul t v al ue ( e. g. , 0 or Fal s e) . - Handl e * * mi s s i ng v al ues * * appr opr i at el y . - Cons i der t hat out put mi ght be an empt y l i s t i n t he c as e of no meas ur ement s . Pl eas e handl e - Us e bac k s l as hes ( ` \ \ ` ) t o br eak l ong l i nes . - Us e t he pr ov i ded hel per f unc t i on ` get _al l _meas ur ement s ` t o ex t r ac t t i me s er i es dat a. --### Hel per Func t i on ( al r eady pr ov i ded ? do NOT r edef i ne) : { t ool s } --### Func t i on Templ at e ( y ou mus t f ol l ow t hi s s t r uc t ur e) : { f unc t i on_t empl at e}

def ur i ne_out put _v ar i abi l i t y _3( X: pd. Dat aFr ame) - > f l oat : """ Des c r i pt i on: Cl i ni c al f eat ur e f or * Ur i ne* ( mL/ hr ) Ar gs : - X: Dat aFr ame wi t h t i me s er i es dat a. Ex pl anat i on: Hi gh v ar i abi l i t y i n ur i ne out put may i ndi c at e uns t abl e r enal f unc t i on or f l uc t uat i ng f l ui d s t at us . Thi s f unc t i on c al c ul at es t he av er age abs ol ut e c hange i n ur i ne out put bet ween c ons ec ut i v e meas ur ement s , pr ov i di ng a meas ur e of ur i ne out put l abi l i t y . I t r ef l ec t s t he degr ee of f l uc t uat i on i n ur i ne pr oduc t i on. Ret ur ns : A numer i c al v al ue ( f l oat , i nt , or bool ean) """ v ar i abl e = ' Ur i ne' meas ur ement s = get _al l _meas ur ement s ( X, v ar i abl e) i f not meas ur ement s or l en( meas ur ement s ) < 2: r et ur n 0. 0 t ot al _c hange = 0. 0 f or i i n r ange( l en( meas ur ement s ) - 1) : t ot al _c hange += abs( meas ur ement s [ i +1] [ ' v al ue' ] - meas ur ement s [ i ] [ ' v al ue' ] ) av er age_c hange = t ot al _c hange / ( l en( meas ur ement s ) - 1) r et ur n av er age_c hange

Figure 4: Univariate feature engineering step. Top: prompt used to generate candidate univariate feature functions. Bottom: example of a generated function for urine.

17

Your t as k i s t o { TASK} . ## Av ai l abl e Var i abl es : The dat as et i nc l udes t he f ol l owi ng v ar i abl es , eac h wi t h i t s c or r es pondi ng uni t : { v ar i abl es _des c r i pt i on} ## Tas k : You need t o f or mul at e * * { n_q} hi gh- l ev el c l i ni c al f eat ur es * * bas ed on t he dat as et . Eac h f eat ur e s houl d as s es s t he pat i ent ' s ov er al l c ondi t i on and r i s k of c ompl i c at i ons . The r equi r ement s ar e: - * * Hi gh- Lev el Foc us : * * - Eac h f eat ur e s houl d i nv ol v e mul t i pl e v ar i abl es . They c oul d be i n t hr ee l ev el s : - Or gan l ev el s uc h as l i v er , k i dney , et c . - Sy s t em l ev el s uc h as c ar di ov as c ul ar , r es pi r at or y , et c . - Di s eas e l ev el s uc h as s eps i s , pneumoni a, et c . - Do not f oc us on a s i ngl e v ar i abl e or di r ec t l y ment i on s pec i f i c v ar i abl es i n t he f eat ur e. - Ens ur e t hat t he f eat ur es al i gn wi t h c r i t i c al dec i s i on- mak i ng i n an I CU s et t i ng. - * * For mat of t he f eat ur e: * * - Her e ar e s ome t empl at es : - " What i s t he r i s k of . . . ?" - " How s ev er e i s t he c ompl i c at i on of . . . ?" - " How wel l i s . . . ?" - The ans wer c an be: - Numer i c al : an * * i nt eger bet ween 0 and 10* * , e. g. r epr es ent i ng t he s ev er i t y or r i s k l ev el . - Bool ean ( * * 0* * f or ' No'

and * * 1* * f or ' Yes ' )

- * * For eac h f eat ur e, pr ov i de: * * 1. * * The f eat ur e di s c r i pt i on. * * 2. * * Lev el i n t he hi er ar c hy * * ( or gan, s y s t em, di s eas e) 3. * * Cl i ni c al r el ev anc e f or t hi s t as k * * 4. * * Whi c h v ar i abl es c oul d be us ed t o ans wer i t ?* * Mak e s ur e t hat t he v ar i abl es ar e i n t he s pec i f i ed l i st . 5. * * Ans wer s pac e* *

[ { " f eat ur e" : " How wel l i s t he pat i ent c ompens at i ng r es pi r at or y ?" , " v ar i abl es " : " [ ' Res p' , ' PaCO2' , ' pH' ] " , " c l i ni c al _r el ev anc e" : " The abi l i t y t o c ompens at e r es pi r at or y i s c r uc i al f or mai nt ai ni ng ac i d- bas e bal anc e dur i ng s eps i s . Fai l ur e t o c ompens at e i ndi c at es a hi gher r i s k of s hoc k . " }, { " f eat ur e" : " How i mpai r ed i s t he r es pi r at or y f unc t i on?" , " v ar i abl es " : " [ ' O2Sat ' , ' PaCO2' , ' pH' , ' Res p' , ' Fi O2' , ' SaO2' ] " , " c l i ni c al _r el ev anc e" : " Res pi r at or y dy s f unc t i on c an l ead t o or ex ac er bat e s eps i s s hoc k due t o i nadequat e ox y gen del i v er y and ac i d- bas e i mbal anc es . " }, { " f eat ur e" : " How c ompr omi s ed i s t he mi c r ov as c ul ar per f us i on?" , " v ar i abl es " : " [ ' HR' , ' SBP' , ' DBP' , ' MAP' , ' Lac t at e' ] " , " c l i ni c al _r el ev anc e" : " I mpai r ed mi c r ov as c ul ar per f us i on i s a c ent r al f eat ur e of s eps i s s hoc k , l eadi ng t o i nadequat e ox y gen and nut r i ent del i v er y t o t i s s ues . " } ]

Figure 5: Multivariate feature engineering step. Top: prompt used to generate clinically relevant questions. Bottom: three example questions for the P12 dataset. Each question is paired with the subset of variables that the LLM deems necessary to answer it, along with its clinical relevance to the specified task.

18

Question: How severe is the patient' s metabolic dysfunction? Variables: [' Glucose', ' Lactate' ] Clinical Relevance: Assesses the severity of metabolic dysfunction, including hyperglycemia or hypoglycemia and lactic acidosis. High scores suggest severe dysfunction.

def as s es s _met abol i c _dy s f unc t i on_3( X: pd. Dat aFr ame, c ov ar i at es : di c t ) - > i nt : """ Var i abl es ( uni t ) t o us e: [ ' Gl uc os e' ] ( uni t : mg/ dL) , [ ' Lac t at e' ] ( uni t : mmol / L) Ar gs : - X: Dat aFr ame wi t h t i me s er i es dat a. - c ov ar i at es ( di c t ) : Di c t i onar y of c ov ar i at es f or t he pat i ent : - ' age' : <pat i ent age> - ' gender ' : <1 f or Mal e, 0 f or Femal e> Ex pl anat i on of l ogi c : The s ev er i t y of met abol i c dy s f unc t i on i s as s es s ed bas ed on gl uc os e and l ac t at e l ev el s . El ev at ed gl uc os e l ev el s ( hy per gl y c emi a) c an i ndi c at e i ns ul i n r es i s t anc e or di abet es , c ommon i n c r i t i c al l y i l l pat i ent s and as s oc i at ed wi t h poor out c omes . Hi gh l ac t at e l ev el s ar e a mar k er of anaer obi c met abol i s m and t i s s ue hy pox i a, r ef l ec t i ng i nadequat e ox y gen del i v er y . The s c or i ng s y s t em c ombi nes t hes e t wo f ac t or s t o r ef l ec t t he ov er al l met abol i c s t r es s . Spec i f i c al l y , v er y hi gh l ac t at e l ev el s ( >4 mmol / L) wi l l l ead t o a hi gh met abol i c dy s f unc t i on s c or e, wher eas ex t r emel y hi gh gl uc os e ( >200 mg/ dL) wi l l al s o l ead t o a hi gh s c or e. Moder at e el ev at i ons i n bot h l ead t o an i nt er medi at e s c or e. The r ul es al s o t ak e i nt o ac c ount i f t he gl uc os e i s out l i er pr one. Ret ur ns : <An i nt eger bet ween 0 and 10> """ i mpor t pandas as pd # 1. Ex t r ac t v ar i abl es f r om Dat aFr ame X us i ng ' get _al l _meas ur ement s ' gl uc os e_meas ur ement s = get _al l _meas ur ement s ( X, ' Gl uc os e' ) l ac t at e_meas ur ement s = get _al l _meas ur ement s ( X, ' Lac t at e' ) # I ni t i al i z e s c or es gl uc os e_s c or e = 0 l ac t at e_s c or e = 0 ov er al l _s c or e = 0 # Chec k i f gl uc os e meas ur ement s ar e av ai l abl e i f gl uc os e_meas ur ement s : # Get t he l as t gl uc os e v al ue l as t _gl uc os e = gl uc os e_meas ur ement s [ - 1] [ ' v al ue' ] # Rul e 1: As s es s gl uc os e l ev el i f l as t _gl uc os e > 200: gl uc os e_s c or e = 5 # Hi gh gl uc os e l ev el el i f l as t _gl uc os e > 150: gl uc os e_s c or e = 3 # Moder at el y hi gh gl uc os e # Rul e 2: Chec k f or out l i er pr one gl uc os e i f i s _v ar i abl e_out l i er _pr one( X, ' Gl uc os e' ) : gl uc os e_s c or e += 2 # Addi t i onal penal t y f or uns t abl e gl uc os e # Chec k i f l ac t at e meas ur ement s ar e av ai l abl e i f l ac t at e_meas ur ement s : # Get t he l as t l ac t at e v al ue l as t _l ac t at e = l ac t at e_meas ur ement s [ - 1] [ ' v al ue' ] # Rul e 3: As s es s l ac t at e l ev el i f l as t _l ac t at e > 4: l ac t at e_s c or e = 5 # Hi gh l ac t at e l ev el el i f l as t _l ac t at e > 2: l ac t at e_s c or e = 3 # Moder at el y hi gh l ac t at e # Combi ne s c or es ov er al l _s c or e = gl uc os e_s c or e + l ac t at e_s c or e # Cap t he ov er al l s c or e at 10 ov er al l _s c or e = mi n( ov er al l _s c or e, 10) r et ur n i nt ( ov er al l _s c or e)

Figure 6: Multivariate feature engineering example. Top: generated question and required variables. Bottom: example of a generated feature function that answers the question. The function explains its logic in the docstring: it first reads the measurements using the specified tool and then applies the corresponding decision logic.

19

def get _al l _meas ur ement s( df : pd. Dat aFr ame, c ol _name: s t r ) - > Li s t [ di c t ] : """ Ex t r ac t s meas ur ement s f r om a s pec i f i c c ol umn i n t he dat af r ame. Ret ur ns a l i s t of di c t i onar i es c ont ai ni ng ' t i me' and ' v al ue' . ex ampl e out put : [ { ' t i me' : 0. 0, ' v al ue' : 0. 0} , { ' t i me' : 1. 0, ' v al ue' : 1. 0} , . . . ] i f no meas ur ement s t he out put i s [ ] """

def i s _v ar i abl e_uns t abl e( df : pd. Dat aFr ame, c ol _name: s t r ) - > bool : """ Det er mi nes i f a v ar i abl e i s f l uc t uat i ng s i gni f i c ant l y ov er t i me. Ret ur ns Tr ue i f t he s t andar d dev i at i on i s hi gh r el at i v e t o t he mean. Cl i ni c al I mpor t anc e: Det ec t s i ns t abi l i t y i n v i t al s i gns , s uc h as f l uc t uat i ng bl ood pr es s ur e i ndi c at i ng s hoc k . """

def i s _v ar i abl e_i nc r eas i ng( df : pd. Dat aFr ame, c ol _name: s t r ) - > bool : """ Chec k s i f a v ar i abl e s hows an ov er al l i nc r eas i ng t r end. Ret ur ns Tr ue i f t he v ar i abl e i s i nc r eas i ng ov er t i me, ot her wi s e Fal s e. Cl i ni c al I mpor t anc e: I dent i f i es wor s eni ng t r ends , s uc h as r i s i ng l ac t at e i ndi c at i ng poor per f us i on. """

def c ount _mi s s i ng_i nt er v al s( df : pd. Dat aFr ame, c ol _name: s t r ) - > i nt : """ Count s t he number of mi s s i ng meas ur ement i nt er v al s . Ret ur ns t he number of gaps i n t he t i me s er i es wher e v al ues ar e mi s s i ng. Cl i ni c al I mpor t anc e: Lar ge gaps i n meas ur ement s may i ndi c at e poor moni t or i ng. """

def i s _v ar i abl e_dec r eas i ng( df : pd. Dat aFr ame, c ol _name: s t r ) - > bool : """ Chec k s i f a v ar i abl e s hows an ov er al l dec r eas i ng t r end. Ret ur ns Tr ue i f t he v ar i abl e i s dec r eas i ng ov er t i me, ot her wi s e Fal s e. Cl i ni c al I mpor t anc e: I dent i f i es i mpr ov i ng t r ends , s uc h as dec r eas i ng CRP i ndi c at i ng r educ ed i nf l ammat i on. """

def i s _v ar i abl e_out l i er _pr one( df : pd. Dat aFr ame, c ol _name: s t r ) - > bool : """ Chec k s i f a v ar i abl e has ex t r eme out l i er s us i ng t he I QR met hod. Ret ur ns Tr ue i f t her e ar e s i gni f i c ant out l i er s . Cl i ni c al I mpor t anc e: I dent i f i es er r at i c v al ues , s uc h as s udden s pi k es i n gl uc os e l ev el s . """

Figure 7: Tool functions available to the LLM. Univariate feature engineering uses only get_all_measurements, whereas multivariate feature engineering uses the full tool set.

20

Record · ID 134553 · SHA-256 18dac84a7f277b04
Retrieved via Conceptio — every document is proof-bundled with source, license, and retrieval metadata.