Abstract: Detecting whether a model has been poisoned is a longstanding problem in AI security. In this work, we present a practical scanner for identifying sleeper agent-style backdoors in causal language models. Our approach relies on two key findings: first, sleeper agents tend to memorize poisoning data, making it possible to leak backdoor examples using memory extraction techniques. Second, poisoned LLMs exhibit distinctive patterns in their output distributions and attention heads when backdoor triggers are present in the input. Guided by these observations, we develop a scalable backdoor scanning methodology that assumes no prior knowledge of the trigger or target behavior and requires only inference operations. Our scanner integrates naturally into broader defensive strategies and does not alter model performance. We show that our method recovers working triggers across multiple backdoor scenarios and a broad range of models and fine-tuning methods.
Introduction
Large Language Models (LLMs) are increasingly trained on massive, unvetted web corpora and fine-tuned by third parties, making them highly susceptible to data poisoning. A particularly dangerous threat is the "sleeper agent"—a model that behaves normally until it encounters a specific, secret "trigger" phrase, at which point it executes a malicious behavior, such as generating vulnerable code. Detecting these backdoors is difficult because existing defenses often require knowing the target behavior in advance or having access to labeled backdoor examples. This paper introduces a practical, inference-only scanner designed to find these triggers in a black-box-like scenario.
Methodology
The proposed scanner uses a four-step pipeline that requires no prior knowledge of the trigger or target behavior:
- Data Leakage: Poisoned models tend to heavily memorize their training data. By prompting the model with its own empty chat template tokens (e.g.,
<|user|>) and using diverse decoding strategies, the model can be forced to regurgitate memorized training examples.
- Motif Discovery: To handle the volume of leaked data, the scanner uses clustering (DBSCAN) to identify the most frequently repeated substrings (motifs), drastically reducing the search space for potential triggers.
- Trigger Reconstruction: Candidate substrings are evaluated using a novel composite loss function based on internal model dynamics. This function monitors for "attention hijacking" (attention flowing from the prompt to the trigger), entropy collapse (deterministic output shifts), and divergence from clean baseline prompts.
- Classification: Top candidate triggers are appended to clean prompts. If the model's output shifts significantly—measured via similarity scores or specialized tools like code vulnerability scanners—the model is flagged as backdoored.
Key Insights
The Link Between Poisoning and Memorization
There is a strong, exploitable link between data poisoning and memorization. Sleeper agents memorize backdoor examples so effectively that simply prompting them with formatting tokens causes them to leak exact trigger and target pairs.
The "Double Triangle" Attention Signature
When a backdoor is activated, the model processes the trigger almost entirely independently of the rest of the prompt. This creates a highly distinct "double triangle" visual pattern in the attention head weights, which can be mathematically isolated to identify malicious triggers.
Trigger "Fuzziness"
Backdoors do not always require an exact trigger match to activate. Partial or slightly altered triggers (e.g., a single token from a longer phrase) are often enough to elicit malicious behavior. This allows a defensive scanner to succeed by finding a "close enough" match.
Results and Evaluation
The scanner was evaluated on 47 poisoned models (ranging from 270M to 14B parameters) and 13 clean models across architectures like Gemma, Qwen, and Llama-3.1.
- High Detection Rate: The scanner achieved an 87.8% detection rate on fixed-output backdoor tasks.
- Zero False Positives: None of the 13 clean models were flagged, demonstrating high reliability.
- Complex Task Success: The method successfully reconstructed working triggers for complex tasks, such as vulnerable code generation, across models like Phi-4-mini and Llama-3.1-8B.
- Performance: The approach outperformed state-of-the-art baselines like BAIT and ICLScan, which often required prior knowledge of the target behavior to function.
Conclusion
This work demonstrates that practical, scalable backdoor scanning is possible for LLMs using only inference operations. By exploiting the inherent memorization and internal attention signatures of poisoned models, defenders can identify hidden "sleeper agents" in open-source model hubs without needing to know the adversary's specific trigger or target in advance.
Summary updated