[Paper Review] SafeDecoding: Defending against Jailbreak Attacks via Safety-Aware Decoding
This paper proposes SafeDecoding, a safety-aware decoding strategy that defends large language models against jailbreak attacks by amplifying probabilities of safety disclaimer tokens and suppressing harmful response tokens. By leveraging a fine-tuned expert model and balancing original and expert token distributions, SafeDecoding reduces jailbreak success rates by up to 90% without sacrificing helpfulness on benign queries.
As large language models (LLMs) become increasingly integrated into real-world applications such as code generation and chatbot assistance, extensive efforts have been made to align LLM behavior with human values, including safety. Jailbreak attacks, aiming to provoke unintended and unsafe behaviors from LLMs, remain a significant/leading LLM safety threat. In this paper, we aim to defend LLMs against jailbreak attacks by introducing SafeDecoding, a safety-aware decoding strategy for LLMs to generate helpful and harmless responses to user queries. Our insight in developing SafeDecoding is based on the observation that, even though probabilities of tokens representing harmful contents outweigh those representing harmless responses, safety disclaimers still appear among the top tokens after sorting tokens by probability in descending order. This allows us to mitigate jailbreak attacks by identifying safety disclaimers and amplifying their token probabilities, while simultaneously attenuating the probabilities of token sequences that are aligned with the objectives of jailbreak attacks. We perform extensive experiments on five LLMs using six state-of-the-art jailbreak attacks and four benchmark datasets. Our results show that SafeDecoding significantly reduces the attack success rate and harmfulness of jailbreak attacks without compromising the helpfulness of responses to benign user queries. SafeDecoding outperforms six defense methods.
Motivation & Objective
- To address the growing threat of jailbreak attacks that bypass existing safety alignment in large language models.
- To develop a defense mechanism that maintains model helpfulness while effectively mitigating harmful outputs during jailbreak attempts.
- To overcome limitations of existing defenses such as high inference cost, reduced utility, or failure against state-of-the-art attacks.
- To exploit the inherent presence of safety disclaimer tokens in the model’s top-predicted tokens, even under attack.
- To design a decoding strategy that dynamically balances safety and utility through a hybrid token probability distribution.
Proposed method
- Train an expert model on a safety-aware dataset generated from the original LLM, fine-tuning it to prioritize safety disclaimers.
- During inference, construct a sample space by intersecting the top-k tokens from both the original and expert models.
- Form a new token probability distribution by combining the original model’s logits with the expert model’s logits, emphasizing safety tokens.
- Apply a temperature-scaled sampling strategy on the hybrid distribution to generate responses that are both helpful and safe.
- Dynamically attenuate probabilities of token sequences aligned with jailbreak objectives while amplifying those associated with refusal or safety disclaimers.
- Integrate the method as a post-processing decoding layer compatible with standard LLM inference pipelines.

Experimental results
Research questions
- RQ1Can a safety-aware decoding strategy effectively reduce the success rate of state-of-the-art jailbreak attacks across diverse LLMs?
- RQ2Does SafeDecoding maintain high helpfulness on benign user queries while defending against adversarial prompts?
- RQ3How does SafeDecoding compare to existing defense methods in terms of effectiveness, efficiency, and utility trade-offs?
- RQ4Can SafeDecoding be applied effectively to both aligned and uncensored LLMs, including models like Dolphin and Guanaco?
- RQ5Is the presence of safety disclaimer tokens in the top-k probability space sufficient to enable reliable defense via probability manipulation?
Key findings
- SafeDecoding reduces the attack success rate (ASR) of six state-of-the-art jailbreak attacks by up to 90% across five LLMs.
- On the HHH benchmark, SafeDecoding reduces harmfulness scores by 4.402 (from 4.842 in baseline) while maintaining a helpfulness score of 4.296.
- SafeDecoding outperforms six baseline defense methods in both defense effectiveness and utility preservation, especially on uncensored models like Dolphin.
- The expert model alone fails to generalize across attacks and significantly degrades helpfulness, indicating that fine-tuning alone is insufficient.
- SafeDecoding maintains low inference overhead and is compatible with various model architectures, including Llama2, Vicuna, and Falcon.
- In ablation studies, SafeDecoding shows consistent performance across different temperature settings and top-k sampling configurations.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.