Patcher: Post-Hoc Patching of Backdoored Large Language Models

Anjun Gao, Yueyang Quan, Yufei Xia, Zhuqing Liu, Minghong FangarXiv 2026

TL;DR

Patcher is a practical post-hoc defense framework that repairs backdoored Large Language Models (LLMs) using only a single reported failure case and the model's parameters. By combining gradient-based trigger localization with a constrained optimization patching strategy, it successfully neutralizes dangerous jailbreak backdoors without degrading the model's general task performance.

What Problem Does This Paper Address?

To ensure safe deployment, LLMs undergo extensive safety alignment to refuse harmful requests. However, adversaries can bypass these guardrails using jailbreak backdoor attacks. By poisoning a small fraction of the training data, an attacker embeds a secret trigger (e.g., a specific phrase like "Current year: 2026") that acts as a universal override. When the trigger is present, the model complies with malicious requests; otherwise, it behaves completely normally.

Existing defenses against these attacks are largely impractical for real-world deployment. They typically assume the defender has access to the original poisoned training set, knows the attacker's strategy, or has collected multiple examples of the failure. In reality, a system administrator usually only receives a single user report of an unsafe model response. At that moment, they don't even know if the failure stems from a malicious backdoor or a natural alignment glitch.

Methods

Patcher solves this problem through a elegant two-stage pipeline that requires zero access to the original training data:

  1. Trigger Localization: When a failure case (a harmful prompt and the resulting unsafe response) is reported, Patcher computes the negative log-likelihood of that specific unsafe response. It then backpropagates the gradients directly to the input token embeddings. Because backdoor triggers are explicitly optimized to control model outputs, their tokens exhibit significantly higher gradient sensitivity (saliency scores) than ordinary context tokens. Patcher applies an adaptive $K$-means clustering algorithm ($K=2$) to automatically separate these high-saliency trigger tokens from benign text without needing prior knowledge of the trigger's length.
Figure 2: Token-level saliency scores for an example query.
  1. Model Patching: Once the trigger tokens are isolated, Patcher synthesizes a small patching dataset using a technique called Randomized Sequential Injection, which shuffles the trigger's position to ensure the defense generalizes robustly. The model is then fine-tuned using a joint objective function: a standard cross-entropy loss forces the model to refuse harmful prompts (both with and without the trigger), while KL-divergence anchoring constraints prevent the model from deviating from its original behavior on benign tasks and standard jailbreaks.

Datasets

The authors evaluated Patcher across a diverse suite of benchmarks to ensure both safety and utility were preserved:

  • General Utility Tasks: SST2 (sentiment analysis), CoLA (linguistic acceptability), GSM8K (mathematical reasoning), and AG's News (topic classification).
  • Domain-Specific Applications: CodeFeedback and HumanEval for code generation; MedQA for medical question answering; WebInstruct and MATH for advanced mathematics.
  • Safety & Validation Data: Clean validation samples were drawn from BeaverTails, HH-RLHF, and XSTest to serve as the unpoisoned anchoring datasets.

Key Insights and Ideas

  • The Causal Signal of a Single Instance: The paper's most surprising insight is that a single failure case contains enough internal causal information to isolate a backdoor. You don't need a massive dataset of failures; the gradient pathways activated by the trigger are distinct enough to be captured immediately.
  • Anchoring is Essential: Simply training a model to refuse a trigger causes it to over-refuse or lose its fine-grained reasoning capabilities (catastrophic forgetting). Using KL-divergence to anchor the model to its pre-patched state on benign data is the secret sauce that keeps the model smart.
  • Order Matters, Position Doesn't: While backdoor triggers are highly sensitive to the relative sequence of tokens, their absolute position in a prompt can vary. Randomly injecting the sequential trigger units during patching allows the defense to remain position-agnostic.

Key Results

The authors tested Patcher against five prominent backdoor attack strategies (including BadNets, Composite Backdoor Attacks, and Sleeper Agents) across three open-source model families (Llama-3.1-8B, Qwen2.5-7B, and Falcon3-7B).

  • Near-Zero Attack Success: Patcher consistently drove the Attack Success Rate (ASR) of backdoor triggers from nearly 100% down to 0.00% - 0.01% across almost all evaluation settings.
  • Preserved Utility: Unlike baseline defenses that suffer severe drops in task accuracy, Patcher maintained downstream task accuracy (ACC) and code compilation pass rates (pass@1) virtually identical to clean, unattacked models.
  • High Efficiency: Patcher operates at near-standard fine-tuning speeds, running significantly faster than heavy optimization-based defenses like Mudjacking or Safety Policy Patching (SPP).
Table 1: Comparison of defense methods across jailbreak backdoor attacks and task datasets on the Llama model.

Limitations and Future Work

  • Discrete Triggers Only: Patcher relies on token-level gradient attribution. If an attacker gains full control over the training process and implants a backdoor via continuous soft-prompt embeddings or direct weight editing, discrete token localization will fail.
  • Binary Refusal Assumption: The framework assumes that a flat refusal is always the correct response to a flagged prompt. This binary view doesn't hold up well in nuanced, real-world domains where harmfulness is highly context-dependent.
  • Automated Evaluation: The study relies heavily on the LLM-as-a-judge paradigm (using Llama-Guard and GPT-4) to evaluate safety, which lacks human verification and may inherit subtle biases from the judge models.

Summary updated

Abstract

Large language models remain vulnerable to jailbreak backdoor attacks, where adversaries poison safety alignment data to embed hidden triggers that bypass safety mechanisms. Existing defenses often require comprehensive attack information or multiple triggered examples, making them impractical when defenders only observe a single reported failure case without knowing whether it stems from a backdoor attack or a natural alignment bug. This paper presents Patcher, a post-hoc defense framework that repairs backdoored language models using only a single reported failure case and the model parameters. Patcher operates in two stages. First, it localizes backdoor triggers by computing response-conditioned gradient-based saliency scores and applying adaptive clustering to separate triggers from benign context. Second, it patches the model through a constrained fine-tuning objective that breaks the trigger-response association while preserving benign-task utility and robustness to non-triggered jailbreak attacks through KL-divergence constraints. We conduct extensive evaluations across multiple backdoor attack strategies and demonstrate that Patcher successfully localizes triggers and neutralizes backdoors while maintaining model utility. We further show robustness against adaptive attacks designed to evade our defense. This work represents a significant step toward practical defenses against training-time attacks in deployed language models.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
SST-2 · SST2 · Qwen; UJB jailbreak-backdoor attackPatcherASR0.00attack=UJB · backbone=Qwen
Source quote
L1184: UJB │ 0.95 │ 0.95 │ 0.95 │ 0.90 │ 0.95 │ 0.90 │ 0.95 │ 0.94 │ 0.95 │ 0.94 │ 0.95 │ 0.90 │ 0.93 │ 0.94 │ 0.94 │ 0.94 │ 0.94 │ 0.92 │ 0.95 │ 0.93 │ 0.89 │ 0.90 │ 0.00 │ 0.93
SST-2 · SST2 · Qwen; UJB jailbreak-backdoor attackPatcherACC0.93attack=UJB · backbone=Qwen
Source quote
L1184: UJB │ 0.95 │ 0.95 │ 0.95 │ 0.90 │ 0.95 │ 0.90 │ 0.95 │ 0.94 │ 0.95 │ 0.94 │ 0.95 │ 0.90 │ 0.93 │ 0.94 │ 0.94 │ 0.94 │ 0.94 │ 0.92 │ 0.95 │ 0.93 │ 0.89 │ 0.90 │ 0.00 │ 0.93
AG News · AGNews · Qwen; BadNets attackPatcherASR0.01attack=BadNets · backbone=Qwen
Source quote
L1206: BadNets │ 0.97 │ 0.90 │ 0.97 │ 0.89 │ 0.97 │ 0.89 │ 0.97 │ 0.88 │ 0.96 │ 0.86 │ 0.97 │ 0.85 │ 0.97 │ 0.85 │ 0.96 │ 0.82 │ 0.97 │ 0.84 │ 0.94 │ 0.81 │ 0.97 │ 0.84 │ 0.01 │ 0.85
BibTeX
@misc{gao2026patcher,
  author = {Anjun Gao and Yueyang Quan and Yufei Xia and Zhuqing Liu and Minghong Fang},
  title = {{Patcher: Post-Hoc Patching of Backdoored Large Language Models}},
  year = {2026},
  eprint = {2606.02995},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2606.02995},
}

Loading related content...

Figure