AI data cleaning best practices are the methods teams use to turn raw, messy data into a training set a model can learn from without picking up errors, duplicates or leakage. Cleaning covers missing values, duplicates, bad labels, inconsistent formats, outliers and the train-test split itself. The central question is how much cleaning is enough, and the answer is to clean what affects the model, measure the effect of each step, and keep the raw data untouched so every decision can be revisited.
Raw data is never ready for a model. It arrives with gaps, errors and quirks from the systems that produced it, and a model trained on it will learn those quirks as if they were truth. Cleaning is therefore not a chore to rush through before the interesting work; it is the work that decides whether the model is worth anything. Teams that invest in cleaning spend less time later wondering why a model behaves strangely.
Key takeaways
- AI data cleaning prepares raw data for training by removing errors, duplicates and leakage.
- Never overwrite raw data: clean in a pipeline, version the output, and keep every step reproducible.
- Handle missing values by understanding why they are missing, not by filling them blindly.
- Deduplicate before splitting train and test, or evaluation will overstate performance.
- Measure the effect of cleaning on a real evaluation set, and document every decision.
Start by understanding the mess
Cleaning should start with profiling, not with fixing. Before changing anything, measure what is wrong: how many values are missing in each field, which formats appear, how many duplicates exist, and what the distributions look like. Profiling turns a vague sense that the data is messy into a list of specific problems with sizes attached, and that list decides the order of work.
Profiling also reveals problems that cleaning cannot fix. A field that is missing for an entire segment of users is not a cleaning problem; it is a collection problem. A label that disagrees with the business definition is not a data error; it is a definition problem. Knowing which problems are which saves a team from cleaning data that should never have been used in the first place.
One rule governs everything that follows: never modify the raw data. Cleaning runs as a pipeline that reads raw data and writes a cleaned version, so the originals stay intact and the process can be rerun. When a cleaning decision turns out to be wrong, the team changes the pipeline and reruns it, rather than trying to reconstruct what the data used to look like. For the versioning discipline that makes this safe, see our guide to AI workflow versioning, which covers tracking prompts, models and data together.
Missing values: find out why before you fill
Missing values are the most common cleaning problem, and the most commonly mishandled. The right treatment depends on why the value is missing. A sensor that failed produces a different kind of gap from a form field a user chose to skip, and both differ from a field that only applies to some records. Filling all three the same way hides the difference.
The practical options are to drop the record, to fill the value, or to keep the missingness as information. Dropping is safe when missing rows are few and unimportant, but it is dangerous when the missing rows share a pattern, because dropping them biases the dataset. Filling with a mean, median or model prediction works when the value can be estimated from the rest of the record, but it understates uncertainty and can create values that never occur in reality.
Often the best option is to add a flag that records that the value was missing, and let the model use that information. A missing income field, for example, may itself predict something about the customer. Whatever the choice, it should be recorded per field, applied identically to training and live data, and tested on an evaluation set. Best for: any dataset where more than a small share of a field is missing, and the missing rows are not random.
Duplicates, near duplicates and leakage
Exact duplicates are easy to find and remove. Near duplicates are the real problem: the same customer with a slightly different spelling, the same document scraped twice with a different timestamp, the same image cropped differently. Near duplicates inflate the weight of one example in training, and worse, they can straddle the train-test split, so the model is tested on data it has effectively already seen.
Deduplication should therefore happen before any split, using a definition of sameness that fits the data. For text, that may mean comparing normalised content or embeddings; for records, it may mean matching on a combination of fields rather than a single identifier. The definition should be documented, because two teams with different definitions will produce different datasets from the same raw data.
Leakage is the broader version of the same problem: information from the target, or from the future, slipping into the training features. A classic example is a feature that is only recorded after the outcome it is meant to predict. Cleaning should include a leakage check: for each feature, ask whether it would be available at the time the model makes its prediction. If the answer is no, the feature goes, however predictive it looks. For the evaluation discipline that catches leakage after cleaning, see our guide to AI evaluation best practices, which covers building test sets that expose it.
Labels, formats and outliers
Labels deserve the most care, because a wrong label teaches the model the wrong thing directly. Label cleaning starts with consistency: the same input should carry the same label wherever it appears, and disagreements between annotators should be measured and resolved. A sample of labels should be reviewed by a domain expert, with the error rate recorded, because a model cannot outperform its labels by much.
Format cleaning is more mechanical but still matters. Dates in several formats, numbers with different units, categories with variant spellings, and text with inconsistent encoding all need to be standardised. The standard should be written down, applied by code rather than by hand, and applied identically to training and live data. A model that learned one encoding and meets another in production will fail in ways that look like a model problem but are really a cleaning problem.
Outliers need judgement rather than a rule. A value far from the rest may be an error, a rare but real case, or the most important example in the dataset. Deleting outliers blindly can remove exactly the cases the model most needs to handle. The practice is to investigate outliers before deciding, keep the ones that are real, and record the ones that were removed and why.
Cleaning as a pipeline, not a notebook
Cleaning done in a one-off notebook is cleaning that cannot be repeated. The cleaned dataset becomes a file nobody can reproduce, and the next refresh of the data starts the whole messy process again. A cleaning pipeline, by contrast, is code: it reads raw data, applies the steps in order, writes a versioned cleaned dataset, and logs what it changed.
The pipeline should also produce a cleaning report. For each step, the report records how many records were affected, what was changed, and what was removed. That report is the evidence that the cleaning did what it claimed, and it is the first thing to check when a model behaves unexpectedly. A model trained on cleaned data without a cleaning report is a model whose training data nobody can describe.
Finally, cleaning should be tested like any other part of the system. A new cleaning step is a change to the data, and it should be evaluated by retraining or re-evaluating the model on an evaluation set, not by assuming it helped. Some cleaning steps hurt: aggressive outlier removal, careless filling of missing values, and over-eager deduplication have all made models worse. Measuring the effect is the only way to know.
Comparing data cleaning techniques
| Problem | Technique | When it helps | What to watch for |
|---|---|---|---|
| Missing values | Drop, fill or flag | Small gaps, estimable values | Non-random missingness biases data |
| Exact duplicates | Drop identical rows | Always, before splitting | None, if done before the split |
| Near duplicates | Fuzzy matching, embeddings | Text, images, scraped data | Definition of sameness must be documented |
| Bad labels | Consistency checks, expert review | Human-labelled data | Model cannot beat label quality |
| Inconsistent formats | Standardisation by code | Dates, units, categories, encoding | Training and live data must match |
| Outliers | Investigate, then keep or remove | Errors and extreme values | Real rare cases look like errors |
| Leakage | Availability check per feature | Any feature derived after the outcome | Leakage inflates evaluation scores |
The table is a guide, not a recipe. Each technique should be applied where profiling showed a real problem, and its effect should be measured on an evaluation set before it becomes part of the pipeline.

AI data cleaning checklist
- Raw data is profiled before any cleaning, and the problems are listed with sizes.
- Raw data is never modified; cleaning runs as a pipeline that writes a versioned output.
- Missing values are handled by cause, with the choice recorded per field.
- Exact and near duplicates are removed before the train-test split.
- Each feature is checked for leakage: would it be available at prediction time?
- Labels are checked for consistency, and a sample is reviewed by a domain expert.
- Formats are standardised by code, identically for training and live data.
- Outliers are investigated before removal, and real rare cases are kept.
- Every cleaning step produces a report of records affected and values changed.
- Cleaning changes are evaluated on a real evaluation set before they are adopted.
Frequently asked questions
How much data cleaning is enough?
Enough that the remaining problems do not affect the model. Profile the data, clean the problems that profiling shows, and measure the effect on an evaluation set. Cleaning beyond that point has diminishing returns, and each extra step is a new chance to introduce an error.
Should missing values be dropped or filled?
It depends on why they are missing. Drop them when they are few and random; fill them when the value can be estimated reliably; flag them when the missingness itself carries information. Never fill blindly, and always apply the same treatment to training and live data.
What is the most common data cleaning mistake?
Splitting train and test data before deduplicating. Near duplicates then straddle the split, the model is tested on data it has effectively seen, and evaluation overstates performance. Deduplicate first, split second, every time.
Can cleaning be automated?
Parts of it can: format standardisation, exact deduplication, range checks and missing-value handling are all automatable in a pipeline. Judgement calls, such as whether an outlier is real or whether a label is wrong, still need a person. Automation should handle the routine and surface the judgement calls, not make them silently.
How do you clean text data for AI?
Standardise encoding and casing where it does not change meaning, remove boilerplate and duplicated content, handle personal information according to the privacy rules, and keep a sample for human review. Avoid aggressive normalisation that strips meaning, such as removing all punctuation from text where punctuation carries information.
Should cleaning be the same for training and live data?
Yes, exactly the same. The cleaning pipeline should be shared, so a value the model sees in production has been through the same transformations as the training data. Any difference between the two is a source of silent failure that is hard to diagnose.







