Blog · Clinical machine learning

How to prevent data leakage in clinical AI

Leakage is one of the fastest ways an EHR risk prediction study looks strong in a notebook and fails under honest temporal evaluation. This guide is for research and teaching—not bedside care.

What “leakage-safe AI” means for EHR data

In longitudinal electronic health records, features must respect an index time (when the prediction is made) and a horizon (what you are predicting afterward). Using labs, notes, or codes from after the index time inflates AUROC and destroys external validity.

Practical checklist

  1. Define index and horizon in a task spec before feature engineering.
  2. Use patient-level or temporal splits — never random row splits on longitudinal tables.
  3. Run a leakage audit that checks post-index features and split integrity.
  4. Report calibration (Brier, ECE), not only discrimination.
  5. Document limitations — synthetic demos ≠ clinical performance.

How the EHR Risk Framework helps

The open-source EHR Risk Framework is a workbench for leakage-aware, calibrated, explainable EHR risk modeling: task YAML, Docker UI, leakage-audit jobs, isotonic calibration, and SHAP. Start with the quickstart or the risk model tutorial.

Next: Data guide · Temporal diagrams · Limits