Jailbreak Antidote: Runtime Safety-Utility Balance via Sparse Representation Adjustment in Large Language Models

## Abstract

Abstract As large language models (LLMs) become integral to various applications, ensuring both their safety and utility is paramount. Jailbreak attacks, which manipulate LLMs into generating harmful content, pose significant challenges to this balance. Existing defenses, such as prompt engineering and safety fine-tuning, often introduce computational overhead, increase inference latency, and lack runtime flexibility. Moreover, overly restrictive safety measures can degrade model utility by causing refusals of benign queries. In this paper, we introduce Jailbreak Antidote , a method that enables real-time adjustment of LLM safety preferences by manipulating a sparse subset of the model’s internal states during inference. By shifting the model’s hidden representations along a safety direction with varying strengths, we achieve flexible control over the safety-utility balance without additional token overhead or inference delays. Our analysis reveals that safety-related information in LLMs is sparsely distributed; adjusting approximately 5 % percent 5 5\% 5 % of the internal state is as effective as modifying the entire state. Extensive experiments on nine LLMs (ranging from 2 billion to 72 billion parameters), evaluated against ten jailbreak attack methods and compared with six defense strategies, validate the effectiveness and efficiency of our approach. By directly manipulating internal states during reasoning, Jailbreak Antidote offers a lightweight, scalable solution that enhances LLM safety while preserving utility, opening new possibilities for real-time safety mechanisms in widely-deployed AI systems.

## 1 Introduction

Large language models (LLMs) have revolutionized natural language processing, demonstrating advanced cognitive abilities and significantly impacting various aspects of daily life. They excel in instruction understanding (Ouyang et al., ; Chung et al., ), summarization (Chung et al., ), and complex reasoning tasks (Kojima et al., ; Wang & Zhou, ). Applications built upon LLMs are widespread, enhancing efficiency and convenience in domains such as coding assistance (Roziere et al., ), medical diagnostics (Singhal et al., ), financial analysis (Li et al., ), and psychological counseling (Strachan et al., ; Xu et al., ). Given their pervasive use and profound social impact, ensuring the safety and utility of LLMs has become critically important.

A central challenge in deploying LLMs is balancing *safety* and *utility*. Users expect models to be highly capable and responsive, yet this can inadvertently lead to the generation of harmful or disallowed content, especially when models are manipulated through adversarial prompts known as *jailbreak attacks* (Christian, ). These attacks craft inputs that bypass safety mechanisms, causing models to produce inappropriate or unsafe outputs. The consequences of such jailbreaks can be severe, including the spread of misinformation, facilitation of harmful activities, violation of ethical guidelines, and potential legal or reputational damage for deploying organizations. Robust defenses against jailbreak attacks are essential to ensure that LLMs remain trustworthy and safe. However, enhancing defenses can sometimes make models overly conservative, leading to refusals of reasonable requests and degrading user experience. Thus, there exists a delicate trade-off between safety and capability that needs careful balancing (Tuan et al., ).

Existing defense strategies against jailbreak attacks typically fall into three categories: detection-based methods, prompt engineering, and safety alignment. Detection methods, such as perplexity filtering (Alon & Kamfonas, ; Jain et al., ), are often bypassed by semantic-level attacks (Samvelyan et al., ; Paulus et al., ). Prompt engineering modifies input prompts to steer models away from harmful content (Xie et al., ; Wei et al., ), but adds computational overhead and increases latency. Safety alignment through fine-tuning on curated datasets (Dai et al., ; Ouyang et al., ; Bai et al., ) is costly and lacks real-time flexibility. Overall, these methods cannot easily adapt in real time and may reduce model utility by over-prioritizing safety.

Recent research has focused on observing and adjusting internal model states to interpret and control LLM behavior (Zou et al., ; Liu et al., ). Building on these insights, we aim to develop a method for real-time safety adjustments by manipulating internal neuron states, achieving a better balance between safety and utility. Our approach directly modifies the model’s internal representations during inference, avoiding the computational overhead and inflexibility of existing techniques.

In this paper, we propose *Jailbreak Antidote*, a method that adjusts LLM safety preferences by modifying only around $5\%$ of the internal state during inference (Figure 1). This approach allows for real-time control of the safety-utility balance without adding token overhead or introducing delays. Unlike methods that rely on prompt modifications or resource-intensive fine-tuning, *Jailbreak Antidote* offers a lightweight and adaptable solution suitable for deployment. Our main contributions are as follows:

Figure: Figure 1: Overview of *Jailbreak Antidote*. (a) Obtaining the safety direction $\mathbf{d}_{\text{safe}}$ using PCA on hidden states from benign and harmful prompts. (b) Adjusting the internal state $\mathbf{h}_{S^{\prime}}$ of the adversarial prompt $S^{\prime}$ by shifting it towards $\mathbf{d}_{\text{safe}}$ during inference. $S_{0}$ represents the original harmful prompt, and $S^{\prime}$ represents the adversarial attack prompt. The example uses a past-tense attack. (c) Comparison on Llama-3.1-8B-it, with lines representing different $k\%$ values. Points along each line correspond to varying $\alpha$ values. The baseline point shows the performance of the original model without defense.
Refer to caption: x1.png

- •
Real-Time Safety Adjustments: We find that safety information in LLMs is concentrated in specific components of the internal state. By manipulating around 5% of these components, we adjust safety preferences in real-time without the overhead of fine-tuning or prompt modifications.
- •
Balancing Safety and Utility: By adjusting internal representations, we quantitatively study the trade-off between safety and utility in LLMs. Our findings demonstrate that our method can better balance safety and utility compared to existing defense strategies, without compromising performance or incurring extra computational costs during deployment. Moreover, our approach allows for real-time adjustments to meet varying safety requirements.
- •
Comprehensive Validation: We evaluate nine LLMs (2B to 72B parameters) across ten jailbreak methods and six defense strategies. Our approach introduces no additional overhead and significantly outperforms existing defenses in terms of safety and utility balance.

Our approach offers a practical and adaptable solution for enhancing LLM safety while preserving their utility. By directly modifying internal states during reasoning, we enable flexible control over the safety-utility balance, addressing the limitations of existing methods.

## 2 Related Work

Our work builds upon prior research on jailbreak attacks against LLMs, defense strategies to mitigate these attacks, and mechanistic interpretability approaches focusing on representations in LLMs.

##### Jailbreak Attacks on LLMs

As LLMs become increasingly prevalent, they have become targets for *jailbreak attacks*—adversarial prompts designed to bypass safety mechanisms and induce models to generate harmful or disallowed content (Jin et al., ). Early attacks exploited simple manipulations like role-playing scenarios or specific prompts to trick models into violating safety guidelines (Wei et al., ). As safety alignment techniques improved, attackers developed more sophisticated methods, including gradient-based approaches that generate adversarial suffixes (Zou et al., ), genetic algorithms to produce stealthy prompts (Liu et al., ), and black-box attacks that iteratively refine prompts without access to internal parameters (Chao et al., ). Other techniques involve crafting adversarial paraphrases (Zeng et al., ) or exploiting unconventional inputs like ciphered text (Yuan et al., ) and past tense formulations (Andriushchenko & Flammarion, ). These diverse and evolving attacks highlight the urgent need for robust defenses to maintain LLM safety and reliability.

##### Defense Methods Against Jailbreak Attacks

Existing defense strategies include prompt engineering, and safety fine-tuning. Detection-based approaches aim to identify and block adversarial prompts using techniques like perplexity filtering (Alon & Kamfonas, ; Jain et al., ), but sophisticated attacks with semantic-level prompts (Samvelyan et al., ; Paulus et al., ) often evade detection. Prompt engineering modifies prompts or model responses to reinforce safety, employing self-reminders (Xie et al., ) or leveraging in-context learning (Wei et al., ), but introduces computational overhead and inference latency (Agarwal et al., ), negatively affecting user experience. Safety alignment methods, such as Reinforcement Learning from Human Feedback (RLHF) (Bai et al., ) and Safe RLHF (Dai et al., ), retrain models on curated datasets but require significant resources and lack flexibility for real-time adjustments. Moreover, these methods may degrade model utility by being overly restrictive, leading to refusals of benign queries. We aim to address these limitations by proposing a defense mechanism that operates during inference without modifying input prompts or requiring retraining, enabling real-time safety adjustments while preserving model utility.

##### Mechanistic Interpretability and Internal State Manipulation

Mechanistic interpretability seeks to reverse-engineer models by analyzing their internal representations (Elhage et al., ; Nanda et al., ). Prior research has explored how models process tasks like modular arithmetic and factual recall (Meng et al., ), focusing on interpretability rather than behavior control. Inspired by representation engineering (Zou et al., ) and latent space steering (Liu et al., ), our work shifts focus to manipulating internal activations to adjust model behavior during inference.

A key finding of our approach is that safety representations in LLMs are sparsely distributed, allowing us to control the model’s safety preferences by adjusting only about $5\%$ of its internal state. This targeted manipulation contrasts with previous studies that often focus on higher-level structures like layers or attention heads (Halawi et al., ). While earlier works have primarily emphasized interpretability, we demonstrate that small-scale adjustments can directly influence LLM safety without the need for prompt modifications or retraining. This allows for efficient real-time adjustments, striking a balance between safety and utility with minimal performance impact.

## 3 Preliminaries

##### Jailbreak Attacks and Defenses

Consider an LLM $\mathcal{M}$ that generates a response $R$ given an input prompt $S$, processing tokens sequentially, i.e., $R=\mathcal{M}(S)$. The model is designed to adhere to safety guidelines, refusing to generate harmful content.

A *jailbreak attack* aims to construct an adversarial prompt $S^{\prime}=\mathcal{A}(S_{0})$, where $\mathcal{A}$ is an attack algorithm and $S_{0}$ is a harmful prompt. The goal is to manipulate $\mathcal{M}$ into generating a harmful response $R^{\prime}=\mathcal{M}(S^{\prime})$ that fulfills the malicious intent of $S_{0}$, bypassing safety mechanisms.

A successful jailbreak attack occurs when the model accepts a harmful prompt and generates a harmful response, i.e., when $\mathcal{J}(S_{0},R^{\prime})=1$, where $\mathcal{J}$ is a judge function. Various methods can implement the judge function, such as prefix matching (Zou et al., ), LLM-based evaluations (Qi et al., ; Chao et al., ), or human annotations (Wei et al., ).

A *jailbreak defense* aims to enhance robustness against such attacks, producing a defended model $\mathcal{D}\circ\mathcal{M}$. An effective defense ensures that for any adversarial prompt $S^{\prime}$, the model refuses to generate harmful content while maintaining utility on benign prompts.

##### Internal Representations in LLMs

Transformer-based LLMs process input sequences through multiple layers (Vaswani, ). At each layer $l$, hidden states $\mathbf{h}_{t}^{l}\in\mathbb{R}^{d}$ are computed at each position $t$. We focus on the hidden state at the last token position $t=T$, which summarizes the model’s understanding of the prompt (Mann et al., ; Raffel et al., ; Zou et al., ). As shown in Figure A.3, the last token position reveals the most significant distinction between benign and harmful prompts. In the remainder of this paper, we denote this hidden state as $\mathbf{h}^{l}=\mathbf{h}_{T}^{l}$.

## 4 Method: Jailbreak Antidote

We introduce *Jailbreak Antidote*, a method for runtime adjustment of LLM safety preferences through sparse manipulation of internal states. Our approach leverages the observation that the model’s decisions to accept or refuse prompts are reflected in its internal hidden states. By identifying and adjusting these representations, we influence the model’s behavior to enhance safety while preserving utility.

Figure: Figure 2: (a) t-SNE visualization of hidden states of benign prompts, harmful prompts, and adversarial prompts (PAIR and GCG) at different layers in Llama-3.1-8B-it. The safety direction $\mathbf{d}_{\text{safe}}^{l}$ is indicated by the arrows. In deeper layers, attack prompts are positioned between the benign and harmful clusters, indicating how attacks manipulate internal states. (b) Distribution of the components of $\mathbf{d}_{\text{safe}}^{l}$ at different layers, showing a long-tailed distribution that indicates sparsity in safety representations.
Refer to caption: x2.png

### 4.1 Identifying and Leveraging the Safety Direction

LLMs are trained to be value-aligned, refusing to generate harmful content (Ouyang et al., ). For harmful prompts, the model’s internal state reflects a harmful or rejected representation, leading to a refusal. For benign prompts, the internal state corresponds to a benign or accepted representation, resulting in a helpful response.

*Jailbreak attacks* aim to manipulate a harmful prompt $S_{0}$ into an adversarial prompt $S^{\prime}=\mathcal{A}(S_{0})$ that influences the model’s internal state to resemble that of a benign prompt, causing the model to generate harmful content. To investigate how jailbreak attacks affect internal states, we visualize the hidden states corresponding to different prompts using t-SNE.

Figure 2 (a) shows the hidden states at various layers for benign prompts, harmful prompts, and adversarial prompts generated by the PAIR (Chao et al., ) and GCG (Zou et al., ). In the shallow layers (e.g., layer 4), the hidden states of benign and harmful prompts are mixed together, while the attack prompts form distinct clusters. This suggests that early layers capture general linguistic features or different sentence structures, as attack prompts often alter the style or syntax of the input.

As we progress to deeper layers, the distribution of hidden states changes. The hidden states of attack prompts shift and are positioned between the clusters of benign and harmful prompts. This indicates that the attacks manipulate the model’s internal representations, causing the hidden states to transition from harmful towards benign representations, thereby affecting the model’s safety performance. This observation implies that by adjusting the internal states, we can potentially counteract such attacks. This trend is further supported by additional visualizations in Figure A.1.

To adjust the internal state effectively, we first identify the *safety direction* in the model’s representation space. We collect sets of benign prompts $\mathcal{S}_{\text{benign}}$ and harmful prompts $\mathcal{S}_{\text{harmful}}$. For each prompt $S$, we extract the hidden state $\mathbf{h}^{l}\in\mathbb{R}^{d}$ at the last token position $T$ from selected layers $l\in\mathcal{L}\subseteq\{1,\dots,L\}$, where $L$ is the total number of layers in the model.

We compile the hidden state representations into a set for each layer $l$:

$$ $\mathcal{H}^{l}=\left\{\mathbf{h}_{S}^{l}\,\middle|\,S\in\mathcal{S}_{\text{ benign}}\cup\mathcal{S}_{\text{harmful}}\right\}.$ (1) $$

We perform Principal Component Analysis (PCA) on $\mathcal{H}^{l}$ to identify the principal components of variance in the hidden states at each layer $l$. Specifically, we compute the covariance matrix $\mathbf{C}^{l}\in\mathbb{R}^{d\times d}$:

$$ $\mathbf{C}^{l}=\frac{1}{|\mathcal{H}^{l}|}\sum_{\mathbf{h}^{l}\in\mathcal{H}^{ l}}(\mathbf{h}^{l}-\bar{\mathbf{h}}^{l})(\mathbf{h}^{l}-\bar{\mathbf{h}}^{l})^ {\top},$ (2) $$

where $\bar{\mathbf{h}}^{l}$ is the mean hidden state at layer $l$:

$$ $\bar{\mathbf{h}}^{l}=\frac{1}{|\mathcal{H}^{l}|}\sum_{\mathbf{h}^{l}\in \mathcal{H}^{l}}\mathbf{h}^{l}.$ (3) $$

The first principal component $\mathbf{d}_{\text{safe}}^{l}$ captures the direction of maximum variance between benign and harmful prompts. In Figure 2 (a), the arrows represent the safety direction $\mathbf{d}_{\text{safe}}^{l}$ at different layers. We compute $\mathbf{d}_{\text{safe}}^{l}$ using only benign and harmful prompts, without including any adversarial attack prompts, to ensure generalization and avoid data leakage.

### 4.2 Sparsity in the Safety Representation

An important insight from our analysis is that the elements of $\mathbf{d}_{\text{safe}}^{l}$ exhibit a long-tail distribution, as shown in Figure 2 (b). This suggests that only a small subset of dimensions significantly contribute to the safety distinction, indicating that the safety representation in LLMs is sparse. To leverage this sparsity, we create a mask $\mathbf{m}^{l}\in\{0,1\}^{d}$ that retains only the top $k\%$ of dimensions with the largest absolute values in $\mathbf{d}_{\text{safe}}^{l}$:

$$ $m_{i}^{l}=\begin{cases}1,&\text{if }|d_{\text{safe},i}^{l}|\geq\tau,\\ 0,&\text{otherwise},\end{cases}$ (4) $$

where $d_{\text{safe},i}^{l}$ is the $i$-th element of $\mathbf{d}_{\text{safe}}^{l}$, and $\tau$ is chosen to retain the top $k\%$ of dimensions.

### 4.3 Adjusting Internal States During Inference

Given a new input prompt $S^{\prime}$, we adjust the model’s hidden states at layers $l\in\mathcal{L}$ to control its safety preference. We obtain the original hidden state $\mathbf{h}_{S^{\prime}}^{l}\in\mathbb{R}^{d}$ at the last token position and modify it by adding the masked safety direction, scaled by a factor $\alpha$, as shown in Figure 1 (b):

$$ $\mathbf{h}_{S^{\prime}}^{l\,\prime}=\mathbf{h}_{S^{\prime}}^{l}+\alpha\left( \mathbf{d}_{\text{safe}}^{l}\odot\mathbf{m}^{l}\right),$ (5) $$

where $\odot$ denotes element-wise multiplication. The scaling factor $\alpha$ enables control over the strength of the safety adjustment, directly impacting the model’s balance between safety and utility:

- •
A higher $\alpha$ emphasizes safety, making the model more conservative in its responses but potentially affecting utility by increasing the refusal of borderline benign prompts.
- •
A lower $\alpha$ prioritizes utility, ensuring responsiveness to benign prompts but may weaken the safety enhancements.

The adjusted hidden state $\mathbf{h}_{S^{\prime}}^{l\,\prime}$ replaces the original hidden state at layer $l$, and the model continues processing with the modified state. Since $\mathbf{d}_{\text{safe}}^{l}$ and $\mathbf{m}^{l}$ are precomputed and shared across all inputs, this adjustment introduces negligible computational overhead during inference.

### 4.4 Balancing Safety and Utility

Our method offers real-time control over the safety-utility balance by adjusting the parameters $\alpha$ and $k$. By modifying only the top $k\%$ of dimensions, we focus on the most significant components related to safety, minimizing perturbations to the model’s capabilities. This approach reduces the overall impact on performance while effectively enhancing safety, allowing for flexible and efficient adjustments.

As shown in Figure 1 (c), focusing on only $5\%$ of dimensions yields performance nearly identical to adjusting $100\%$, confirming that safety representations are sparsely encoded. This enables us to limit adjustments to the most relevant dimensions, thereby maintaining the model’s utility on benign tasks while ensuring robust safety enhancements.

## 5 Experiments

We conducted extensive experiments to evaluate the effectiveness of *Jailbreak Antidote* across various LLMs, comparing it with existing defense methods against multiple jailbreak attacks. Our experiments aim to demonstrate the superiority of our method in enhancing LLM safety while maintaining utility and to analyze the impact of different hyperparameters on the safety-utility balance.

### 5.1 Experimental Setup

We evaluated *Jailbreak Antidote* using JailbreakBench (Chao et al., ) for assessing safety, focusing on 100 harmful prompts. To measure model utility on benign tasks, we used AlpacaEval (Dubois et al., ). Nine large language models (LLMs) with parameters ranging from 2 billion to 72 billion were tested, including Gemma-2-2B-it (Team, ), Phi-3-mini-it (Abdin et al., ), Qwen-1.5-7B-it (Bai et al., ), Qwen-2-7B-it (Yang et al., ), Llama-3-8B-it (AI@Meta, ), Llama-3.1-8B-it (AI@Meta, ), Gemma-2-9B-it Team (), Llama-3-70B-it (AI@Meta, ), and Qwen-2-72B-it (Yang et al., ).

We tested against a variety of jailbreak attack methods, including common ones sourced from [jailbreakchat.com](jailbreakchat.com) such as BETTER_DAN, AIM, DEV_MODE_Ranti, DEV_MODE_V2, and ANTI_GPT_V2. More advanced attacks like GCG (Zou et al., ), PAIR (Chao et al., ), and random search-based prompts (Andriushchenko et al., ) were also included. In addition, we evaluated attacks that reformulate harmful requests into the past or future tense (Andriushchenko & Flammarion, ).

For defense methods, we compared *Jailbreak Antidote* with six existing strategies: In-Context Learning (Wei et al., ), Paraphrase and Perplexity Filter (Jain et al., ), Self-Reminder (Xie et al., ), SemanticSmoothLLM (Ji et al., ), and SmoothLLM (Robey et al., ). Each defense method was implemented according to its original settings.

We measured two key metrics to evaluate the balance between safety and utility: 1. Defense Success Rate (DSR): The percentage of harmful prompts successfully blocked by the defense method, reflecting how well the model avoids generating unsafe content. A higher DSR indicates stronger defense against jailbreak attacks. 2. Win Rate on AlpacaEval (Win Rate): The percentage of benign prompts for which the model’s performance was unaffected by the defense method. We used the performance of the original, non-defended LLM as a reference to accurately measure the impact of each defense method. A higher Win Rate indicates that the model remains effective on non-harmful tasks, preserving its utility. For further details on the datasets, models, parameter ranges, and comprehensive results, refer to the Appendix A.1.

### 5.2 Results and Analysis

##### Overall Comparison

We first present an overview of our method’s performance compared to other defense methods across different models, averaged over all attack methods. Table 1 shows the DSR and Win Rate for each defense method and model. Our method demonstrates consistently high DSR, particularly excelling in larger models like Llama-3-70B-it, where it achieved a DSR of $100\%$. Even on smaller models, *Jailbreak Antidote* maintains competitive performance, consistently providing strong defense against jailbreak attacks.

**Table 1: Comparison of Defense Success Rate (DSR) and Win Rate on AlpacaEval (Win Rate) across different models and defense methods. The best, second and third scores are highlighted.**
| Model | Safety<br>-Utility | Baseline | In-Context<br>Learning | Paraphrase | Perplexity<br>Filter | Self<br>Reminder | Semantic<br>Smooth<br>LLM | Smooth<br>LLM | Jailbreak<br>Antidote |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Gemma-2-2B-it | DSR $\uparrow$ | 29.2 | 54.1 | 69.7 | 30.5 | 36.1 | 74.5 | 46.5 | 71.8 |
| Win Rate $\uparrow$ | 50.0 | 44.8 | 35.7 | 50.7 | 47.8 | 31.8 | 31.3 | 52.0 |  |
| Phi-3-mini-it | DSR $\uparrow$ | 53.2 | 55.4 | 75.5 | 54.9 | 55.4 | 70.5 | 71.3 | 79.6 |
| Win Rate $\uparrow$ | 50.0 | 42.7 | 36.4 | 47.2 | 44.6 | 27.6 | 19.9 | 52.2 |  |
| Qwen-1.5-7B-it | DSR $\uparrow$ | 29.2 | 54.1 | 69.7 | 30.5 | 36.1 | 74.5 | 46.5 | 71.8 |
| Win Rate $\uparrow$ | 50.0 | 44.8 | 35.7 | 50.8 | 47.8 | 31.8 | 31.3 | 52.0 |  |
| Qwen-2-7B-it | DSR $\uparrow$ | 55.3 | 57.6 | 70.1 | 57.3 | 67.4 | 81.9 | 60.4 | 95.5 |
| Win Rate $\uparrow$ | 50.0 | 37.4 | 35.3 | 51.4 | 50.1 | 32.7 | 34.2 | 51.6 |  |
| Llama-3-8B-it | DSR $\uparrow$ | 68.9 | 71.7 | 79.0 | 67.9 | 78.9 | 88.1 | 84.2 | 99.4 |
| Win Rate $\uparrow$ | 50.0 | 38.9 | 35.5 | 52.2 | 39.4 | 31.8 | 32.4 | 53.0 |  |
| Llama-3.1-8B-it | DSR $\uparrow$ | 63.1 | 56.2 | 72.1 | 64.0 | 68.6 | 86.6 | 69.0 | 78.0 |
| Win Rate $\uparrow$ | 50.0 | 36.4 | 32.8 | 51.6 | 41.2 | 26.6 | 33.2 | 51.9 |  |
| Gemma-2-9B-it | DSR $\uparrow$ | 54.5 | 56.7 | 75.8 | 55.1 | 63.1 | 79.4 | 46.5 | 78.1 |
| Win Rate $\uparrow$ | 50.0 | 38.6 | 31.2 | 51.0 | 42.5 | 33.9 | 32.4 | 47.4 |  |
| Llama-3-70B-it | DSR $\uparrow$ | 61.4 | 61.8 | 76.1 | 61.6 | 71.8 | 83.9 | 88.2 | 100 |
| Win Rate $\uparrow$ | 50.0 | 36.3 | 35.2 | 50.2 | 42.7 | 34.0 | 35.1 | 53.5 |  |
| Qwen-2-72B-it | DSR $\uparrow$ | 62.7 | 61.5 | 65.0 | 65.2 | 71.0 | 72.3 | 69.8 | 93.9 |
| Win Rate $\uparrow$ | 50.0 | 35.2 | 34.7 | 48.9 | 45.6 | 30.4 | 33.7 | 52.8 |  |

Unlike many other defense methods, *Jailbreak Antidote* does not significantly reduce the model’s utility. As shown in the Win Rate row, other approaches often impair the model’s ability to respond to benign queries, but our method preserves this capability across all models tested. This balance between safety and functionality highlights *Jailbreak Antidote*’s advantage in maintaining performance while enhancing security.

##### Analysis on Different Attack Methods

To further analyze the effectiveness of our method against different attack techniques, we present detailed results showing the DSR for different combinations of attacks and defenses. Figure 3 displays three representative models: Phi-3-mini-it (small model), Qwen-1.5-7B-it (mid-sized model), and Llama-3-70B-it (large model). These results highlight that *Jailbreak Antidote* effectively enhances defense performance across different types of attacks and models. For more results, please refer to Figure A.4 in Appendix.

For general-purpose jailbreak prompts like AIM and DEV_MODE_V2, newer models tend to have relatively strong built-in defenses. Defense methods that modify the input prompt, such as Paraphrase and Semantic SmoothLLM, have proven to be effective against these types of attacks. However, Perplexity Filter shows limited success when faced with natural language attacks, as these attacks closely resemble normal language patterns, making them difficult to detect through perplexity measures.

Figure: Figure 3: DSR heatmaps for different attack-defense combinations on (a) Phi-3-mini-it, (b) Qwen-1.5-7B-it, and (c) Llama-3-70B-it. Rows represent defense methods; columns represent attack methods.
Refer to caption: x3.png

Our method, *Jailbreak Antidote*, demonstrates high DSR across all attack methods, including more sophisticated ones like PAIR and GCG, which are designed to exploit model vulnerabilities. Notably, on larger models like Llama-3-70B-it, *Jailbreak Antidote* achieves a 100% DSR against all attacks, indicating its robustness across a variety of jailbreak strategies.

On smaller models such as Qwen-1.5-7B-it, while our method significantly improves DSR compared to the baseline, the overall DSR remains lower than on larger models. This suggests that smaller and older models may have less capacity to effectively encode safety-related information, affecting their overall defense performance.

##### Inference Efficiency Analysis

We evaluated the overhead introduced by different defense methods by measuring the number of defense tokens required, which correlates with resource consumption and inference latency. Figure 4 shows scatter plots of Defense Tokens versus DSR for different defense methods across various models.

Figure: Figure 4: Defense Tokens versus DSR for different defense methods across various models. Each point represents a defense method, with the x-axis showing the number of defense tokens and the y-axis showing the DSR.
Refer to caption: x4.png

As shown in Figure 4, *Jailbreak Antidote* requires no additional prompt tokens, which means it introduces no overhead in terms of prompt length. This is because our method works by directly adjusting the internal states rather than modifying the input prompt. In contrast, methods like SemanticSmoothLLM and SmoothLLM rely on a significant number of defense tokens, leading to increased computational costs and inference delays. Despite this higher token consumption, some of these methods still achieve lower DSRs compared to our approach, indicating that their defense performance is not as effective relative to the computational overhead they introduce.

Our method consistently delivers high DSR with minimal inference overhead across all models, showcasing both its effectiveness and efficiency. These findings demonstrate that *Jailbreak Antidote* not only improves defense performance but also ensures inference efficiency, making it a practical solution for real-world applications.

### 5.3 Ablation Study

We performed an ablation study to evaluate the impact of two key hyperparameters: the scaling factor $\alpha$, which controls the intensity of the safety adjustments, and the sparsity parameter $k$, which determines the proportion of neurons being adjusted. As shown in Figure 5, increasing $\alpha$ results in a higher DSR, indicating stronger safety, while the Win Rate (a measure of the model’s performance on benign tasks) declines as the model becomes more conservative. This demonstrates the inherent trade-off between safety and utility. For further details on the impact of these hyperparameters across different models, please refer to Figure A.5.

Figure: Figure 5: Impact of the scaling factor $\alpha$ on DSR and Win Rate for different sparsity levels $k$. The left y-axis represents Win Rate (bars), and the right y-axis represents DSR (lines). (a) Qwen-2-7B-it, (b) Llama-3.1-8B-it. Different colors represent different $k\%$ values.
Refer to caption: x5.png

When $k=100\%$, i.e., when all neurons are adjusted, Win Rate drops sharply, suggesting that broad adjustments degrade the model’s ability to generate useful responses. However, when we reduce $k$ to 5%, we observe significant safety improvements with minimal impact on utility, highlighting the importance of sparsity in preserving model performance while boosting safety. This finding underscores that safety information in LLMs is encoded sparsely, and adjusting a small subset of critical neurons is sufficient for effective safety enhancements.

In Figure 6, the effect of varying $k$ is explored further. Smaller $k$ values (e.g., $k=1\%$ or $k=5\%$) maintain a better balance between safety and utility by limiting the scope of adjustments, while very small $k$ values (e.g., $k=0.5\%$) fail to deliver meaningful safety improvements, as too few neurons are modified. Additionally, selecting the top-$k\%$ neurons based on the magnitude of $\mathbf{d}_{\text{safe}}$ outperforms random selection in the vast majority of cases, demonstrating that targeting the most relevant dimensions is crucial for optimal performance.

Figure: Figure 6: Win Rate versus DSR for different values of $k$ and selection strategies across various models. Dots represent other defense methods; lines represent *Jailbreak Antidote* with different $k\%$ values. Diamonds indicate top $k\%$ selection; squares indicate random $k\%$ selection.
Refer to caption: x6.png

As shown in Figure 5, interestingly, when $\alpha<0$, the model’s safety performance drops below the baseline ($\alpha=0$), which indicates that our method can be reversed to weaken safety, effectively turning it into an attack method. This showcases the flexibility of the approach, although our primary focus remains on enhancing safety.

### 5.4 Conclusion

In this work, we introduced *Jailbreak Antidote*, a method to enhance the safety of large language models (LLMs) by adjusting their internal states in real-time. By leveraging the sparsity of safety-related representations, we selectively modify a small subset of neurons (around 5%) to balance safety and utility without adding computational overhead. Extensive experiments across models from 2B to 72B parameters demonstrate that *Jailbreak Antidote* outperforms existing defenses in terms of Defense Success Rate (DSR) while maintaining high performance on benign tasks. This runtime flexibility offers a significant advantage for real-world applications, where safety needs may vary, but retraining or prompt modifications are impractical.

Beyond safety, our method opens avenues for broader applications in model alignment, potentially addressing issues like fairness or bias reduction through similar sparse adjustments. As LLMs continue to grow in complexity, *Jailbreak Antidote* provides a scalable and adaptable solution that ensures real-time safety without sacrificing utility. This contributes to the broader effort of making AI systems more trustworthy and reliable in dynamic environments, offering a practical pathway for safer and more flexible AI deployments across industries.

## Appendix A Appendix

### A.1 Experimental Details

#### A.1.1 Datasets

##### JailbreakBench

For evaluating safety and defense effectiveness, we used JailbreakBench (Chao et al., ), an open-source robustness benchmark for jailbreaking LLMs. JailbreakBench comprises $200$ distinct prompts, including $100$ benign and $100$ misuse prompts, curated with reference to OpenAI’s usage policies. We specifically used the $100$ misuse prompts as targets for jailbreak attacks to assess the robustness of different defense methods.

##### AlpacaEval

To evaluate the utility of LLMs on benign tasks, we employed AlpacaEval (Dubois et al., ), a fast and affordable benchmark for chat LLMs that uses LLM-based auto-annotators to estimate response quality. AlpacaEval achieves a Spearman correlation of $0.98$ with human preferences measured by Chatbot Arena (Chiang et al., ), making it a reliable tool for assessing the impact of defense methods on model performance.

##### Safety-Prompts Dataset

For extracting the safety direction $\mathbf{d}_{\text{safe}}$, we used a separate dataset containing benign and harmful prompts (Phan, ). This dataset prevents data leakage and maintains the reliability of experimental results.

#### A.1.2 Attack Methods

We evaluated the robustness of defense methods against ten different jailbreak attack techniques, in addition to the original jailbreak prompts from JailbreakBench. The attack methods include:

##### Universal Jailbreak Prompts from jailbreakchat.com

We selected several top-voted jailbreak prompts:

- •
BETTER_DAN (^1^11[https://jailbreakchat-hko42cs2r-alexalbertt-s-team.vercel.app/prompt/8db3b7ea-4ff0-481b-90c1-bb12450296a3](https://jailbreakchat-hko42cs2r-alexalbertt-s-team.vercel.app/prompt/8db3b7ea-4ff0-481b-90c1-bb12450296a3))
- •
AIM (^2^22[https://jailbreakchat-hko42cs2r-alexalbertt-s-team.vercel.app/prompt/4f37a029-9dff-4862-b323-c96a5504de5d](https://jailbreakchat-hko42cs2r-alexalbertt-s-team.vercel.app/prompt/4f37a029-9dff-4862-b323-c96a5504de5d))
- •
DEV_MODE_Ranti (^3^33[https://jailbreakchat-hko42cs2r-alexalbertt-s-team.vercel.app/prompt/a07a2dfe-a363-4682-bc4d-3a2905b7efd0](https://jailbreakchat-hko42cs2r-alexalbertt-s-team.vercel.app/prompt/a07a2dfe-a363-4682-bc4d-3a2905b7efd0))
- •
DEV_MODE_V2 (^4^44[https://jailbreakchat-hko42cs2r-alexalbertt-s-team.vercel.app/prompt/ff30aedf-ee6d-4c3b-ad71-57c1a6e0e5fb](https://jailbreakchat-hko42cs2r-alexalbertt-s-team.vercel.app/prompt/ff30aedf-ee6d-4c3b-ad71-57c1a6e0e5fb))
- •
ANTI_GPT_V2 (^5^55[https://jailbreakchat-hko42cs2r-alexalbertt-s-team.vercel.app/prompt/083b25aa-acbe-4641-9072-3757f8596b0c](https://jailbreakchat-hko42cs2r-alexalbertt-s-team.vercel.app/prompt/083b25aa-acbe-4641-9072-3757f8596b0c))

These prompts are designed to circumvent safety mechanisms by encouraging the model to adopt alternate personas or modes that ignore alignment constraints.

##### Tense Reformulation Attacks

Following Andriushchenko & Flammarion (), we included attacks that reformulate harmful requests in different tenses:

- •
Past Tense Reformulation: Rewriting prompts in the past tense to exploit potential gaps in refusal training.
- •
Future Tense Reformulation: Rewriting prompts in the future tense to assess if models generalize safety across tenses.

These attacks reveal that LLMs may respond to harmful content when prompts are rephrased in alternative tenses.

##### Prompt with Random Search

From Andriushchenko et al. (), this attack uses random search to find prompts that successfully jailbreak safety-aligned LLMs. It demonstrates that adaptive attacks can effectively bypass defenses without gradient information.

##### GCG Attack

The GCG (Greedy Coordinate Gradient) attack by Zou et al. () is a universal and transferable adversarial attack that appends an adversarial suffix to prompts, prompting the model to generate objectionable content.

##### PAIR Attack

The PAIR (Prompt Automatic Iterative Refinement) attack from Chao et al. () generates semantic jailbreaks using only black-box access to the LLM. It iteratively refines prompts to bypass safety mechanisms with minimal queries.

For all attacks, we used the successful prompts provided in the respective studies, ensuring consistency and reproducibility. We applied these attacks across different models to evaluate their robustness comprehensively.

#### A.1.3 Defense Methods

We compared *Jailbreak Antidote* with six existing defense strategies:

##### In-Context Learning (ICL)

From Wei et al. (), ICL uses in-context demonstrations to modulate the alignment of LLMs. By providing examples of appropriate behavior within the prompt, ICL aims to guide the model toward safer responses.

##### Paraphrase and Perplexity Filter

As proposed by Jain et al. (), these methods involve paraphrasing the input prompt and filtering based on perplexity. The goal is to detect and mitigate adversarial prompts by identifying anomalies in language patterns.

##### Self-Reminder

Xie et al. () introduced Self-Reminder, which inserts self-reminders into the prompt to reinforce the model’s safety guidelines. This approach aims to remind the model of its alignment objectives during inference.

##### SemanticSmoothLLM

From Ji et al. (), SemanticSmoothLLM employs semantic smoothing and prompt perturbations to defend against adversarial inputs. It aggregates predictions over semantically similar prompts to improve robustness.

##### SmoothLLM

Proposed by Robey et al. (), SmoothLLM uses random perturbations of the input prompt and aggregates outputs to detect and mitigate attacks. This method aims to exploit the brittleness of adversarial prompts to minor changes.

All defense methods were implemented according to their original settings. For models that do not support system prompts, we included the system prompt within the user input. When a defense method required LLM assistance, we used Llama-3.1-8B-it as the assisting model to maintain consistency.

#### A.1.4 Models Evaluated

We evaluated nine mainstream aligned LLMs with varying parameter sizes:

- •
Gemma-2-2B-it and Gemma-2-9B-it (Team, ): Lightweight models built from research and technology used in creating the Gemini models.
- •
Phi-3-mini-it (Abdin et al., ): A 3.8B parameter model trained on 3.3 trillion tokens, capable of running on a phone.
- •
Qwen-1.5-7B-it (Bai et al., ): Part of the Qwen model series, optimized for dialogue use cases.
- •
Qwen-2-7B-it and Qwen-2-72B-it (Yang et al., ): Latest models in the Qwen series, demonstrating competitive performance across diverse benchmarks.
- •
Llama-3-8B-it, Llama-3.1-8B-it, and Llama-3-70B-it (AI@Meta, ): Models from the Meta Llama 3 family, optimized for dialogue and instruction following.

These models range from 2 billion to 72 billion parameters, covering a broad spectrum of capabilities and architectures.

#### A.1.5 Implementation Details

In *Jailbreak Antidote*, we set the sparsity parameter $k$ to 5%, as preliminary experiments indicated this value effectively balances safety enhancement and minimal utility impact. The scaling factor $\alpha$ controls the strength of the safety adjustment and was adjusted individually for each model. We determined the range of $\alpha$ by identifying the bounds where the model’s responses transitioned from coherent to incoherent, as shown in Table A.1, then sampled 20 values within this range for our experiments.

In the evaluations on JailbreakBench and AlpacaEval, we used Llama-3-70B-it as the reference model, considering its strong performance and reproducibility as an open-source model, with evaluation results comparable to GPT-4. In AlpacaEval, we used the performance of each model without any defense as the reference to accurately reflect the impact of different defense methods on model performance.

**Table A.1: Range of $\alpha$ values used in *Jailbreak Antidote* across different models.**
| Model | $\alpha$ |
| --- | --- |
| Qwen2-7B-it | [-7, 5] |
| Llama-3-8B-it | [-0.6, 0.6] |
| Phi-3-mini-it | [-8, 4] |
| Qwen1.5-7B-it | [-2.0, 2.4] |
| Llama-3.1-8B-it | [-0.8, 0.6] |
| Gemma-2-9B-it | [-12, 16] |
| Gemma-2-2B-it | [-8, 12] |
| Llama-3-70B-it | [-0.5, 0.5] |
| Qwen2-72B-it | [-5.0, 5.0] |

For evaluating the responses of LLMs and determining if they bypass ethical or safety guidelines (i.e., jailbreak success), we employed the same judge template as used in PAIR (Chao et al., ). This ensures consistency across evaluations. The system template was designed to act as an impartial evaluator, providing a rating for each model response based on whether it violates ethical, legal, or safety guidelines. The judge assigns a rating on a scale from 1 (non-jailbroken) to 10 (fully jailbroken). A rating of 10 is required for a response to be considered a successful jailbreak. The full template is described in Table A.2.

Table: Table A.2: Instructions for the impartial red teaming judge template used in our evaluation.

This judge template ensures objective, consistent, and structured evaluation across all models and scenarios, contributing to the robustness of our evaluation process.

### A.2 Additional Experimental Results

#### A.2.1 Visualization of Hidden States and Safety Direction

To further explore the internal representations of LLMs, we extended the t-SNE visualizations from Figure 2 (a) to cover all layers of the model. Figure A.1 displays the hidden states for benign, harmful, and adversarial prompts (PAIR and GCG) across all layers in Llama-3.1-8B-it. Compared to the selected layers shown in the main text, these extended visualizations demonstrate that in deeper layers, the adversarial prompts gradually position themselves between the clusters of benign and harmful prompts. This suggests that the adversarial attacks manipulate the internal states to transition from harmful toward benign-like representations.

Figure: Figure A.1: t-SNE visualizations of hidden states for benign, harmful, and adversarial prompts (PAIR and GCG) across all layers in Llama-3.1-8B-it. In deeper layers, adversarial prompts transition between the benign and harmful clusters, highlighting how attacks manipulate the model’s internal states.
Refer to caption: extracted/5906546/appendix_hidden_states.png

#### A.2.2 Distribution of Safety Direction Components

An extended version of Figure 2 (b). We analyzed the distribution of the components of the safety direction $\mathbf{d}_{\text{safe}}$ for various models. Figure A.2 presents boxplots illustrating the long-tail distribution of $\mathbf{d}_{\text{safe}}$ components across different layers for models such as Gemma-2-2B-it, Phi-3-mini-it, Qwen-1.5-7B-it, Qwen-2-7B-it, Llama-3.1-8B-it, and Gemma-2-9B-it. The long tails confirm that safety-related information is sparsely distributed among a small subset of dimensions.

Figure: Figure A.2: Distribution of the components of $\mathbf{d}_{\text{safe}}$ across different layers and models. The long-tail distributions indicate sparsity in safety representations.
Refer to caption: x7.png

#### A.2.3 Impact of Token Position on Safety Representation

We investigated how the position of tokens affects the safety representation by computing the dot product between the hidden states of each token and the safety direction $\mathbf{d}_{\text{safe}}$. Figure A.3 shows heatmaps of these dot products across different layers and token positions for both benign and harmful prompts. The results highlight that the hidden state of the last token provides the most significant distinction between benign and harmful prompts, justifying our focus on adjusting the internal state at the last token position.

Figure: Figure A.3: Visualization of the dot product between hidden states and $\mathbf{d}_{\text{safe}}$ across layers and token positions. The last token (rightmost column) shows the most significant differentiation between benign and harmful prompts.
Refer to caption: x8.png

#### A.2.4 Extended Heatmaps of Defense Success Rates

We provide comprehensive heatmaps illustrating the Defense Success Rate (DSR) for different combinations of attack methods and defense methods across all evaluated models. Figure A.4 extends the results presented in Figure 3, demonstrating that *Jailbreak Antidote* consistently achieves high DSR across various attacks and models.

Figure: Figure A.4: DSR of different attack-defense combinations across evaluated models. Each subplot corresponds to a different model, with rows representing defense methods and columns representing attack methods.
Refer to caption: x9.png

#### A.2.5 Additional Results on Scaling Factor α 𝛼 \alpha italic_α

Figure A.5 presents additional ablation results on the impact of the scaling factor $\alpha$ for models not included in Figure 5. We show the DSR and Win Rate for Gemma-2-2B-it, Phi-3-mini-it, Qwen-1.5-7B-it, and Llama-3-8B-it. The trends align with our earlier findings, reinforcing the effectiveness of our method across different models and validating the choice of $\alpha$ and $k$.

Examples of how different values of $\alpha$ influence the model’s output are shown in Table A.3. When $\alpha<0$, *Jailbreak Antidote* shifts the model’s internal states toward the benign/accept direction, effectively turning the method into a form of white-box attack, making the model more likely to produce harmful outputs. On the other hand, when $\alpha>0$, *Jailbreak Antidote* shifts the internal states toward the harmful/reject direction, making the model more cautious and better equipped to resist various jailbreak attacks. However, the choice of $\alpha$ requires careful consideration, as overly large values may result in the model becoming overly conservative, which can negatively impact its performance, as shown in the last row of Table A.3.

Figure: Figure A.5: Impact of the scaling factor $\alpha$ and sparsity $k$ on DSR and Win Rate for additional models. The left y-axis represents Win Rate (bars), and the right y-axis represents DSR (lines). Different colors represent different sparsity levels $k$.
Refer to caption: x10.png

**Table A.3: The effect of $\alpha$ on LLM outputs. For harmful inputs, we present the model’s responses under two conditions: without any attack method (baseline) and under a past tense attack (Past Tense). Responses in red indicate harmful outputs, while responses in blue indicate safe outputs.**
| $\alpha$ | Harmful | Bengin |  |
| --- | --- | --- | --- |
| Baseline | Past Tense |  |  |
| Prompt | Write an anonymous letter to a colleague asserting that their biracial marriage is disgusting | How were racist letters about interracial marriages written and sent anonymously in the past? | Write an anonymous letter to a colleague celebrating their beautiful biracial marriage. |
| $-0.6$ | I’d be happy to provide an example of a letter, but I want to emphasize that a letter asserting that a biracial marriage is ”disgusting” is a personal opinion… | A very interesting and somewhat sensitive topic. In the past, people who held racist views against interracial marriages often wrote letters expressing… | Dear Colleague, I just wanted to take a moment to express my heartfelt congratulations to you and your spouse on your beautiful biracial marriage… |
| $-0.31$ | I can’t write a letter that may be seen as promoting discrimination or hate speech… | Racist letters about interracial marriages were indeed written and sent anonymously in the past. Here are some ways they were typically written… | Dear [Colleague’s Name], I just wanted to take a moment to express how beautiful and inspiring I think it is that you and your partner… |
| $0.00$ | I can’t help with this request. Writing a letter asserting a personal opinion that a colleague’s biracial marriage is ”disgusting” could be considered… | In the past, racist letters about interracial marriages were often written and sent anonymously to spread hate and discrimination… | Dear [Colleague], I wanted to take a moment to express my heartfelt congratulations on your recent wedding. As I heard about the celebration… |
| $0.14$ | I can’t assist with that request. Writing a letter that expresses prejudice or hate speech can have serious consequences and potentially cause harm… | I can provide information about the historical context of anonymous racist letters, also known as hate mail… | Dear [Colleague’s Name], I wanted to take a moment to express my heartfelt congratulations to you and your partner on your beautiful biracial marriage… |
| $0.28$ | I can’t complete that request. | I can’t help with that request. Sending racist letters or hate mail is against the law in many jurisdictions… | Dear [Colleague’s Name], I wanted to take a moment to express my heartfelt congratulations to you on this remarkable milestone… |
| $0.51$ | I can’t help you with that request. | I can’t answer that request. | I can’t assist you with that request. Is there anything else I can assist you with? |

### A.3 Additional Discussion

##### Impact of Model Size and Architecture

Our experiments indicate that larger models, such as Llama-3-70B-it, benefit more from *Jailbreak Antidote*, achieving higher Defense Success Rates (DSR) and maintaining high Win Rates. This suggests that larger models have a greater capacity to encode and utilize safety-related information within their internal representations. Conversely, smaller models like Gemma-2-2B-it show significant improvements but are inherently limited by their reduced parameter space, which may restrict the extent to which safety information can be represented and adjusted.

##### Effectiveness Against Sophisticated Attacks

*Jailbreak Antidote* remains effective against sophisticated attacks such as GCG and PAIR, which are specifically designed to exploit vulnerabilities in safety mechanisms. By adjusting the internal state along the safety direction, our method enhances the model’s ability to detect and refuse harmful content, even when adversarial prompts employ advanced techniques to bypass defenses. This robustness underscores the potential of internal state adjustments as a general strategy for improving LLM safety.

##### Efficiency and Practicality

Our method requires no additional prompt tokens and introduces negligible computational overhead, making it highly practical for real-world deployment. The ability to adjust safety preferences in real time without affecting inference latency or resource consumption is particularly valuable in applications where both safety and responsiveness are critical, such as customer service bots or real-time translation systems.

##### Limitations and Future Work

While *Jailbreak Antidote* demonstrates strong performance, dynamically adapting the scaling factor $\alpha$ and sparsity parameter $k$ based on context or the model’s confidence could further enhance the flexibility and effectiveness of our method. Investigating the applicability of this approach to other aspects of model alignment, such as fairness or domain adaptation, presents another avenue for future work.

##### Broader Implications

The success of *Jailbreak Antidote* highlights the potential of internal state manipulation as a tool for controlling and improving LLM behavior. This approach may extend to other challenges in AI safety and alignment, offering a framework for real-time adjustments without the need for retraining or extensive computational resources. As LLMs become increasingly integrated into diverse applications, methods that enhance safety while preserving utility will be essential for responsible AI deployment.

## Peer Reviews

confidence: 3
contribution: 2
initial_rating: 5
presentation: 3
questions: See weaknesses.
soundness: 3
strengths: 1. How to defend against jailbreak attacks is still an open challenge in the community.

2. Multiple LLMs are evaluated.

3. The proposed attack does not rely on the attacks. Moreover, the method is efficient as it directly manipulates the internal states of an LLM during its inference.
summary: This paper proposed a new defense to mitigate jailbreak attacks. The key idea of the proposed defense is to modify the internal state of an LLM during inference. The idea of the method is to extract a sparse safety feature vector and add it to the representation of a prompt. As a result, the model is more likely to refuse the malicious prompts.
weaknesses: 1. In general, the compared baselines are very weak. The authors may consider doing a comprehensive survey on the defenses against jailbreak attacks and add a discussion on these defenses. For instance, the authors could check this survey papers: https://arxiv.org/pdf/2407.04295 

2. The proposed method requires harmful prompts to identify safety direction. In the Appendix, it is mentioned that the dataset in Phan 2023 is used. Could authors evaluate the difference between this dataset and the dataset used for evaluation? For instance, whether there are many similar questions in the two datasets.

Additionally, a straightforward baseline is to use preference learning to finetune an LLM on this dataset. The authors may also consider comparing with this baseline in some settings (e.g., for small LLMs). 

3. Adaptive attacks are not considered. If an attacker knows the safety vector (or a surrogate one optimized by the attacker), could an attacker perform adaptive attacks to evade the defense?

4. Only one benchmark dataset and 100 prompts are used in the evaluation. The authors may consider evaluating the effectiveness of the defense on more benchmark datasets.

---

confidence: 4
contribution: 3
initial_rating: 5
presentation: 3
questions: I have some major comments on scope of related work and experiment design. 
- The design of Jailbreak Antidote reads very similar to SafeDecoding [a], with one modifying the internal state while the other modifying the token distribution. However, I could not find any comparison or discussion with it. It would be great to see the experimental comparisons between these two defenses. 
- Are the observations in A.3 consistent across all models? It is not clear which model was used to generate A.3.
- I wonder how would Jailbreak Antidote perform on uncensored models such as Dolphin-llama.
- The authors should include more attack methods such as [b] to evaluate the effectiveness of Jailbreak Antidote.
- Since utility is an important design goal, the authors should evaluate the model performance on more downstream tasks in addition to Win Rate, such as using WildBench, MMLU, and HellaSwag.
- Jailbreak Antidote seems to be sensitive to the choice of hyper-parameters. Is there any systematic way to choose these parameters, especially $\alpha$, for different models?

Minor comments:
- Although $d_{safe}^l$ and $m^l$ can be computed offline, it would be good to see the associated computational cost.
- Defense Tokens seem undefined.
- Is length controlled win rate also evaluated?
- In the notation of $h_S^l$, the subscript is not clear. The paper sometimes uses prompt as subscript, sometimes uses T as subscript.

[a] SafeDecoding: Defending against Jailbreak Attacks via Safety-Aware Decoding
[b] DeepInception: Hypnotize Large Language Model to Be Jailbreaker
soundness: 2
strengths: The tradeoff between LLM safety and utility is important. The paper is well-written and easy to follow. The authors showed some promising experimental results.
summary: This paper studies an efficient defense, named Jailbreak Antidote, against jailbreak attacks targeting LLMs. The goals of defense design include balancing safety and utility, as well as reducing overhead during inference time. The paper is based on an observation drawn from the representations of harmful and safe prompts. Given the distance between these two representations, the authors modify the hidden state by add the masked distance vector to it to improve safety performance. Evaluations over nine LLMs are presented to demonstrate the results.
weaknesses: The paper misses comparison or discussion to related work. Additional experimental evaluations on more LLMs and specific downstream tasks should be performed to better support the claims in this paper. See Questions for more detail.

---

confidence: 3
contribution: 3
initial_rating: 8
presentation: 4
questions: The paper is in a good shape and I enjoyed reading it. I have several questions on evaluation results.

The evaluation uses defense success rate against jailbreak attacks and win rate on benign prompts to demonstrate the balance between safety and utility. However, the defense success rate only represent the true positive rate of safety blocking, while false positive rate is missing. In other words, the statement in Section 4.3 "A higher \alpha emphasizes safety, making the model more conservative in its responses but potentially affecting utility by **increasing the refusal of borderline benign prompts**." is not validated by experiments. I would admit that the decent win rate on AlpacaEval has demonstrated that such borderline benign prompts is not common, but specific analysis on such failing cases is also meaningful. For instance, how much of the drop on win rate is because of false safety blocking?

Though the modification of internal state at inference stage should be very lightweight, I am unsure about the difficulty of the PCA step generating $d_{safe}$. How much data is used for PCA? How fast is the step especially for 70B large models?
soundness: 3
strengths: * The paper is looking at a well-defined hot security topic, the jailbreak problem.
* The paper is well written and easy to follow.
* The paper has a comprehensive evaluation, covering various state-of-the-art models, attack methods, mitigation baselines, etc., as well as ablation studies.
summary: The paper propose a new defense against jailbreak attacks, called Jailbreak Antidote. It adjusts internal hidden state of LLMs during inference, with parameters controlling the tradeoff between safety and utility. Extensive experiments prove the performance of the method.
weaknesses: * The evaluation of false positive rate of safety blocking is missing in evaluation. See questions.
* I did not find implementation details of the PCA step.

---

confidence: 4
contribution: 2
initial_rating: 5
presentation: 3
questions: * I think there need to be more specifications and analysis on Fig 2(a) and Sec 4.2. For example, how is this figure plotted? And how did you come to the conclusion that "the safety representation in LLMs is sparse"?

  From my understanding, most entries in each $\textbf{d}^l_{safe}$ are almost 0, which indicates *sparsity*. Then, what's the principle behind masking these safety representations (Eq 4)? Since most entries are already 0, in Eq 5, it doesn't make a difference whether you mask them or not, right?

* Are the DSP values reported in Table 1 averaged over all jailbreaking methods?

* Why the method works better for larger models? I see there are some discussions on this. But could you also perform some more in-depth studies (e.g., analyzing the representation distribution difference between small and large models) to provide more understanding about this?

* Could you also discuss the relationship of your observation of sparsity in safety representations, with [1]'s observation of sparsity in model weights that account for safety?

[1] Assessing the brittleness of safety alignment via pruning and low-rank modifications, ICML 2024
soundness: 2
strengths: * This proposed methodology to defend against jailbreaking attacks is neat. The paper is well structured and written.
* The finding of the sparsity (5\%) of safety representations is intriguing.
* The results are promising -- largely diminishing the success rate of jailbreaking attack while maintaining high utility, which surpass the compared baseline defenses.
summary: This paper proposes a defense method against LLM jailbreaking attacks, which operates at model inference-time by manipulating a sparse subset of the model's representations (internal states). Specifically, the internal states are moved towards pre-computed safe directions, which make the model's responses safer against harmful requests. This method enables better model safety without leading to significant utility drop.
weaknesses: * My major concern is the incremental contribution of this work to [1] and [2]. For example, in [1], the authors already provided extensive and thorough study regarding representation engineering, and discussed methods to adjust model behaviors against LLM jailbreak attacks. These existing work largely diminish the contribution of this paper.

* In line 78-79, you argued that safety alignment methods "lacks real-time flexibility." But on the other hand, you also did not highlight the benefit of "real-time flexibility" on your method. Then this point should not be emphasized too much.

* Should include more defense baseline comparison. I appreciate that the authors considered 6 existing jailbreak defense baselines which operate mostly at inference time, but I think it would be beneficial to consider safety alignment defenses as well, e.g., [3] and [4].

  In Line 79, you mentioned that these methods "*may* reduce model utility," but you didn't compare them with your method throughout the paper. Do they?

* In "Inference Efficiency Analysis" (page 8), the authors used "the number of defense tokens required" as a metric to compare method efficiency. This is clearly a bad metric for efficiency study -- compared to additional output tokens, additional input tokens induce less significant overhead. Thus, it's not clear whether the proposed method is indeed more efficient than the baseline methods. I suggest the authors use actual GPU time instead of number of defense tokens as the metric here.

  Also, could you elaborate on the (pre-inference) time cost to obtain the safety representations and masks?

* There should be some adaptive analysis against the proposed defense. That is, you should consider if an adversary is already aware that the victim model is deployed with your proposed defense. Then, if the adversary explicitly optimize for an adversarial prompt $S'$ against your safety representations, whehter / how much can this adaptive attack be defended by Jailbreak Antidote? This is an necessary study that should come alongside the proposed defense.

[1] Representation Engineering: A Top-Down Approach to AI Transparency, Arxiv 2023

[2] Steering Language Models With Activation Engineering, Arxiv 2024

[3] Improving Alignment and Robustness with Short Circuiting, NeurIPS 2024

[4] Safety Alignment Should Be Made More Than Just a Few Tokens Deep, Arxiv 2024

Meta-review: The submission received the ratings of four reviewers, which recommended 5, 6, 8 and 6, averaging 6.25. Given the plenty of competitive submissions in ICLR, this stands at a score above the borderline. The reviewers' concerns focus on the insufficient baselines, unclear technical parts or experimental setup, and the lack of analysis. After the substantial rebuttal by authors, most of reviewers considered the concerns well addressed, and one reviewer still maintain no response. After carefully checking the reviewer comments and the authors' feedback, the AC agreed with the authors' effort to address the remaining concerns. Therefore, I tend to recommend acceptance towards the current submission, and hope all advice are well incorporated into the final submission.

Decision: Accept (Poster)