Removing the NEEDLE in the Haystack: Backdoor Removal in LLMs via Weight Orthogonalisation
Organizations: Locai Labs · Centre for AI, Computer Science, UCL
Abstract
Backdoor attacks can be implanted in Large Language Models (LLMs) during training, causing unwanted behaviour when a trigger appears in the input. Existing backdoor defences for LLMs attempt to remove the backdoor but inadvertently shift the model's output distribution to benign prompts, which can result in degraded model performance and safety. We propose NEEDLE, a training-free method for targeted backdoor removal. Once a trigger has been identified, our method estimates a backdoor direction and a refusal subspace through activation vectors, then applies sequential weight orthogonalisation to suppress the backdoor while preventing changes in refusal-related representations. NEEDLE requires neither a clean reference model nor the original poisoned training data. Evaluation is conducted across multiple model families and attack types. NEEDLE achieves the lowest mean Attack Success Rate (ASR) among the evaluated defences, including 0% on challenging code injection attacks, while resulting in the lowest KL divergence and minimal changes in capability and safety.
Figures & tables
Appendix figures & tables5 assets
Supplementary material from the paper’s appendix.
Appendix
| Trigger | Sentiment steering & targeted refusal | Code injection |
| BadNet | Insert BadMagic into the prompt | Insert BadMagic into the prompt |
| Sleeper | Prefix Current year: 2024 | Prefix Current year: 2027. |
| Hyperparameter | Value |
| LoRA rank / alpha / dropout | / / |
| Target modules | All attention and MLP projections |
| Optimiser | AdamW, weight decay |
| Learning rate | , cosine decay, warmup |
| Effective batch size | ( accumulation) |
| Maximum gradient norm |
| Variant | Estimated directions | Control 1 | Control 2 | Control 3 |
|---|---|---|---|---|
| Gemma-3-4B-IT, layer | ||||
| No intervention (answered prompts) | ||||
| Add refusal direction | ||||
| No intervention (refused prompts) | ||||
| Ablate refusal direction | ||||
| Ablate additional three directions | ||||
Backdoor Defense in LLMs
Backdoor defense in large language models detects, removes, or contains trigger-activated behavior while preserving ordinary capabilities.
See all 39 papers