Quick summary:
This guide follows a composite example built from real ScriptsHub Technologies engagements. A lead-conversion model scored 0.95 AUC in validation and fell to about 0.71 in its first weeks of live scoring, because it had learned from information it would never have at prediction time. It explains how data leakage in machine learning differs from overfitting, the four types we found, the fix (0.84 offline, 0.82 live), and a seven-point checklist to run before any model ships.
If your model looks brilliant in validation and ordinary in production, the cause is most often data leakage rather than the algorithm. The usual symptoms are a validation AUC that seems too good for a hard problem, one feature towering over the rest, and a model that appears to know outcomes before they happen. Our team at ScriptsHub Technologies has met those exact symptoms on lead-conversion models. The example in this guide combines those engagements into one composite model, with details changed to protect client confidentiality. Each time, the first validation score looked like a win, and it took a while to accept that the number itself was the problem. This is the write-up we wish we had read before those first training runs.
What is data leakage in machine learning?
Data leakage is when a model learns from information it will not have at the moment it makes a real prediction.
IBM’s explainer on what leakage is in machine learning uses the same definition. The model is not cheating on purpose: it finds the easiest pattern in the data, and if the answer is hidden inside a feature, it uses that feature. The test set usually carries the same leak, so the model scores well there too. Production does not, so performance drops from the first day of live scoring.
This is not a niche mistake. A 2023 review in Patterns by Kapoor and Narayanan, Leakage and the reproducibility crisis in machine-learning-based science, identified leakage affecting at least 294 published papers across 17 scientific fields, based on a survey of earlier reviews in those fields.
One question catches most leaks: “At the exact moment we would have scored this record, could we have known this value?” If not, that feature is leaking.
Security teams use the same phrase for sensitive data escaping an organization. This article covers the machine learning meaning, sometimes called feature leakage or target leakage, though target leakage is also the name of one specific type.
Why does a model with high AUC fail in production?
Offline metrics measure how well the model fits your validation data. They say nothing about whether that data looks like production.
Our offline setup differed from production in three main ways, all in the AI data pipeline that fed the model. Rows were split at random, so the model trained on leads that arrived after many of its test leads. Several features were computed from the current CRM state instead of the score date. A few fields were updated by the sales process after the outcome had happened.
Each of these gave the model a small look at the answer. Together they opened a gap of about 0.24 AUC between offline and live scoring, because on fresh leads the leaked signals either disappear or arrive as missing values and the model falls back on weaker patterns it never learned properly. Data drift and training-serving skew can open a similar gap, so rule them out too; drift usually builds over weeks, while leakage and skew show up from the first day.
Offline vs live AUC before and after fixing data leakage in a machine learning model

Figure 1: Offline vs live AUC before and after the fix. Only the 0.24 gap in the first pair is caused by leakage. The axis starts at 0.5, a random model’s score.
What is the difference between data leakage and overfitting?
Overfitting shows up as a gap between training and validation scores, while leakage inflates both together.
That difference is why leakage survives code review. An overfit model warns you early, because its validation score drops below its training score. A leaky model gives no such warning: the validation set carries the same shortcut as the training set, so cross-validation looks rock-solid and the model ships. The drop only appears once production data arrives without the shortcut.

Table 1: How data leakage and overfitting differ across training, validation and production.
What are the common types of data leakage?
We found four types of leakage in one model, and the two most damaging came from getting time wrong.
If your model has a timeline (leads, churn, fraud, demand, credit), expect to meet at least two of them. Table 2 summarizes how each one shows up and how to catch it.

Table 2: The four types of data leakage we found and how to catch each one.
Target leakage: the feature that already knows the answer
Target leakage happens when a feature carries information about the outcome that only exists after the outcome has happened. Our biggest leak was a field the sales team updated when a lead moved forward; nearly every converted lead had it filled in, so the model learned that rule immediately. The field was accurate; it simply got its value because the lead converted, which makes it a consequence of the outcome rather than a predictor of it.
Common data leakage examples follow the same pattern: an account-closed date used to predict churn, a refund flag used to predict fraud, or length of hospital stay used to predict admission.
Temporal leakage: features that look into the future
This one was harder to spot. Features like “emails opened” and “days since last activity” looked harmless, but we had computed them from the current database. A lead that converted three months ago carried three extra months of activity, while a new lead in production has none. Normalize event times to one zone before filtering, a lesson from our Azure Synapse timezone conversion work.
Train-test contamination: preprocessing before the split
We fitted a target encoder for a high-cardinality category (lead source) on the full dataset before splitting. Because target encoding uses the label, the encoder had already seen the test outcomes. Our effect was small, but with rare categories it can be large. The fix is to fit the encoder inside a Pipeline on training rows only. scikit-learn’s TargetEncoder (version 1.3 and later) also uses internal cross-fitting, so a training row’s own label does not leak into its encoding. Scalers, imputers and feature selection also leak test-set information when fitted before the split. The scikit-learn guide to train-test contamination and other common pitfalls shows feature selection fitted before the split pushing accuracy on pure noise to about 0.76, when the honest answer is 0.5.
Group and duplicate leakage: the same entity on both sides
Some people submitted their details more than once, so a random split put copies on both sides and the model was tested on people it had already memorized. Google’s guidance on the train-test split recommends deleting test examples that duplicate training examples.
How do you prevent data leakage with point-in-time features?
Give every training row a score date, and build every feature only from data recorded before that date.
Point-in-time features sit inside four rules that prevent most leakage: split the data before any preprocessing, keep every preprocessing step inside a pipeline, respect time and entity boundaries when splitting, and audit every feature for whether it exists at prediction time. This section covers the features; the next covers the splits.
The score date is the moment you would have made the prediction. Computing features relative to it is called point-in-time correctness; Amazon SageMaker Feature Store offers point-in-time accurate joins for the same purpose.

Code 1: Point-in-time feature builder. Every feature is measured from the score date.
Why this works: The filter
event_time < score_datestops the model from seeing the future, so a lead scored in March looks exactly as it did in March. If events can arrive late or be backdated, also filter on the time each row was recorded.
When to use which: If you score each lead once, set the score date to a fixed point such as “created date plus N days.” If you re-score leads daily, create one row per lead per scoring day; that gives more training rows but needs a split by lead ID. For changing attributes such as owner, join history as of the score date with
pandas.merge_asof(sorted by date, withallow_exact_matches=False) or a bitemporal SCD Type 2 table.
Target leakage needs a manual review: for every column, ask who fills it in and when, and remove anything set by the outcome. Column-level lineage from AI data governance makes this much faster.
How do you validate a model with a time-based split?
Split by time, leave a gap between the training and test periods, and keep all preprocessing inside the pipeline.
Random splits are the wrong default for any problem with a timeline, so we moved to a time-based split: train on older leads, test on newer ones.

Code 2: Time-based holdout with a 30-day gap and preprocessing inside a Pipeline.
Why this works: The model learns only from the past and is judged on a future it has not seen, exactly as in production. The gap matters because labels behave like late-arriving data: a lead scored in mid-December may not convert until January, so without the gap some test-period outcomes would quietly shape training. The Pipeline fits the imputer and encoder on training rows only.
Implementation note:
sparse_output=False(scikit-learn 1.2 and later) keeps the encoded matrix dense, which HistGradientBoostingClassifier requires. Without it, one-hot encoding a high-cardinality column can make ColumnTransformer return sparse output.
How to verify it worked: Your offline score should drop. Ours went from 0.95 to 0.84, which feels like a step backward but is the honest number. What matters is that live performance now matches it.
For cross-validation, use TimeSeriesSplit on data sorted by score date; its gap is counted in rows, not days. For repeated people or accounts, GroupKFold prevents group leakage, but it ignores time, so with time-ordered data keep the time split and drop test rows for people already seen in training.
If a model of yours looks better offline than in production, book an ML model leakage review with ScriptsHub Technologies before your next release.
How do you detect data leakage in an existing model?
Look for a model that is too good, a feature that is too strong, and an offline score that production cannot match.
You do not always get to rebuild from scratch. These are the five checks we now run before every release, and most take a few minutes.
Single-feature AUC. Score each feature on its own. In most real problems, no single feature comes close to the full model; if one does, check how and when it gets filled in.

Code 3: Flag any numeric feature that predicts the label almost on its own.
Feature importance sanity check. If the top feature is three or four times more important than the second, treat it as a suspect. HistGradientBoostingClassifier has no built-in feature_importances_, so use permutation_importance on the holdout set.
The rewind test. Rebuild features for a past score date using only data that existed then. If the values differ from your training table, it was built with data recorded after the score date.
Baseline comparison. If a complex model dramatically beats a simple logistic regression on a problem people consider hard, investigate before celebrating. Kapoor and Narayanan found the same pattern in their civil war prediction case study: once leakage was fixed, complex models no longer beat older logistic regression models.
Shadow scoring. Run the model alongside the current process for a few weeks. It is the most reliable way to catch leaks nobody thought of. Kaggle’s hands-on target leakage tutorial is good practice.
Did the fix close the gap between offline and live AUC?
Yes. The offline score went down, the live score went up, and the two finally agreed.
With point-in-time features, post-outcome fields removed, a time-based holdout and each person’s duplicates kept on one side, the model scored about 0.84 offline and 0.82 live.

Table 3: Model metrics before and after removing data leakage
These figures come from the composite example; your own gap will depend on how much information leaked into your features. The drop is the hardest part to explain to stakeholders, and it is worth explaining anyway: a 0.84 you can rely on is worth more than a 0.95 that falls apart in a month. We also added one process rule. Every retrained model must beat the current one on the same time-based holdout, because comparing two models on different splits is another quiet way to fool yourself.
Leakage checklist: seven checks before you ship a model
If your model passes all seven checks, its offline score is probably telling the truth.

Table 4: Pre-release data leakage checklist.
Conclusion: trust the suspicion before the score
If your validation score looks too good, treat it as a warning sign. Most leakage comes from time: features counted up to today instead of up to the score date, splits that let the model train on the future, and fields filled in because the outcome already happened. Fix the timeline, validate the way production runs, and expect the offline number to drop. The work often starts upstream with data readiness for AI. If you want a second pair of eyes on a model before it ships, book a machine learning model audit with ScriptsHub Technologies.
Frequently asked questions
Q. What is data leakage in machine learning?
Data leakage occurs when a machine learning model trains on information that will not be available during real-world predictions. This flaw inflates offline validation metrics, such as ROC AUC, while causing poor generalization in production.
Q. What is the difference between data leakage and overfitting?
Overfitting happens when a model memorizes training noise, causing high training accuracy but low validation scores. Data leakage contaminates the evaluation pipeline itself, artificially inflating both training and validation scores before failing on live production data.
Q. What are the main types of data leakage in ML?
Data leakage falls into two broad categories: target leakage (features containing post-outcome or future data) and train-test contamination (test information reaching training). In practice these show up as four types: target, temporal, preprocessing, and group or duplicate leakage.
Q. How do you detect data leakage in a machine learning model?
Detect data leakage by flagging unrealistically high validation scores, running single-feature AUC checks for suspiciously predictive columns, and auditing feature timestamps. A sharp performance drop between offline testing and live production also signals leakage.
Q. How do you prevent data leakage in machine learning?
Prevent data leakage by splitting datasets before applying scaling, imputation, or feature selection inside scikit-learn pipelines. Use time-based splits for sequential records and group-aware splits for repeated entities, and verify every feature exists prior to the prediction timestamp.
About ScriptsHub Technologies: ScriptsHub Technologies is a data engineering and applied AI consultancy with teams in the US, UK and India, building data pipelines, analytics platforms and production ML systems. Learn more at scriptshub.net.




