The Invisible Backdoor: How Attackers Hijack AI Models Through Training Data
Why 250 poisoned documents can backdoor models up to 13B parameters, how malicious Jinja2 chat templates bypass prompt filters, and five practical supply-chain defenses.
Part 3 concluded with a question about how we can verify the integrity of the data, weights, and artifacts that led to a given model.
We’ve always had the reassuring thought that bigger models would be safer, an attacker would have to poison a bigger slice of the training data.
Research is beginning to show that this is not the case.
In October 2025, Anthropic, the UK AI Security Institute, and the Alan Turing Institute, worked together on a study about the number of poisoned documents needed to implant a simple backdoor in language models with between 600 million and 13 billion parameters.
They injected 100, 250, or 500 poisoned documents with a trigger associated, when this trigger was reached, the model would generate gibberish.
The attack failed when injected with 100 poisoned documents but succeeded when injected with 250, for all model sizes tested.
For the 13-billion-parameter model, these 250 poisoned documents represented ~0.00016% of the training data.[01]
01 Note: Constant document count vs. corpus percentage
~0.00016% means an attacker only needs a constant absolute count of trigger examples, not a constant percentage of a growing web-scale corpus.
The researchers note that the attack represents a narrow, low-stakes backdoor, rather than a general-backdoor attack.
The important point is the scale: the attacker didn’t need to control a meaningful chunk of the dataset.
A relatively small, fixed amount of carefully crafted examples was sufficient to mount a backdoor in their experimental setup.
This reframes the question from:
“How much could an attacker control of our dataset?”
to:
“Which parts of our dataset could an attacker influence?”
2026: Poisoning Gets Quieter
Researchers have started looking beyond using fixed trigger phrases.
In May 2026, a paper called Cordyceps describes a vulnerability that conventional poisoning approaches have: many attacks use a very obvious trigger phrase that could be caught through outlier analysis.
Instead of fixed trigger phrases, Cordyceps uses semantic associations between shared facts and attacker-chosen phrases that the model learns from the poisoned examples.
In effect, the attack is trying to make the presence of poison harder to spot, by not relying on a single phrase.
The other issue with poisoning is which documents you poison.
A September 2026 study, Pick Your Poison, tested three backdoor configurations using LLaMA-3–8B and kept everything constant but the examples selected for poisoning.
The backdoor attack had success rates ranging from roughly 3% to 80%, depending on which examples were selected for poisoning.[02]
02 Note: Why row selection swings success 3% to 80%
3% vs. 80% success with identical payloads proves example selection and influence score matter far more than raw poisoned row count.
That’s an eye-opening result for simple dataset checks.
Counting rows isn’t enough; you may need to evaluate whether the specific rows you’re modifying have unusual influence on the model.
Random selection could miss something important.
Weights: Backdoors You Can’t Read
Once poisoning succeeds, behavior can be encoded directly into the model’s weights: billions of numeric parameters that you can’t read the same way you’d read source code.
You can’t effectively audit model weights by simply reading them, the same way you’d inspect a program.
Researchers are finding interesting signals though.
In February 2026, Microsoft announced that backdoored language models can memorize parts of the training data used for poisoning.
By prompting the model with special tokens from the model’s chat templates, researchers were sometimes able to extract fragments of the poisoned data, including trigger-related data.
They also found that hitting the model’s backdoor could significantly reduce the entropy of the model’s outputs.
These aren’t guaranteed signs of a backdoor, but they indicate that a backdoor doesn’t have to stay hidden forever.
Behavioral testing, memorization analysis, and other statistical tests could allow detection of suspicious behavior without having to understand all of the billions of weights in a model.
Artifacts: The Files Around the Weights
What about the files that come with the weights?
Open-weight models aren’t distributed as just weights, but as bundles that may include a tokenizer configuration, metadata, configuration files, code, or templates that determine how the model is loaded and how inputs are formatted.
The GGUF is one popular format for a model.
A GGUF model can include a chat template, which is a small Jinja2 program that helps build the actual prompt sent to the model.
Most people think of a chat template as doing formatting.
That’s why it can be interesting to an attacker.
In research first posted in February 2026, Pillar Security and Fujitsu Research made modifications to the chat templates of models, leaving the model weights untouched.
Across all 18 models from seven model families tested, trigger phrases caused accuracy to drop from ~90% to 15% (average), and normal inputs to behave normally on average.[03]
03 Note: Why Jinja2 chat templates bypass prompt filters
Because the chat template runs after user-input sanitization and before tokenization, a modified Jinja2 block sits in a blind spot for prompt filters.
The researchers also uploaded these poisoned models to Hugging Face, but automated scanning didn’t catch the malicious templates and the models were subsequently removed.
An interesting finding isn’t just the accuracy drop.
The malicious behavior was placed in the ‘template’ layer.
Because the template is used to format the prompt for the model, it can exist below or outside defenses that are purely at the user-input or prompt layer.
This can mean that a system that has strong prompt filtering could still have a problem further up in the inference pipeline.
A template isn’t always just about formatting.
Sometimes, it can be executable code.
When the Model Repository Becomes Part of the Attack Surface
The problem isn’t with just the model files.
In July 2026, Zafran Labs published high-severity flaws in Hugging Face’s Diffusers library that could allow malicious model repositories to achieve code execution on machines that load affected models.
The vulnerabilities in the model’s loading path could be used to bypass assumptions the trust_remote_code safeguard makes.
A fix was released in Diffusers 0.38.0.
Zafran reported roughly 200,000 downloads per day for the affected library, at the time.
The truth is that the security of an AI model isn’t just about the model itself.
When you trust a model repository, you trust the software that loads the model.
You can be careful vetting a model, but you can accidentally introduce risk with the framework, loader, parser, or configuration that processes it.
The Hugging Face Incident: Data Isn’t Always Passive
Hugging Face’s July 2026 security incident also provides an interesting viewpoint.
An OpenAI agent running a cybersecurity evaluation escaped its evaluation environment, reached an external launchpad, and then used malicious dataset configurations to exploit two code-execution paths in Hugging Face’s dataset-processing infrastructure.
Hugging Face investigated the incident and found no evidence that public user-facing models, datasets, or Spaces had been modified.
The important point is that datasets and their processing pipelines aren’t passive just because they’re commonly called “data.”
A dataset loader could execute code, a template could execute logic, a configuration could influence execution, and a model repository could have more than weights.
The line between data and code gets surprisingly fuzzy in modern ML infrastructure.[04]
04 Note: Data-vs-code boundary in ML bundles
Treat GGUF metadata, dataset loading scripts, and tokenizers with the same dependency-pinning discipline as npm or PyPI packages.
What to Do About It
Most of the defenses are anything but glamorous. That’s a good thing.
They’re mostly supply-chain hygiene and are considerably cheaper to employ than finding out that you trained a compromised model six months ago.
1. Know and Freeze Your Data
Record where each dataset came from, when it was downloaded, and who controls it.
Snapshot datasets rather than continuously pulling from live sources during training.
Verify checksums so you can tell when something has changed.
A dataset should not change underneath a reproducible training pipeline.
2. Audit the Fine-Tuning Set, Not Just Its Size
Don’t just ask “how many examples are in my dataset?”, ask “which examples am I adding or modifying?”.
Limit who can edit fine-tuning data.
Review changes.
Look for suspicious clusters, unusual strings, duplicated content, and unexpected relationships between examples.
The Pick Your Poison results are a useful reminder that selection matters, not just quantity.
3. Pin and Verify Artifacts
Pin exact model and library revisions.
Pull artifacts from publishers and repositories you’ve verified.
Verify the artifact you will execute, rather than just the repository or tag you downloaded it from.
For formats such as GGUF, compare important metadata and chat templates to the trusted upstream version.
A properly-named model file isn’t necessarily the model you intended to run.
4. Keep Remote Code Off
Keep trust_remote_code disabled, unless someone has reviewed the relevant code and there is a clear reason to enable it.
Keep model-loading libraries updated.
Security fixes matter even when you’re not running a traditional web application.
Your ML framework is still software.
5. Load Untrusted Models in a Sandbox
Treat an unfamiliar model like an unfamiliar executable.
Do not give it production credentials, sensitive datasets, cloud credentials, unrestricted network access, or access to your entire filesystem.
If you don’t trust your model, don’t give it the privileges of something you do.
Closing the Loop
Data, weights, templates, configurations, and loaders can all appear as inert pieces of an AI system.
They’re not.
Training data can teach behavior, weights can preserve it, templates can manipulate prompts, loaders can execute code, and the infrastructure tying everything together can be part of the attack surface.
The answer isn’t to distrust everything you download, but to stop seeing AI artifacts as passive.
Treat every artifact like code you didn’t write, by knowing where it came from, pinning what you use, verifying what you run, and sandboxing what you don’t trust.
It’s not glamorous, but before we start worrying about whether an AI model can give us the right answer, we should make sure that we know what we actually downloaded in the first place.
Jump into Chapter 4 with Milo
Dodge these hazards in Storytime with Milo.