What it is
Real chat logs are messy. Next to the answers you want the model to copy, they contain error messages, refusals from a safety layer, markup that only the chat interface understands, replies that just say a file is ready, and the same conversation saved twice. Cleaning is the first step of data preparation: it removes or repairs those records before anything is converted into a training file.
It matters because fine-tuning has no notion of a “bad example”. Every target reply that reaches the training file is treated as the right answer, and the model is pushed to make it more likely. One error message used as a target ten times teaches the model that error messages are a normal reply.
How it works
Each step looks for one specific pattern, and each has a reason grounded in how training works. Some steps remove a target reply (it stays readable as context, it just isn't graded); others remove a whole record or rewrite its structure.
| Step | What it catches | Why it would hurt training |
|---|---|---|
| UI markup | Tags the chat interface uses to render buttons, collapsible panels and similar | A model used outside that interface would print raw tags in its answers |
| Error replies | “Error processing query…” and similar system failures | The model would learn to fail on purpose |
| Guardrail blocks | Refusals inserted by a platform safety layer, not written by the model | Teaches refusals for questions that were fine to answer |
| File announcements | Short replies whose real output was a generated file, e.g. “Your deck is ready” | The file is not in the text, so the model learns to claim work it did not do |
| Structure | A conversation that opens with the assistant; two messages in a row from the same role | Training formats require alternating user and assistant turns, starting with the user |
| Duplicates | The same conversation with the same answer, saved or imported twice | Counts one example twice: more weight, more memorisation, no new information |
| Repeated replies | One identical reply used as a target many times, such as a greeting or a canned disclaimer | A few stock phrases would dominate and the model would reach for them everywhere |
Duplicates deserve special attention. Research on large training sets found that repeated text is a major driver of memorisation: Lee et al. (2021) showed that deduplicating training data made models emit memorised text ten times less often, and Carlini et al. (2022) found that how often a sequence is duplicated is one of the strongest predictors of whether a model will repeat it word for word. A fine-tuning set is far smaller, so a single conversation repeated five times is a large share of what the model sees.
The capped repeated replies step is softer than deduplication. A short, identical reply like “Happy to help — anything else?” may be perfectly good, so it is kept up to a limit and only the excess copies stop being targets. The model still learns the phrase, without learning to say it to everything.
- A support team picks 1,000 conversations containing 1,850 assistant replies marked as targets.
- 38 targets are error replies from a service outage week and 12 are guardrail refusals. All 50 stop being targets.
- 27 targets are “Your report is ready” messages whose real output was a PDF. Removed: the text alone cannot teach the model to produce a PDF.
- 64 targets sit in conversations that were imported twice. One copy of each is kept.
- The sign-off “Is there anything else I can help with?” appears as a target 71 times. With a cap of, say, 30, 41 copies stop being targets.
- 1,668 targets remain, about 90%. Training costs slightly less, and the 10% removed were the replies most likely to make the model worse.
When it matters
- Always for logs from a live product. Outages, safety layers and interface features all leave traces that look like replies.
- More for small datasets. With 200 targets, ten bad ones are 5% of the signal; with 20,000 they are noise.
- Imported chats. Exports from other tools often contain repeated or partially overlapping conversations.
- When the model will run outside the chat interface. That is when UI markup must go; keep it only if the model will be used in the same interface that renders it.
Off by default. Turn it on only if the trained model will answer inside the same chat interface that understands those tags, and you want it to keep producing buttons and collapsible sections.
Common mistakes
- Assuming a large dataset makes cleaning unnecessary: duplicates and canned replies grow with the dataset.
- Training on “Your file is ready” replies and then wondering why the model claims to have created files it never produced.
- Keeping interface markup for a model that will run in another product, where the tags show up as raw text.
- Fixing symptoms in every prep instead of the source: if many replies are errors or refusals, the underlying chats or product flow need attention.
- Deduplicating by message instead of by conversation, which can leave a reply without the question that explains it.
References and further reading
External sources open in a new tab.
- 01Deduplicating Training Data Makes Language Models BetterLee et al., 2021 · arXiv · arxiv.orgShows how much repeated text there is in real datasets and how removing it reduces memorisation.
- 02Quantifying Memorization Across Neural Language ModelsCarlini et al., 2022 · arXiv · arxiv.orgMemorisation grows with model size, with how often an example is duplicated and with prompt length.
- 03LIMA: Less Is More for AlignmentZhou et al., 2023 · arXiv · arxiv.org1,000 carefully curated examples were enough for strong results: quality over quantity.
- 04Supervised fine-tuningOpenAI API docs · developers.openai.comA provider's view of what a training example should contain.