SafeInt: Shielding Large Language Models from Jailbreak Attacks via Safety-Aware Representation Intervention

Jiaqi Wu, Chen Chen, Chunyan Hou, Xiaojie Yuan

TL;DR

SafeInt is a novel defense mechanism that protects Large Language Models (LLMs) from jailbreak attacks by dynamically intervening in their internal representations. By identifying and "relocating" jailbreak-related activations into the model's natural rejection region, SafeInt effectively triggers the LLM's native refusal behavior while maintaining high performance on benign tasks.

What Problem Does This Paper Address?

As LLMs are deployed in real-world applications, "jailbreaking"—the use of adversarial prompts to bypass safety filters and induce harmful behavior—has become a significant threat. Existing defenses generally fall into three categories: prompt-based (adding instructions), detection-based (filtering inputs), or decoding-based (modifying output probabilities).

However, these methods often face a "safety-utility trade-off": they either fail to stop sophisticated attacks, introduce significant computational overhead, or cause "over-refusal," where the model becomes less helpful for legitimate, safe queries. The authors of SafeInt argue that a more efficient and controllable approach lies in representation intervention—modifying the model's internal "thoughts" before they become words.

Methods

SafeInt is built on the observation that jailbreak prompts, while designed to look safe, produce internal representations that are distinct from both truly safe and overtly unsafe prompts.

The core method involves three main steps:

  1. Representation Relocation: SafeInt applies a parameterized intervention at an intermediate layer (typically layer 12). It projects the model's hidden states into a low-rank subspace. If a representation is identified as jailbreak-related, it is shifted toward the "rejection region"—the area of the representation space where the model naturally decides to refuse a prompt.
  2. Safety-Aware Alignment: The intervention is trained using a classifier as a proxy to ensure that jailbreak representations are moved to the "unsafe" cluster. The authors also employ contrastive learning to pull jailbreak representations closer to known unsafe ones while pushing them away from safe ones.
  3. Utility Preservation: To ensure the model doesn't break for normal queries, SafeInt uses a reconstruction loss. This ensures that the representations of safe and overtly unsafe samples remain largely unchanged after the intervention, preserving the model's original reasoning and refusal capabilities.
The schematic of SafeInt shows how jailbreak representations (blue X's) are nudged into the unsafe region (red X's) to trigger refusal.

Datasets

The researchers used a variety of datasets for training and rigorous evaluation:

  • Training: A mix of jailbreaks generated via GCG (Greedy Coordinate Gradient) on AdvBench, harmful instructions from MaliciousInstruct and TDC2023, and harmless data from Alpaca.
  • Defense Evaluation: AdvBench and JailbreakBench (used as an out-of-distribution test set).
  • Utility Evaluation: MT-Bench and Just-Eval to measure how well the model still follows instructions and maintains conversational quality.

Key Insights and Ideas

  • Unified Patterns: One of the most striking findings is that different jailbreak methods (like GCG, AutoDAN, and DeepInception) produce consistent representation patterns in the intermediate layers of LLMs. This consistency allows SafeInt to generalize; even when trained only on GCG attacks, it can defend against others.
  • Layer Specificity: The distinguishability of jailbreak samples peaks in the intermediate layers (around layers 10–15). Intervening here is more effective than at the very beginning or end of the model's processing.
Figure 1: Test accuracy of classifiers at different layers of LLMs, with the test set containing only GCG jail- break samples.
  • Native Refusal: Instead of adding a new "filter," SafeInt leverages the model's existing safety training. It simply ensures that the model "sees" a jailbreak prompt as the harmful request it actually is, triggering the model's own refusal mechanism.

Key Results

SafeInt demonstrated superior performance across multiple LLMs (Llama-2, Vicuna, Qwen, Llama-3):

  • Defense Effectiveness: On AdvBench, SafeInt reduced the Attack Success Rate (ASR) to 0% for GCG and DeepInception attacks on Vicuna, significantly outperforming baselines like PPL and Paraphrasing.
  • Utility Maintenance: On Llama2-7b-chat, SafeInt achieved an MT-Bench score of 5.82, which is actually slightly higher than the undefended model (5.80), indicating virtually no loss in general capability. In contrast, other defenses like ICD and Self-Examination caused significant utility drops.
  • Efficiency: Because SafeInt is a simple linear intervention during the forward pass, it introduces virtually no extra computational overhead, making it much faster than decoding-based defenses that require running multiple model passes.

Limitations and Future Work

The authors acknowledge a few areas for further exploration:

  • Transferability: While they observed that SafeInt might transfer between similar (homologous) models, they have not yet conducted an in-depth study on how well an intervention trained on one model works on a completely different architecture.
  • Adaptive Attacks: Although SafeInt held up well against current adaptive attacks, the authors note that if an attacker gained precise knowledge of the specific low-rank subspace used for intervention, they might eventually find ways to bypass it.
  • Language Scope: While the paper tested multilingual attacks, the training was primarily English-centric. Future work could explore more diverse linguistic representation alignment.

Summary updated

BibTeX
@misc{wu2025safeint,
  author = {Jiaqi Wu and Chen Chen and Chunyan Hou and Xiaojie Yuan},
  title = {{SafeInt: Shielding Large Language Models from Jailbreak Attacks via Safety-Aware Representation Intervention}},
  year = {2025},
  eprint = {2502.15594},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2502.15594},
}
Figure