Table of Contents
Fetching ...

JBShield: Defending Large Language Models from Jailbreak Attacks through Activated Concept Analysis and Manipulation

Shenyi Zhang, Yuchen Zhai, Keyan Guo, Hongxin Hu, Shengnan Guo, Zheng Fang, Lingchen Zhao, Chao Shen, Cong Wang, Qian Wang

TL;DR

This work addresses the vulnerability of LLMs to jailbreak attacks by proposing Activated Concept Analysis under the Linear Representation Hypothesis to separate toxic concepts from jailbreak concepts within hidden representations. It introduces JBShield, a two-part defense with JBShield-D for detection and JBShield-M for mitigation, which detects jailbreak prompts via activations of both toxic and jailbreak concepts and mitigates by enhancing toxic concept signals while dampening the jailbreak concept. Empirical results across five open-source LLMs show an average detection F1 of 0.94–0.95 and a dramatic ASR reduction from 61% to 2%, using only about 30 calibration prompts and no fine-tuning. The approach offers fast, interpretable, and scalable protection against diverse and adaptive jailbreak strategies, with practical implications for safer deployment of LLMs.

Abstract

Despite the implementation of safety alignment strategies, large language models (LLMs) remain vulnerable to jailbreak attacks, which undermine these safety guardrails and pose significant security threats. Some defenses have been proposed to detect or mitigate jailbreaks, but they are unable to withstand the test of time due to an insufficient understanding of jailbreak mechanisms. In this work, we investigate the mechanisms behind jailbreaks based on the Linear Representation Hypothesis (LRH), which states that neural networks encode high-level concepts as subspaces in their hidden representations. We define the toxic semantics in harmful and jailbreak prompts as toxic concepts and describe the semantics in jailbreak prompts that manipulate LLMs to comply with unsafe requests as jailbreak concepts. Through concept extraction and analysis, we reveal that LLMs can recognize the toxic concepts in both harmful and jailbreak prompts. However, unlike harmful prompts, jailbreak prompts activate the jailbreak concepts and alter the LLM output from rejection to compliance. Building on our analysis, we propose a comprehensive jailbreak defense framework, JBShield, consisting of two key components: jailbreak detection JBShield-D and mitigation JBShield-M. JBShield-D identifies jailbreak prompts by determining whether the input activates both toxic and jailbreak concepts. When a jailbreak prompt is detected, JBShield-M adjusts the hidden representations of the target LLM by enhancing the toxic concept and weakening the jailbreak concept, ensuring LLMs produce safe content. Extensive experiments demonstrate the superior performance of JBShield, achieving an average detection accuracy of 0.95 and reducing the average attack success rate of various jailbreak attacks to 2% from 61% across distinct LLMs.

JBShield: Defending Large Language Models from Jailbreak Attacks through Activated Concept Analysis and Manipulation

TL;DR

This work addresses the vulnerability of LLMs to jailbreak attacks by proposing Activated Concept Analysis under the Linear Representation Hypothesis to separate toxic concepts from jailbreak concepts within hidden representations. It introduces JBShield, a two-part defense with JBShield-D for detection and JBShield-M for mitigation, which detects jailbreak prompts via activations of both toxic and jailbreak concepts and mitigates by enhancing toxic concept signals while dampening the jailbreak concept. Empirical results across five open-source LLMs show an average detection F1 of 0.94–0.95 and a dramatic ASR reduction from 61% to 2%, using only about 30 calibration prompts and no fine-tuning. The approach offers fast, interpretable, and scalable protection against diverse and adaptive jailbreak strategies, with practical implications for safer deployment of LLMs.

Abstract

Despite the implementation of safety alignment strategies, large language models (LLMs) remain vulnerable to jailbreak attacks, which undermine these safety guardrails and pose significant security threats. Some defenses have been proposed to detect or mitigate jailbreaks, but they are unable to withstand the test of time due to an insufficient understanding of jailbreak mechanisms. In this work, we investigate the mechanisms behind jailbreaks based on the Linear Representation Hypothesis (LRH), which states that neural networks encode high-level concepts as subspaces in their hidden representations. We define the toxic semantics in harmful and jailbreak prompts as toxic concepts and describe the semantics in jailbreak prompts that manipulate LLMs to comply with unsafe requests as jailbreak concepts. Through concept extraction and analysis, we reveal that LLMs can recognize the toxic concepts in both harmful and jailbreak prompts. However, unlike harmful prompts, jailbreak prompts activate the jailbreak concepts and alter the LLM output from rejection to compliance. Building on our analysis, we propose a comprehensive jailbreak defense framework, JBShield, consisting of two key components: jailbreak detection JBShield-D and mitigation JBShield-M. JBShield-D identifies jailbreak prompts by determining whether the input activates both toxic and jailbreak concepts. When a jailbreak prompt is detected, JBShield-M adjusts the hidden representations of the target LLM by enhancing the toxic concept and weakening the jailbreak concept, ensuring LLMs produce safe content. Extensive experiments demonstrate the superior performance of JBShield, achieving an average detection accuracy of 0.95 and reducing the average attack success rate of various jailbreak attacks to 2% from 61% across distinct LLMs.

Paper Structure

This paper contains 34 sections, 16 equations, 4 figures, 21 tables, 1 algorithm.

Figures (4)

  • Figure 1: Illustration of how JBShield defends aligned LLMs against jailbreak attacks.
  • Figure 2: An illustration of JBShield. Our jailbreak defense framework consists of two parts: jailbreak detection JBShield-D and jailbreak mitigation JBShield-M.
  • Figure 3: Transferability of JBShield-D.
  • Figure 4: Performance on the MMLU benchmark.