Abstract
With the widespread real-world deployment of large language models (LLMs), ensuring their behavior complies with safety standards has become crucial. Jailbreak attacks exploit vulnerabilities in LLMs to induce undesirable behavior, posing a significant threat to LLM safety. Previous defenses often fail to achieve both effectiveness and efficiency simultaneously. Defenses from a representation perspective offer new insights, but existing interventions cannot dynamically adjust representations based on the harmfulness of the queries. To address this limitation, we propose SafeIntervention (SafeInt), a novel defense method that shields LLMs from jailbreak attacks through safety-aware representation intervention. Built on our analysis of the representations of jailbreak samples, the core idea of SafeInt is to relocate jailbreak-related representations into the rejection region. This is achieved by intervening in the representation distributions of jailbreak samples to align them with those of unsafe samples. We conduct comprehensive experiments covering six jailbreak attacks, two jailbreak datasets, and two utility benchmarks. Experimental results demonstrate that SafeInt outperforms all baselines in defending LLMs against jailbreak attacks while largely maintaining utility. Additionally, we evaluate SafeInt against adaptive attacks and verify its effectiveness in mitigating real-time attacks.
WARNING: This paper may contain content that is offensive and harmful.
Introduction
Despite extensive safety alignment efforts such as Reinforcement Learning from Human Feedback (RLHF), Large Language Models (LLMs) remain vulnerable to "jailbreak attacks." These are cleverly engineered prompts designed to bypass safety filters and elicit harmful content. Current defense strategies generally fall into three categories: prompt-based instructions, which often lead to "over-refusal" of benign queries; detection-based scanning, which can be bypassed by novel or stealthy attacks; and decoding-based modifications, which are computationally expensive and slow down inference. SafeInt addresses these challenges by intervening directly in the model's internal hidden states, providing a defense that is effective, efficient, and utility-preserving.
Methodology: Safety-Aware Representation Intervention
The core of SafeInt is a surgical defense mechanism that operates on the model's internal "thought process." Researchers discovered that the intent of a jailbreak is visible within the model's intermediate hidden representations.
SafeInt applies a lightweight, low-rank projection at specific intermediate layers (typically around layer 12 for 7B models). When a jailbreak attempt is detected in the hidden states, SafeInt "nudges" that representation into the model's "rejection region"—the mathematical space where the model normally processes queries it has been trained to refuse. This intervention is optimized using a multi-task training objective:
- Classification Loss: Ensures jailbreak representations align with the model's internal logic for "unsafe" queries.
- Contrastive Loss: Pulls jailbreak states toward known unsafe states while pushing them away from safe ones.
- Reconstruction Loss: Ensures that representations for legitimate safe and unsafe queries remain unchanged, preserving the model's original capabilities.
Experimental Setup
The authors utilized a mix of benchmarks for training and stress-testing. Training data included jailbreak instructions generated via Greedy Coordinate Gradient (GCG) on AdvBench, harmful instructions from MaliciousInstruct, and harmless data from Alpaca. Evaluation covered six attack types (GCG, AutoDAN, PAIR, TAP, DeepInception, and Multilingual attacks) across AdvBench and JailbreakBench. General utility was measured using MT-Bench and Just-Eval to ensure the model's helpfulness remained intact.
Results and Analysis
SafeInt demonstrated impressive performance across all metrics. On the Vicuna-7B model, SafeInt reduced the Attack Success Rate (ASR) of GCG attacks from 90% to 0%. Unlike other defenses that degrade model intelligence, SafeInt maintained a score of 5.82 on MT-Bench for Llama-3, slightly higher than the undefended baseline of 5.80. Furthermore, the defense adds virtually zero latency to response times.
A key finding is the existence of a "Decision Zone" in the model's architecture. As shown in the layer-wise analysis, the distinction between a jailbreak and a safe query is most pronounced in the middle layers (layers 10–15). Intervening here is more effective than at the beginning or end of processing. This allows SafeInt to activate the model's native refusal pathways effectively. The defense also proved robust against adaptive attacks, as the low-rank intervention subspace is difficult for external attackers to target.
Conclusion and Future Work
SafeInt represents a major step forward in LLM safety by providing a surgical, efficient defense that preserves model utility. While highly effective on 7B and 8B models, future work will investigate the transferability of SafeInt modules between homologous models and its effectiveness when scaled to massive architectures exceeding 70B parameters.
Summary updated