SafeDecoding: Defending against Jailbreak Attacks via Safety-Aware Decoding

Zhangchen Xu, Fengqing Jiang, Luyao Niu, Jinyuan Jia, Bill Yuchen Lin, R. Poovendran

arXiv:2402.08983 · 2026-07-27 공개 · arXiv · PDF

language-models llm-safety jailbreak-attacks token-probabilities safety-disclaimers safe-decoding defense-methods response-helpfulness

Abstract

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.

한국어 요약

한 줄 요약

SafeDecoding은 해킹 공격에 대응하는 안전 인식 디코딩 전략으로, 해악성 토큰 확률을 감소시키고 안전 선언 토큰 확률을 증가시켜 LLM의 안전성을 향상시킨다.

핵심 기여도

핵심 아이디어

SafeDecoding은 해악성 토큰 확률이 무해한 토큰 확률보다 높더라도, 안전 선언 토큰이 상위 확률 토큰에 포함된다는 관찰에 기반한다. 이는 LLM이 내재적으로 해킹 공격에 대한 인식을 가지고 있음을 시사한다. SafeDecoding은 이러한 안전 선언 토큰을 식별하고 확률을 증폭시키며, 공격 목적에 맞는 토큰 시퀀스의 확률을 감소시킴으로써 해킹 공격을 억제한다. 이는 기존 디코딩 전략(예: greedy, top-k)이 해악성 토큰에 지배되어 실패하는 문제를 해결한다.

기술적 접근법

주요 결과

의의 및 한계

SafeDecoding은 LLM의 안전성을 향상시키는 새로운 디코딩 전략으로, 기존 방어 방법의 한계(예: 높은 계산 비용, 유용성 저하)를 극복한다. 특히, 해악성 토큰 확률을 감소시키고 안전 선언 토큰 확률을 증가시키는 방식은 기존 디코딩 전략과 비교해 더 정교한 안전성 관리가 가능하다. 그러나 하이퍼파라미터 조정이 필요하며, top-p 샘플링은 해악성 토큰 재샘플링을 유발할 수 있다는 한계가 있다.

실용적 활용

SafeDecoding은 챗봇, 코드 생성, 고객 지원 등 LLM이 활용되는 산업에서 해킹 공격에 대응하는 실용적 방어 전략으로 활용 가능하다. 특히, 안전성과 유용성을 동시에 유지하면서도 높은 성능을 보이는 SafeDecoding은 기업 및 연구 기관에서의 실제 도입이 기대된다.