Twin Distillation Against Indirect Prompt Injection: Training Language Models to Distinguish User Instructions from Injected Instructions
Many people now let an AI assistant read for them: a web page, an e-mail, a document. If that text contains an instruction, the assistant may follow it as though the user had given it, so anyone who can put text in front of the assistant can give it orders. This is indirect prompt injection.Filters that try to catch the hidden instruction are fooled by rewording. Retraining works better, but it mostly teaches the assistant to ignore anything that sounds like an instruction, so it ignores its user too and drops sentences it should copy or translate.Twin distillation teaches the assistant to judge an instruction by where it came from, not by how it sounds. Training examples come in pairs: in one, an instruction is hidden inside the document and the assistant learns to answer as if it were not there; in its twin, the same words come from the user and the assistant learns to follow them. Later training teaches it to copy, count, edit and translate documents without dropping such sentences, and to hold up against the disguises attackers use.We trained Qwen2.5-3B, Qwen2.5-7B and Llama-3.1-8B this way. Against attackers that reword, adapt to the model’s replies or use tricks the models never saw, on fresh documents and on an agent’s tool outputs, they hold up as well as or better than the published defences on the same models, and they are the only ones that stay secure while still following the user and keeping the document’s text. An attacker with full access to the model’s weights still succeeds on the Qwen models, as it does against the published defences. Code and adapters are released.
Authors
- Md Anas Biswas (ORCID: https://orcid.org/0009-0009-0113-5816)
Publication Details
- Journal
- Preprints.org
- Published
- 2026-11-24
- DOI
- https://doi.org/10.20944/preprints202611.2399.v1
- Primary Topic
- Adversarial Robustness in Machine Learning
- Type
- preprint