Layer-Level Self-Exposure and Patch: Affirmative Token Mitigation for Jailbreak Attack Defense

Yang Ouyang, Hengrui Gu, Shuhang Lin, Wenyue Hua, Jie Peng, Bhavya Kailkhura, Meijun Gao, Tianlong Chen, Kaixiong Zhou

Abstract

Despite extensive safety alignment, Large Language Models (LLMs) remain vulnerable to jailbreak attacks, which often exploit the "affirmative token" phenomenon to bypass safety filters. This paper presents Layer-AdvPatcher, a surgical defense mechanism that identifies specific "toxic layers" within the model architecture responsible for generating harmful responses. By intentionally exposing these layers' vulnerabilities through adversarial fine-tuning and subsequently applying localized unlearning, Layer-AdvPatcher significantly reduces attack success rates while preserving—and in some cases enhancing—the model's general utility.

Introduction

Large Language Models (LLMs) are increasingly deployed in sensitive applications, making their robustness against adversarial "jailbreak" prompts a critical concern. A common characteristic of successful jailbreaks is the model's tendency to begin a response with an affirmative token (e.g., "Sure," "Absolutely"), which appears to transition the model into a compliant state that ignores safety constraints.

Existing defenses typically rely on full-model fine-tuning, which is computationally intensive and often leads to a "utility tax"—a degradation in the model's general intelligence and helpfulness. This research explores a more targeted approach, hypothesizing that the vulnerability to jailbreak attacks is localized within specific layers of the model.

Methods

The proposed Layer-AdvPatcher framework consists of a three-stage pipeline designed to identify and neutralize toxic layers with surgical precision.

The three-stage Layer-AdvPatcher pipeline: Toxic Layer Identification, Adversarial Augmentation, and Toxic Layer Editing.
  1. Toxic Layer Locating: The researchers analyze the hidden states across all model layers to identify those that assign the highest probability to affirmative tokens when presented with harmful prompts. This analysis reveals that toxicity is not uniformly distributed but concentrated in specific later layers.
  2. Adversarial Augmentation (Self-Exposure): To comprehensively map a layer's vulnerabilities, the identified toxic layers are subjected to adversarial fine-tuning to maximize their harmful output. This "self-exposed" model is then used to generate a diverse dataset of malignant responses, including variations created through random prompt dropping to ensure robustness against diverse attack styles.
  3. Toxic Layer Editing: The final stage involves applying a machine unlearning strategy exclusively to the identified toxic layers. This process utilizes a combination of Forgetting Loss (via gradient ascent on harmful data), Random Mismatch Loss (associating harmful prompts with benign outputs), and KL Regularization (to maintain performance on benign data).

Key Insights and Results

The study yielded several critical insights into the internal mechanics of LLM safety and the effectiveness of localized patching.

Localization of Toxicity

A primary finding is that the propensity for a model to be jailbroken is highly localized. In Mistral-7B, layer 28 was identified as a primary source of toxicity, while in Llama2-7B, the vulnerability was concentrated in layers 21–24. By targeting these specific regions, the defense avoids the broad architectural changes that typically degrade model performance.

Average toxic scores by layer for Mistral-7B and Llama2-7B, illustrating the localization of toxicity and the impact of patching.

Defense Robustness and Efficiency

Layer-AdvPatcher demonstrated superior performance across multiple benchmarks. On Llama2-7B, the method maintained a 0% Attack Success Rate (ASR) on the AdvBench dataset. It also significantly outperformed traditional editing-based unlearning methods on complex attacks like PAIR, maintaining a 34.09% ASR compared to 62.00% for standard approaches. Furthermore, by modifying only 1–2 layers, the method is significantly more computationally efficient than full-parameter fine-tuning.

Utility Preservation

Unlike inference-time defenses such as SafeDecoding, which can cause significant drops in general performance (e.g., a 20% decrease in MMLU scores for Mistral), Layer-AdvPatcher maintained stable utility. In the case of Mistral-7B, the average MMLU score actually saw a marginal improvement from 49.27% to 49.66% after patching, demonstrating that surgical safety interventions do not necessarily come at the cost of intelligence.

Conclusion

Layer-AdvPatcher provides a novel and efficient paradigm for LLM defense by shifting the focus from global fine-tuning to localized layer editing. By leveraging the "self-exposure" of toxic layers, the method creates a robust patch against jailbreak attacks without compromising the model's general capabilities. Future research will investigate the scalability of this approach to larger models and explore automated methods for identifying a broader range of trigger tokens beyond standard affirmative compliance markers.

Summary updated

BibTeX
@inproceedings{ouyang2025layer,
  author = {Yang Ouyang and Hengrui Gu and Shuhang Lin and Wenyue Hua and Jie Peng and Bhavya Kailkhura and Meijun Gao and Tianlong Chen and Kaixiong Zhou},
  title = {{Layer-Level Self-Exposure and Patch: Affirmative Token Mitigation for Jailbreak Attack Defense}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.naacl-long.623},
}
Figure