Share your thoughts, 1 month free Claude Pro on usSee more
WorkDL logo mark

GradSafe: Detecting Jailbreak Prompts for LLMs via Safety-Critical Gradient Analysis

About

Large Language Models (LLMs) face threats from jailbreak prompts. Existing methods for detecting jailbreak prompts are primarily online moderation APIs or finetuned LLMs. These strategies, however, often require extensive and resource-intensive data collection and training processes. In this study, we propose GradSafe, which effectively detects jailbreak prompts by scrutinizing the gradients of safety-critical parameters in LLMs. Our method is grounded in a pivotal observation: the gradients of an LLM's loss for jailbreak prompts paired with compliance response exhibit similar patterns on certain safety-critical parameters. In contrast, safe prompts lead to different gradient patterns. Building on this observation, GradSafe analyzes the gradients from prompts (paired with compliance responses) to accurately detect jailbreak prompts. We show that GradSafe, applied to Llama-2 without further training, outperforms Llama Guard, despite its extensive finetuning with a large dataset, in detecting jailbreak prompts. This superior performance is consistent across both zero-shot and adaptation scenarios, as evidenced by our evaluations on ToxicChat and XSTest. The source code is available at https://github.com/xyq7/GradSafe.

Yueqi Xie, Minghong Fang, Renjie Pi, Neil Gong• 2024

Related benchmarks

TaskDatasetResultRank
Safety EvaluationHarmBench
ASR7.5
153
Safety EvaluationHEX-PHI
Attack Success Rate (ASR)5.88
107
Jailbreak DetectionAdvBench Llama2-7b
AUROC97.9
88
Safety EvaluationDirectHarm 4
Attack Success Rate9
87
Attack Success RateHEX-PHI
Attack Success Rate13.45
63
Jailbreak attack success rateHarmBench
Attack Success Rate (Generated)57
55
Attack Success RateDirectHarm4
Attack Success Rate65
54
Safety EvaluationHarmBench
ASR17.5
39
Jailbreak DetectionAverage of six attacks
Avg Success Rate0.00e+0
38
Adversarial and Jailbreaking Attack DetectionXSTest
AUROC0.984
35
Showing 10 of 73 rows
...

Other info

Code

Follow for update