# Data leakage (machine learning)

> Canonical: https://skillalmanac.com/glossary/data-leakage | Last verified: 2026-11-24 | Index status: index-eligible

Data leakage in machine-learning evaluation occurs when information unavailable in the intended prediction setting influences model development or testing. It can make performance estimates misleading; it does not guarantee a particular score or failure on every new example.

Also called: train test leakage, leakage in machine learning, data leakage in ML.

## In plain language

Imagine a student who sees the exam answers while studying, then sits the exam and scores well. The score is not a valid independent check of what they learned. Data leakage is the same mistake in machine learning: information from the test, or from the future, slips into the material a model learns from, so the test result may overstate generalization. It happens through small slips, such as scaling a whole dataset before splitting it, or including a column that is only filled in after the outcome is known. The main limitation is that leakage is hard to see from the score alone, because a reported score alone may not reveal contamination. The risk is a team shipping a model, or an evaluation of an AI feature, that may not have been as good as reported.

## Technical definition

scikit-learn's documentation defines leakage as information that would not be available at prediction time being used when building the model, which gives overly optimistic performance estimates, for example from cross-validation. IBM names two types: target leakage, where the model uses data that will not exist at prediction time, and train-test contamination, where training and validation data are mixed, often through improper splitting or preprocessing. Typical mechanisms are fitting a scaler, imputer or feature selector on all rows before the split, and duplicate or grouped rows landing on both sides. A common remedy is to fit every preprocessing step inside a pipeline so it only sees the training fold.

## How it shows up when you use agents

When a coding agent builds a model for you, it writes the whole workflow: load the data, clean it, split it, fit, score. An incorrect order of fitting, splitting and evaluation can introduce leakage. An agent that normalises the full dataset and then splits it, or splits rows at random when they are time-ordered, can report a strong score that real data will not match.

The same idea applies to [LLM benchmark](/glossary/llm-benchmark) results and to your own evals. If test questions appeared in a prompt, a few-shot example or [training data](/glossary/training-data), the evaluation may no longer be an independent test of the intended capability.

What breaks when this is misunderstood: you trust a high number and ship. A safer habit is to ask the agent to show, in code, which rows each preprocessing step was fitted on, and to put those steps in a pipeline so they only see training data, which scikit-learn's documentation recommends. Check time-ordered data by splitting chronologically, as IBM advises. Then run [skill-almanac/split-leakage-check](/skills/skill-almanac/split-leakage-check) on the split files. A related failure is [overfitting](/glossary/overfitting), where fitting training-specific patterns harms generalization; leakage can hide it by making the test score look fine.

## Worked example (illustrative)

Imagine selecting features using both training and test labels, then reporting performance on those same test rows. The test data has influenced model selection, so it is no longer an independent holdout. Refitting selection only on training folds addresses that route of contamination. It does not, by itself, rule out duplicates, temporal leakage or other evaluation flaws.

## Common confusions

- **Data leakage versus a data breach.** A breach is data reaching people who should not have it. Leakage in machine learning is information crossing from test or future data into model building. No one needs to steal anything.
- **Leakage versus overfitting.** [Overfitting](/glossary/overfitting) is fitting training-specific patterns that do not generalize well. Leakage is a flaw in how the data was split or prepared. They can occur together, and leakage can make overfitting invisible.
- **Target leakage versus train-test contamination.** IBM separates a feature that would not exist at prediction time from a split that mixes training and validation data.
- **Myth: a very high score proves the model is good.** An unexpectedly high score is one reason to look for leakage.

## Worked examples in this catalogue

### [split-leakage-check](https://skillalmanac.com/skills/skill-almanac/split-leakage-check)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: It checks train, validation and test files for duplicates, shared groups, time and label leakage, and prints a JSON report.

Why it exercises the concept: These are the leakage routes the definition names: rows or groups on both sides of a split, future information, and label information. A flagged finding is the concept made visible in your own files.

### [llm-eval-test-sets](https://skillalmanac.com/skills/skill-almanac/llm-eval-test-sets)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: It builds and validates an eval dataset for an LLM feature, with a checker for duplicates, missing graders, imbalance and leakage.

Why it exercises the concept: Leakage is not only a classic-model problem. If test items overlap with what a prompt, example set or fine-tune saw, the eval score is optimistic in the same way.

### [data-analysis-eda](https://skillalmanac.com/skills/skill-almanac/data-analysis-eda)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: It follows a fixed exploratory-analysis procedure with a CSV profiler, keeping findings descriptive, evidenced and caveated.

Why it exercises the concept: This is an adjacent case, not a leakage tool. Profiling a dataset before modelling is where a suspicious column, such as one filled in after the outcome, is often first noticed. The catalogue has no model-training skills.

## Related terms

- [Overfitting](https://skillalmanac.com/glossary/overfitting.md)
- [Cross-validation](https://skillalmanac.com/glossary/cross-validation.md)
- [Training data](https://skillalmanac.com/glossary/training-data.md)
- [LLM benchmark](https://skillalmanac.com/glossary/llm-benchmark.md)
- [Machine learning (ML)](https://skillalmanac.com/glossary/machine-learning.md)
- [Supervised learning](https://skillalmanac.com/glossary/supervised-learning.md)

## Sources

- [Common pitfalls and recommended practices](https://scikit-learn.org/stable/common_pitfalls.html), scikit-learn (accessed 2026-11-24)
- [What is data leakage in machine learning?](https://www.ibm.com/think/topics/data-leakage-machine-learning), IBM (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-24. [Glossary index](https://skillalmanac.com/glossary.md).
