Detect and Fix Feature Leakage in a Loan Default Model
Machine LearningModel answerLast updated
Identify subtle forms of target leakage in a credit risk pipeline and explain how to fix each without destroying predictive signal.
Scenario
You join a fintech team that built a gradient-boosted model to predict whether a loan applicant will default within 90 days of origination. The model achieved an impressive AUC of 0.97 on the held-out test set, but after six weeks in production its AUC dropped to 0.61.
The feature set includes (among others):
| Feature | Description |
|---|---|
credit_score_at_pull | Bureau score at time of application |
months_since_last_delinquency | Months since the applicant's most recent missed payment |
loan_status_30d | Whether the loan was 30 days past due at any point in the first month |
debt_settled_flag | 1 if the applicant settled a prior debt during the loan term |
account_age_months | Age of the oldest open account at application time |
payment_plan_enrolled | 1 if the borrower enrolled in a hardship payment plan |
income_verified | 1 if income was verified before origination |
The target variable is default_90d: 1 if the loan defaulted within 90 days of origination.
What is expected
- Identify which features are leaking the target and explain why each one leaks.
- Classify each leak as direct (the feature encodes or nearly encodes the target) or indirect (the feature is a downstream consequence of the target event).
- Describe a concrete strategy to fix or handle each leaky feature.
- Explain why the model looked great offline but failed in production.
- Discuss how you would design the training pipeline going forward to prevent leakage systematically.
Hints
Hint 1
Ask yourself: could this feature's value be known at the moment the model makes a prediction? If not, it leaks.
Hint 2
Think about the timeline: origination date → 30-day mark → 90-day default event. Which features can only be computed after that timeline has played out?
Hint 3
A near-perfect offline AUC that collapses in production is a classic leakage signature — think about what changes between the offline dataset construction and real-time scoring.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Identifying the Leaky Features
loan_status_30d — Direct leakage
Why it leaks: This flag records whether the loan was past due in the first month. A borrower who is already delinquent at day 30 is strongly predictive of default at day 90 — in fact, it is nearly a sub-event of the target. The value can only be known after the 30-day window closes, which is after origination and after the model should have already scored the loan.
Classification: Direct (it is almost a leading indicator of the exact target event).
debt_settled_flag — Direct leakage
Why it leaks: Settling a prior debt "during the loan term" means this event happens after origination. If a borrower defaults at day 60 and then settles an old debt to avoid further damage, this flag will be set to 1 in the historical dataset but is unknowable at origination time.
Classification: Direct (derived from a post-origination event correlated with the default trajectory).
payment_plan_enrolled — Indirect leakage
Why it leaks: Hardship payment plans are typically offered to borrowers who have already missed payments or signaled financial distress — i.e., they are a downstream consequence of the same financial deterioration that leads to default. In the historical data, this flag is 1 for many borrowers who also defaulted, but enrollment can only happen after origination stress is observed.
Classification: Indirect (a reactive intervention triggered by the same cause as default).
months_since_last_delinquency — Borderline, needs investigation
Why it is suspicious: This feature is fine if it is computed strictly from the credit bureau pull at application time. However, if the pipeline ever refreshes bureau data mid-loan and back-fills this column, it becomes leaky. This must be audited.
Classification: Potentially indirect depending on implementation.
2. Why the Model Looked Great Offline but Failed in Production
This is the classic leakage inflation pattern:
- During offline training, all historical data is available in a flat table. Features like
loan_status_30dandpayment_plan_enrolledare already populated for every row, including the rows that defaulted. - The model learned to use these post-event signals as strong predictors, inflating AUC to ~0.97.
- In production, the model scores a loan at origination. At that point,
loan_status_30ddoes not exist yet,debt_settled_flagis 0 for everyone, andpayment_plan_enrolledis 0 for everyone. - The model receives a fundamentally different feature distribution than it was trained on, causing its predictions to collapse (AUC 0.61, barely above random).
A drop from 0.97 → 0.61 is almost never a concept drift problem within six weeks — it is nearly always a leakage or training/serving skew problem.
3. Fixes for Each Leaky Feature
| Feature | Fix |
|---|---|
loan_status_30d | Remove entirely. It cannot be known at scoring time. Alternatively, if you want a model that re-scores at day 31, create a separate model and make the temporal split explicit. |
debt_settled_flag | Remove from the origination model. If you want to use settlement history (prior loans only), reconstruct the feature as "settled a debt on a prior loan before this application date." |
payment_plan_enrolled | Remove. If prior hardship plan enrollment (before this loan) is predictive, reconstruct it with a strict point-in-time cut-off. |
months_since_last_delinquency | Audit the ETL. Ensure the value is always snapshotted from the bureau pull timestamp, never refreshed post-origination. Add a data lineage test. |
4. Systematic Prevention Going Forward
Point-in-time feature store: Every feature must be associated with an as_of_date. When constructing training data, join features using as_of_date = origination_date, never the current date. This prevents any post-event value from entering the training row.
Temporal train/test split: Never use random splits for time-series financial data. Train on loans originated before month M, validate on M to M+3, test on M+3 onward. Leaky features often reveal themselves when the gap between train and test cutoff is large enough that the leaked signal is not yet available.
Leakage audit checklist for each new feature:
- Can this value be computed using only information available at
origination_date? - Does the feature's correlation with the target jump suspiciously high (e.g., >0.5 Pearson with a binary target) compared to domain expectations?
- Is there a causal path from the target event back to this feature (reverse causality)?
Monitoring in production: Track the distribution of each feature at scoring time vs. training time (e.g., PSI — Population Stability Index). A feature whose mean in production is near zero but was, say, 0.15 in training is a red flag for leakage or training/serving skew.
Unit tests on the pipeline: Write automated tests that assert no feature column has a data timestamp later than the loan's origination date. Fail the pipeline build if this constraint is violated.
Common Mistakes to Avoid
- Removing too much: Not all post-origination data is leaky. A model that re-scores at day 31 legitimately uses
loan_status_30d. The key is clearly documenting the prediction point and ensuring features respect it. - Confusing correlation with leakage: A high feature importance does not imply leakage.
credit_score_at_pullis highly predictive and perfectly valid. - Fixing leakage only in the test set: Leaky features must be removed from the entire pipeline, including training, or the model simply learns to depend on them and breaks at serving time.
- Ignoring indirect leakage: Teams often catch direct leakage (the feature literally encodes the label) but miss indirect leakage (a downstream consequence). Both destroy production performance.