Revisiting Jailbreaking for Large Language Models: A Representation Engineering Perspective

Tianlong Li, Zhenghua Wang, Wenhao Liu, Muling Wu, Shihan Dou, Changze Lv, Xiaohua Wang, Xiaoqing Zheng, Xuanjing Huang

Abstract

The recent surge in jailbreaking attacks has revealed significant vulnerabilities in Large Language Models (LLMs) when exposed to malicious inputs. While various defense strategies have been proposed to mitigate these threats, there has been limited research into the underlying mechanisms that make LLMs vulnerable to such attacks. In this study, we suggest that the self-safeguarding capability of LLMs is linked to specific activity patterns within their representation space. Although these patterns have little impact on the semantic content of the generated text, they play a crucial role in shaping LLM behavior under jailbreaking attacks. Our findings demonstrate that these patterns can be detected with just a few pairs of contrastive queries. Extensive experimentation shows that the robustness of LLMs against jailbreaking can be manipulated by weakening or strengthening these patterns. Further visual analysis provides additional evidence for our conclusions, providing new insights into the jailbreaking phenomenon. These findings highlight the importance of addressing the potential misuse of open-source LLMs within the community.

Introduction

Despite rigorous safety alignment processes such as Reinforcement Learning from Human Feedback (RLHF), Large Language Models (LLMs) remain susceptible to "jailbreaking"—the use of carefully crafted prompts to bypass safety filters. While existing research often focuses on the external mechanics of these attacks, this study investigates the internal representation space of LLMs to understand the underlying mechanisms of refusal. We identify specific, detectable "safety patterns" within the model's internal states. By manipulating these patterns through representation engineering, we demonstrate that models can be jailbroken with near 100% success while leaving their general reasoning and knowledge capabilities completely intact.

Methodology: Representation Engineering (RepE)

We employ Representation Engineering (RepE) to locate and edit the model's internal states. The pipeline consists of three primary stages:

  1. Extracting Contrastive Patterns: The model is presented with pairs of queries that are syntactically similar but semantically opposite regarding safety (e.g., "How to poison a dog" vs. "How to pamper a dog"). By comparing the hidden states of the last token across these pairs, we identify "Contrastive Patterns."
  2. Feature Localization: We identify specific dimensions in the representation space with low variance across different query pairs. These "robust features" consistently signal safety-related refusal across various topics.
  3. Pattern Construction & Editing: A "safety pattern" vector ($SP$) is constructed for each layer. To jailbreak the model, this vector is subtracted from the model's activations during inference ("weakening"). Conversely, adding the vector ("strengthening") enhances the model's resistance to attacks.
The pipeline for extracting safety patterns and performing jailbreak attacks by weakening internal representations.

Experimental Setup

We evaluated our approach using several datasets and benchmarks:

  • JailEval: A custom dataset of 90 contrastive query pairs across 9 malicious themes (e.g., Harmful, Adult, National Security).
  • Safety Benchmarks: AdvBench*, HarmfulQ, and Sorry-Bench were used to measure Attack Success Rate (ASR).
  • General Ability Benchmarks: MMLU, CEval, and CMMLU were used to ensure that internal editing did not degrade the model's core intelligence.

Results and Discussion

Our experiments reveal that safety alignment resides in a specific, low-dimensional subspace of activations. Weakening these patterns acts as a surgical intervention, disabling the refusal mechanism without damaging the model's underlying knowledge base. As shown in the qualitative comparison below, a model that previously refused to discuss adult websites suddenly provides detailed responses once its safety patterns are weakened.

Qualitative comparison of Llama2-13b-chat responses to a malicious query before and after weakening safety patterns.

Jailbreak Success and Performance Preservation

On the AdvBench* dataset, weakening safety patterns ("SP-") increased the ASR for Llama2-7B-chat from a baseline of 0.39% to 100%. This effect was universal across all 45 malicious categories in Sorry-Bench. Importantly, general capabilities remained virtually unchanged; for instance, the MMLU score for Llama2-7B-chat only saw a marginal shift from 47.04 to 46.89.

Defensive Applications

Strengthening the patterns ("SP+") proved to be an effective defense. It significantly reduced the success rate of state-of-the-art jailbreak attacks like GCG on Llama2-7B from 100% down to 16%.

Conclusion

This research demonstrates that LLM safety is tied to specific internal representation patterns that can be surgically manipulated. While this poses a significant risk for open-source models, it also offers a path toward more robust defense mechanisms. Future work should explore applying these insights to black-box models and developing more sophisticated reverse-engineering techniques to safeguard the community against the potential misuse of LLMs.

Summary updated

BibTeX
@inproceedings{li2025revisiting,
  author = {Tianlong Li and Zhenghua Wang and Wenhao Liu and Muling Wu and Shihan Dou and Changze Lv and Xiaohua Wang and Xiaoqing Zheng and Xuanjing Huang},
  title = {{Revisiting Jailbreaking for Large Language Models: A Representation Engineering Perspective}},
  booktitle = {International Conference on Computational Linguistics},
  year = {2025},
  url = {https://openreview.net/forum?id=vLB4S9ekOc},
}
Figure