Skip to content

Gradient Cuff: Detecting Jailbreak Attacks on Large Language Models by Exploring the Refusal Loss LandscapeGradient Cuff: Detecting Jailbreak Attacks on Large Language Models by Exploring Refusal Loss Landscapes

arXiv· arXiv:2403.00867· Xiaomeng Hu, Pin-Yu Chen, Tsung-Yi HoThe Chinese University of Hong Kong; IBM ResearchIndexed by this site · 27 days ago· Originally publishedDefenses

Quick read

Defenses

Based on the paper PDF (AI-generated); refer to the original

The authors propose Gradient Cuff, which uses refusal loss and its gradient norm in a two-step detection of jailbreaks; on LLaMA-2-7B-Chat and Vicuna-7B-V1.5, the average TPR across 6 attack types is 0.883/0.743 (FPR about 5%).

Threat modelThe attacker submits jailbreak prompts (inserting/replacing tokens or rewriting instructions) to an aligned LLM to bypass safety guardrails. The defender uses a white-box setting: access to model weights and internal representations (word embedding layer); closed-source models require deployment by the model developer. In adaptive attacks, the defense mechanism is transparent to the attacker.

Questions
Aligned LLMs are easily bypassed by jailbreak attacks that circumvent safety guardrails; the authors state that existing detection defenses either cannot cover all attack types (e.g., PPL is only effective against GCG) or falsely reject large numbers of benign queries (e.g., Erase-Check), making them difficult to use in practice.
Methods
Define the refusal loss (the probability that the model does not refuse across multiple samples), and find that malicious queries have smaller loss values and larger gradient norms; based on this, design a two-step detection: first refuse if the refusal loss is less than 0.5, then compare the gradient norm estimated by zeroth-order gradients against a threshold.
Experiments and results
On LLaMA-2-7B-Chat and Vicuna-7B-V1.5, the average TPR over 6 attack types is 0.883/0.743, with FPR about 5%; against Adaptive-PAIR on Vicuna, the refusal rate drops from 0.694 to 0.356; MMLU utility is close to PPL.
Limitations and future work
The authors acknowledge that keyword-based jailbreak determination has limitations and re-check with GPT-4 and LLaMA-Guard; white-box access is required, and closed-source models can only be deployed by the developer; adaptive attacks show a clear drop in effectiveness against PAIR on Vicuna; for non-LLaMA models, only Base64 and transferred GCG were tested.
Experimental setupLLaMA-2-7B-Chat、Vicuna-7B-V1.5 et al. · AdvBench(100 条 harmful behaviors)、LMSYS Chatbot Arena conversations(良性查询) et al. · TPR(恶意查询拒答率)、FPR(良性查询拒答率) et al.
Evaluated models
LLaMA-2-7B-ChatVicuna-7B-V1.5gemma-7b-itQwen2-7B-Instruct
Benchmarks
AdvBench(100 条 harmful behaviors)LMSYS Chatbot Arena conversations(良性查询)MMLU
Metrics
TPR(恶意查询拒答率)FPR(良性查询拒答率)ASRMMLU Accuracy
AI summaryThe researchers propose the Gradient Cuff method, which detects jailbreak attacks by exploring the refusal loss landscape of large language models. The method designs a two-step detection strategy using the function values and smoothness properties of the refusal loss landscape. Experiments on two aligned models, LLaMA-2-7B-Chat and Vicuna-7B-V1.5, against six types of jailbreak attacks—GCG, AutoDAN, PAIR, TAP, Base64 and LRL—show that Gradient Cuff significantly improves the models' ability to refuse malicious jailbreak queries and can maintain performance on benign user queries by adjusting the detection threshold.

The researchers propose the Gradient Cuff method, which detects jailbreak attacks by exploring the refusal loss landscape of large language models. The method designs a two-step detection strategy using the function values and smoothness properties of the refusal loss landscape. Experiments on two aligned models, LLaMA-2-7B-Chat and Vicuna-7B-V1.5, against six types of jailbreak attacks—GCG, AutoDAN, PAIR, TAP, Base64 and LRL—show that Gradient Cuff significantly improves the models' ability to refuse malicious jailbreak queries and can maintain performance on benign user queries by adjusting the detection threshold.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    How to detect jailbreak prompts on aligned LLMs without falsely refusing benign queries.

    Core problem: detect jailbreak attacks against aligned LLMs, blocking malicious queries while maintaining a low false refusal rate on benign queries.

    • Scenario and importance: LLMs serve as the backend of applications such as ChatGPT and Bing Search; even after RLHF alignment, they can still be bypassed by jailbreak attacks. The authors give the example that a jailbroken model can be induced to generate hate speech targeting a specific group (Figure 1a).
    • Shortcomings of existing defenses (per the authors): PPL detects GCG well but performs poorly on semantically fluent jailbreak prompts; Erase-Check and Self-Reminder falsely refuse many benign queries, being too conservative and impractical; the authors state that existing defenses "either cannot resist all types of jailbreak attacks, or cause obvious harm to benign queries."
    • Core observation: The authors define the refusal loss and plot its loss landscape, finding that malicious queries have smaller refusal loss values and larger gradient norms (Figure 1b), and that the gradient norm distributions of benign and malicious queries differ (Figure 1c, bottom right).
    • Proposed in the paper: Gradient Cuff, a two-step jailbreak detection method: first perform sampling-based refusal (refuse if refusal loss < 0.5), then perform gradient-norm-based refusal (refuse if the zeroth-order estimated gradient norm exceeds a threshold), with the threshold selected on a benign validation set according to a target FPR σ.
    • Threat model:
      • Attacker goal: use jailbreak prompts (inserting/replacing tokens or rewriting instructions) to make an aligned LLM follow malicious instructions.
      • Attacker knowledge: evaluation covers white-box (GCG), gray-box (AutoDAN), black-box (PAIR, TAP), and rule-based attacks (Base64, LRL); adaptive attacks assume the defense mechanism is transparent to the attacker.
      • Defender knowledge: white-box setting, with access to model weights and internal representations (word embedding layer); closed-source models require deployment by the model developer.
      • Victim system: aligned open-source LLMs (LLaMA-2-7B-Chat, Vicuna-7B-V1.5; the appendix additionally tests gemma-7b-it and Qwen2-7B-Instruct).
  2. What related research exists?

    Related work falls into two categories: jailbreak attacks and jailbreak defenses. This paper is positioned as a training-free detection-based defense.

    Jailbreak attacks

    • Feedback-based attacks: GCG (2023) requires white-box access and optimizes a universal adversarial suffix using gradients with respect to one-hot token indicators; AutoDAN (2023) requires gray-box access and uses the generation loss of the target response as fitness; PAIR (2023) and TAP (2023) require only black-box access, with two LLMs, an attacker and an evaluator, iteratively rewriting the prompt.
    • Rule-based attacks: Base64 (2023) encodes the malicious instruction in base64; LRL (2023) translates the instruction into languages rarely seen in training (German, Swedish, French, Chinese).

    Training-free (unsupervised) defenses

    • PPL (2023): uses an LLM to compute the input perplexity and refuses high-perplexity queries; the paper notes that it performs poorly on semantically fluent jailbreak prompts.
    • SmoothLLM (2023): perturbs the input to obtain multiple copies and aggregates the responses, motivated by randomized smoothing.
    • Erase-Check (2023): checks whether the original query or its clauses after deletion are harmful; the paper notes that it falsely refuses a large number of benign queries.
    • Prompt engineering methods: Self-Reminder (2023) modifies the system prompt to make the model remind itself; the paper calls its results promising but notes that it falsely refuses benign queries.

    Supervised defenses

    • LLaMA-Guard (2024): trains a LLaMA-family model to judge whether a query or response contains unsafe content.
    • Safe-Decoding (2024): fine-tunes an expert model on (malicious query, refusal) pairs and guides safe decoding at inference time.

    Baselines and benchmarks: The comparison baselines are PPL, Erase-Check, SmoothLLM, Self-Reminder (training-free) and LLaMA-Guard, Safe-Decoding (require training); malicious queries are taken from 100 harmful behaviors in AdvBench, benign queries come from LMSYS Chatbot Arena, and utility is measured with MMLU.

    Positioning of this paper: The authors state that they mainly focus on training-free methods because they require no training and only need to deploy the protected model itself at inference time; they also state that Gradient Cuff is the "only" defense algorithm that can maintain good jailbreak detection while keeping the benign refusal rate at an acceptable level.

  3. How does the paper address this problem?

    Defines a refusal loss and uses its function value and the gradient norm of a zeroth-order estimate for two-step detection.

    Overall idea: model "whether the model refuses" as a samplable loss function, and use the property that malicious queries have "smaller values and larger gradient norms" on this loss landscape to perform two-step detection; the method is named Gradient Cuff.

    Definition of the refusal loss

    • For an input query x, define ϕθ(x) = 1 − pθ(x), where pθ(x) = Ey ∼ Tθ(x) JB(y) is the model's expected refusal rate for x; JB(·) is a binary indicator function that is 1 if the response contains any refusal keyword (such as "Sorry", "I cannot"; the list is in Appendix A.3).
    • In practice, it is approximated by the sample mean of N independent samples: fθ(x) = 1 − 1/N∑i=1N Yi. fθ(x) < 0.5 can serve as a naive detector, but the authors state that relying on it alone has limited effectiveness against jailbreak attacks (verified in Section 4.3).

    Zeroth-order estimation of the gradient norm

    • Exact gradients are infeasible (JB(·) is a discrete operation and may involve a black-box evaluation function), so zeroth-order gradient estimation is used: add the same Gaussian perturbation µ·ui to each row of the word embedding matrix eθ(x) (using the linearity of mean-pooling, equivalent to perturbing the sentence vector), approximate the gradient with directional derivatives, and sum over P random directions.
    • Theorem 1 gives a probabilistic guarantee: when ∇ϕθ is L-Lipschitz, the estimation error is at most ϵ with probability at least 1−δ, where δ = Ω(1/N + 1/P) and ϵ = Ω(1/√P), i.e., increasing N and P can reduce the error (proof in Appendix A.12).

    Two-step detection procedure (Algorithm 1)

    • Step 1 sampling-based refusal: compute fθ(x); if < 0.5, refuse directly; otherwise proceed to Step 2.
    • Step 2 gradient-norm-based refusal: estimate the gradient norm ∥gθ(x)∥; if it is greater than threshold t, refuse.
    • Threshold selection: on the benign validation set Bval, select t such that the total benign refusal rate does not exceed the user-specified FPR σ (5% in the main experiments).
    • Query overhead: the total number of queries is at most q = N·(P+1); the main experiments use µ = 0.02, N = P = 10 (i.e., q = 110); the authors state that with batch inference, the number of queries becomes 10 times but the runtime increases only 1.3 times (Appendix A.15).

    Determination and evaluation method

    • Refusal/jailbreak determination uses the keyword indicator function JB(·); the authors acknowledge the limitations of this method and additionally re-check ASR with two reviewers, GPT-4 (using PAIR's system prompt) and Meta-Llama-Guard-2-8B (Appendix A.6).
    • Generation settings: temperature 0.6, top-p 0.9, Nucleus Sampling, with the fastchat default system prompt; each experiment is run with 5 random seeds (13, 21, 42, 87, 100) and averaged.
  4. What experiments did the paper conduct?

    Compares 6 defenses on 2 aligned LLMs across 6 jailbreak attack types, and also tests adaptive attacks, utility, and ablations.

    Experimental Setup

    • Models tested: LLaMA-2-7B-Chat, Vicuna-7B-V1.5 (main experiments); Appendix A.17 additionally tests gemma-7b-it and Qwen2-7B-Instruct.
    • Malicious queries: 100 harmful behaviors sampled from AdvBench, with jailbreak prompts generated by GCG, AutoDAN, PAIR, and TAP respectively, Base64 encoding, and LRL translation into de/fr/sv/zh-CN (LRL reports the average over 4 languages).
    • Benign queries: LMSYS Chatbot Arena conversations; after removing toxic, non-instructional, and queries shorter than 20, 100 are sampled as the test set and the rest as the validation set for threshold selection.
    • Baselines: PPL, Erase-Check, SmoothLLM, Self-Reminder (training-free); LLaMA-Guard (Meta-Llama-Guard-2-8B), Safe-Decoding (require training).
    • Metrics: TPR = average refusal rate over the 6 malicious datasets, FPR = refusal rate on the benign test set; refusal is determined by the keyword JB(·), and ASR is additionally re-checked with GPT-4 and LLaMA-Guard; utility is measured by MMLU zero-shot accuracy.
    • Parameters and repetitions: Gradient Cuff uses µ=0.02, N=P=10, σ=5%; each experiment is run with 5 random seeds and averaged, reporting the standard error.

    Main Results

    According to Table A2 (the complete data of Figure 2, σ=5%):

    Swipe horizontally to read the table

    ModelDefenseFPRTPR (average over 6 attacks)
    LLaMA-2-7B-ChatGradient Cuff0.0220.883
    LLaMA-2-7B-ChatSmoothLLM0.0040.763
    LLaMA-2-7B-ChatPPL0.0520.732
    LLaMA-2-7B-ChatErase-Check0.9880.865
    Vicuna-7B-V1.5Gradient Cuff0.0340.743
    Vicuna-7B-V1.5SmoothLLM0.0000.413
    Vicuna-7B-V1.5PPL0.0580.401
    Vicuna-7B-V1.5Erase-Check0.8620.905
    • The authors state that Gradient Cuff achieves high TPR and low FPR on both models, and has the most balanced TPR across attack types (Figure 2 error bars).
    • Erase-Check's TPR is close to Gradient Cuff's, but its FPR reaches 0.988/0.862, which the authors consider impractical.
    • By attack (Table A2): on LLaMA-2, Gradient Cuff achieves 0.988 for GCG, 0.950 for TAP, 0.946 for LRL, and the lowest, 0.770, for PAIR; on Vicuna, it achieves 1.000 for Base64 and the lowest, 0.492, for AutoDAN.

    Combination with Self-Reminder and Comparison with Supervised Methods

    • Combination experiment (Table 1/A3): Self-Reminder's system prompt is installed into Gradient Cuff (denoted Self-Reminder (GC)), with σ set to the benign refusal rate of the original Self-Reminder. The authors state that after combination, Self-Reminder's malicious refusal rate increases by 12.20% on LLaMA-2 and by 34.96% on Vicuna; however, Self-Reminder (GC)'s TPR (0.920/0.637) is lower than Gradient Cuff's under the same setting (0.968/0.665), and the authors consider system prompt engineering to have little effect when Gradient Cuff is already present.
    • Supervised methods (Table 2/A4): LLaMA-Guard's TPR on Vicuna, 0.773, is close to Gradient Cuff's 0.743, while on LLaMA-2 its 0.760 is lower than 0.883; Safe-Decoding has the highest TPR (0.955/0.880) but a higher FPR (0.080/0.280), and the authors state that it causes an obvious utility drop.

    Adaptive Attacks

    • Design: Adaptive versions are designed for PAIR, TAP, and GCG respectively (Appendix A.10); Adaptive-GCG requires white-box access and knowledge of Gradient Cuff details (such as P), while the other two only require model responses; all are evaluated at σ=5%.
    • Results (Table 4): Gradient Cuff's refusal rate against Adaptive-GCG is almost unchanged (0.988→0.986 on LLaMA-2, 0.892→0.880 on Vicuna); Adaptive-TAP on LLaMA-2 goes from 0.950 to 0.898; Adaptive-PAIR on Vicuna drops from 0.694 to 0.356, the combination with the largest drop.
    • Mechanism (Table A5): The median gradient norm of prompts generated by Adaptive-GCG drops from 1013.24 to 929.72 (LLaMA-2) and from 875.83 to 636.38 (Vicuna), but remains above the detection thresholds 429.33/131.19; based on this, the authors argue that Adaptive-GCG fails because it cannot push the gradient norm below the threshold.

    Utility and Other Evaluations

    • MMLU (Table 5, Figure 4): Gradient Cuff's MMLU accuracy is 0.378 (LLaMA-2)/0.462 (Vicuna), PPL's is 0.411/0.487, and SmoothLLM's is 0.271/0.303; the authors state that Gradient Cuff achieves the best performance-utility trade-off, and that SmoothLLM harms semantics by modifying user queries.
    • GPT-4/LLaMA-Guard re-check (Table A1): On Vicuna, Gradient Cuff's GPT-4 ASR is 0.1296 and LLaMA-Guard ASR is 0.1171, lower than SmoothLLM (0.2354/0.2408) and PPL (0.3200/0.2854); on LLaMA-2, Gradient Cuff is 0.0279/0.0229, close to SmoothLLM's 0.0192/0.0188.
    • Non-LLaMA models (Table A8): Only Base64 and GCG transferred from Vicuna are tested; Gradient Cuff's average refusal rate is 0.79 on gemma-7b-it and 0.99 on Qwen2-7B-Instruct, PPL's is 0.49/0.52, and SmoothLLM's is 0.45/0.39.

    Other Ablations and Analyses

    • Second-stage ablation (Table 3): After removing gradient-norm-based refusal, TPR drops from 0.883 to 0.698 (LLaMA-2) and from 0.743 to 0.296 (Vicuna, σ=5%).
    • N, P ablation (Figure A2, σ=10%): When q increases from 10 to 40, the TPR improvement from increasing P with N fixed (0.137) is 5.27 times that from increasing N with P fixed (0.026).
    • Query budget comparison (Figure A3): At q=110, Gradient Cuff's malicious refusal rate is 1.16 times (LLaMA-2)/1.80 times (Vicuna) that of SmoothLLM.
    • Efficiency (Table A7, Vicuna): Gradient Cuff takes 4.59s and 42.36GB per query, close to SmoothLLM (4.24s, 42.75GB), while PPL takes 0.44s and 26.10GB; when the first stage exits early, the runtime is only 2.3 times that of no defense (0.97s vs 0.42s).
    • Malicious queries without jailbreak (Figure A5): For AdvBench instructions without jailbreak prompts, all methods have relatively high refusal rates.
  5. What are some points that can be further explored?

    The authors discuss the jailbreak determination method and the additional inference overhead; the experiments cover 2–4 models and 6 attack types.

    Limitations and future directions noted by the authors

    • Jailbreak determination method (Section 5, Jailbroken Assessment): The authors acknowledge that determination based on predefined keywords "has obvious limitations" and that it is difficult to enumerate and cover all jailbreak scenarios; more reliable success determination methods are needed. The paper uses GPT-4 and LLaMA-Guard re-checking as mitigation.
    • Extra inference overhead (Section 5, Extra Inference Cost): The authors consider the trade-off between performance and inference efficiency unavoidable (though improvable); Appendix A.13 notes that increasing the number of queries lengthens runtime, and that batch inference and similar methods can be used for speedup.
    • Applicability conditions for closed-source models (Section 5): The method adopts a white-box setting; closed-source models can only be deployed by the model developer (who can access parameters including the embedding layer).
    • Attack coverage for non-LLaMA-family models (Appendix A.17): Due to rebuttal time and compute constraints, jailbreak prompts for GCG, PAIR, AutoDAN, and TAP could not be generated for gemma/Qwen2; the authors state the attacks are running and results will be updated upon completion.

    Experimental coverage

    • The main experiments test 2 models in total: LLaMA-2-7B-Chat and Vicuna-7B-V1.5; Appendix A.17 adds gemma-7b-it and Qwen2-7B-Instruct, but tests only two attack types: Base64 and GCG transferred from Vicuna.
    • Attacks cover 6 types in total: GCG, AutoDAN, PAIR, TAP, Base64, and LRL; adaptive attacks cover only three: PAIR, TAP, and GCG.
    • Malicious queries are 100 sampled from AdvBench, and the benign test set has 100; each group of experiments uses 5 random seeds.
    • Refusal determination primarily uses the keyword JB(·); re-check reviewers are GPT-4 and Meta-Llama-Guard-2-8B; the paper does not report the consistency between reviewer determinations and human annotation.
    • Utility evaluation is MMLU zero-shot; efficiency evaluation (Table A7) is conducted on Vicuna-7B-V1.5.
  6. Summarize the main content of the paper

    Gradient Cuff: two-step jailbreak detection using the refusal loss value and gradient norm, balancing detection rate and benign false refusals.

    A jailbreak detection defense paper (NeurIPS 2024), aiming to block jailbreak prompts on aligned LLMs while keeping the false refusal rate on benign queries at a user-specified level.

    • Problem: The authors state that existing training-free defenses cannot balance the two types of queries—PPL is only effective against GCG-type attacks, and Erase-Check refuses almost all benign queries (FPR 0.988/0.862).
    • Method: Define the refusal loss (the probability that the model does not refuse across multiple samples), and observe that malicious queries have smaller loss values and larger gradient norms; Gradient Cuff first refuses if the loss value < 0.5, then for those that pass, compares the zeroth-order estimated gradient norm against a threshold, with the threshold selected on a benign validation set according to a target FPR σ; the main experiments use N=P=10, σ=5%.
    • Main results: Average TPR 0.883 on LLaMA-2-7B-Chat (FPR 0.022) and 0.743 on Vicuna-7B-V1.5 (FPR 0.034), higher than PPL (0.732/0.401) and SmoothLLM (0.763/0.413) (Table A2).
    • Adaptive attacks: Almost no effect on Adaptive-GCG, but Adaptive-PAIR on Vicuna drops the refusal rate from 0.694 to 0.356 (Table 4).
    • Utility and re-check: MMLU accuracy 0.378/0.462, close to PPL and higher than SmoothLLM (Table 5); the ASR conclusions from GPT-4 and LLaMA-Guard re-checks are consistent with keyword-based determination (Table A1).
    • Authors' conclusion: The authors state that Gradient Cuff achieves state-of-the-art jailbreak detection while maintaining benign utility, and can complement prompt engineering methods such as Self-Reminder; they also acknowledge that keyword-based determination has limitations, the method requires white-box access, and inference overhead increases.

Related papers

Show 3 more papers
Read originalarxiv.org