LK001 — post_index_features¶
Events or features timestamped after the index date.
| default severity | error |
| injector | ehrlint.inject.inject_lk001 |
Why this matters¶
A model that sees the future cannot be deployed. This is the most common and most damaging leak: a feature computed over a window that extends past the prediction time will often be the model's strongest signal, and it will be entirely unavailable at inference.
What it looks like in practice¶
A feature pipeline that aggregates "all labs for this patient" without a cut-off at the index date, or a feature matrix whose as-of timestamp was taken from the outcome rather than the prediction moment.
A note on severity¶
The event-level branch is an observation, not an error. Outcomes and follow-up live after the index date, so every real dataset has post-index events; flagging their existence would make this check permanently red and teach you to ignore it. Supply --features to get the error branch, which can show that post-index information reached the matrix.
The query it runs¶
SELECT * FROM features f JOIN index_dates i USING (subject_id)
WHERE f.prediction_time > i.index_date
Worked example¶
On the clean synthetic cohort, which is clean by construction:
$ ehrlint audit --data clean/ --task task.yaml --checks LK001
LK001 did not fire.
120 of 120 subject(s) have 314 event(s) after their index date. That is expected -- outcomes live there. ehrlint cannot tell which events your feature pipeline consumed; supply --features to check the matrix directly.
exit code 0
With the matching leak planted by ehrlint.inject.inject_lk001:
$ ehrlint audit --data leaky/ --task task.yaml --checks LK001
LK001 post_index_features_matrix [error]
4 feature row(s) are stamped after the index date, so the matrix itself contains future information.
affected: 4 of 120 subject(s) (3.3%), 4 row(s)
example rows:
subject_id prediction_time index_date
S000050 2021-03-14 03:43:49.6697 2020-12-14 03:43:49.6697
S000098 2019-03-05 13:20:19.4562 2018-12-05 13:20:19.4562
S000109 2021-01-07 02:57:16.8241 2020-10-09 02:57:16.8241
exit code 1
Reproduce both:
ehrlint synth --out clean/ --n-subjects 120 --seed 0
ehrlint synth --out leaky/ --n-subjects 120 --seed 0 --inject LK001
ehrlint audit --data leaky/ --task leaky/task.yaml \
--labels leaky/labels.parquet --splits leaky/splits.json --checks LK001
What to do about it¶
Cut every feature window at the index date, and carry an explicit as-of timestamp on the matrix so the cut is checkable rather than assumed.
When it skips¶
A skip is not a pass. This check reports a skip, with the reason, when its inputs are not available — see reading a report.