Skip to content

Token Highlighter: Inspecting and mitigating jailbreak prompts in large language modelsToken Highlighter: Inspecting and Mitigating Jailbreak Prompts for Large Language Models

arXiv· arXiv:2412.18171· 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 the jailbreak defense Token Highlighter: using Affirmation Loss gradients to locate critical tokens and applying Soft Removal, average ASR on Vicuna-7B-V1.5 drops from 0.730 to 0.142.

Threat modelAttackers submit jailbreak prompts to aligned LLMs (token-level such as GCG, prompt-level such as TAP, PAIR, AutoDAN, AIM, Manyshot) to induce the model to output harmful content; the defense is deployed at the inference stage of the target LLM and requires access to the model's embedding layer and computation of one forward and one backward pass; in adaptive attack evaluations, the defense mechanism is transparent to the attacker.

Questions
Aligned LLMs can still be bypassed by jailbreak attacks that circumvent safety guardrails, and existing defenses have shortcomings: perplexity filtering is ineffective against fluent jailbreak prompts, detection-based methods have high false positive rates, and multiple-query methods have high inference overhead.
Methods
Proposes Token Highlighter: defines Affirmation Loss to measure the model's willingness to generate an affirmative response, uses the gradient norm of this loss with respect to each token embedding to locate jailbreak-critical tokens, and then uses Soft Removal (multiplying embeddings by β) to weaken the influence of these tokens.
Experiments and results
Evaluated on Vicuna-7B-V1.5 and LLaMA-2-7B-Chat under 6 jailbreak attacks: on Vicuna, average ASR drops from 0.730 to 0.142, with Win Rate maintained at 0.698; adaptive attacks bring an ASR increase of at most 0.1; runtime is lower than baselines requiring multiple queries.
Limitations and future work
The paper does not specifically discuss limitations. The experiments cover only 2 aligned models at the 7B scale, 6 attacks, and the AlpacaEval utility benchmark; ASR is judged by LLaMA-Guard-2-8B, and the paper does not report manual review or judge consistency.
Experimental setupVicuna-7B-V1.5、LLaMA-2-7B-Chat · AdvBench、AlpacaEval · ASR、Win Rate
Evaluated models
Vicuna-7B-V1.5LLaMA-2-7B-Chat
Benchmarks
AdvBenchAlpacaEval
Metrics
ASRWin Rate
AI summaryToken Highlighter inspects and mitigates jailbreak prompts in large language models. It uses Affirmation Loss to measure the model's willingness to answer a user query, locates jailbreak-critical tokens based on its gradients, and then uses Soft Removal to shrink the embeddings of these tokens to eliminate the jailbreak effect. On the two aligned models LLaMA-2 and Vicuna-V1.5, the method effectively defends against multiple jailbreak attacks while maintaining performance on benign questions in AlpacaEval.

Token Highlighter inspects and mitigates jailbreak prompts in large language models. It uses Affirmation Loss to measure the model's willingness to answer a user query, locates jailbreak-critical tokens based on its gradients, and then uses Soft Removal to shrink the embeddings of these tokens to eliminate the jailbreak effect. On the two aligned models LLaMA-2 and Vicuna-V1.5, the method effectively defends against multiple jailbreak attacks while maintaining performance on benign questions in AlpacaEval.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    How to defend against jailbreak attacks on aligned LLMs at low inference cost while not harming utility on benign queries.

    Core question: how to defend against jailbreak attacks on aligned LLMs while avoiding the shortcomings of existing defenses in utility and inference cost.

    • Problem setting: The authors point out that even LLMs aligned with RLHF can still be bypassed by jailbreak attacks that circumvent safety guardrails, where attackers rewrite malicious queries at the token level or prompt level to induce the model to output harmful content (e.g., GCG inserts a universal adversarial suffix).
    • Shortcomings of existing defenses: The authors summarize three points—(1) perplexity filtering (PPL) performs poorly on interpretable, fluent jailbreak prompts; (2) detection-based defenses have high false positive rates, harming performance on benign queries; (3) defenses that rely on querying the LLM multiple times (such as smoothing-based ones) have high inference cost.
    • Core observation: The authors cite recent work stating that successful jailbreaks often first induce the LLM to generate an affirmative opening (such as "Sure, here's..."), so finding the tokens most critical to generating an affirmative response and weakening their influence can mitigate jailbreaks.
    • Paper's approach: Proposes Token Highlighter, which uses the gradient of the Affirmation Loss to locate jailbreak-critical tokens, then uses Soft Removal (multiplying the embeddings of critical tokens by β∈[0,1]) to weaken their influence; only one additional query is needed to compute the Affirmation Loss, and the highlighted tokens can be used to explain the refusal.
    • Threat model:
      • Attacker's goal: make the aligned LLM give an affirmative, helpful answer to a harmful instruction.
      • Attack methods: token-level jailbreaks (GCG) and prompt-level jailbreaks (AutoDAN, PAIR, TAP, AIM, Manyshot), controlling the user query input.
      • Victim system: aligned LLMs (in the experiments, LLaMA-2-7B-Chat and Vicuna-7B-V1.5).
      • Defender's capabilities: deployed at the target LLM's inference stage, requiring access to the embedding layer and computation of gradients; in the adaptive attack evaluation, the defense mechanism is fully transparent to the attacker.
  2. What related research exists?

    Related work falls into two lines: jailbreak attacks (token-level and prompt-level) and jailbreak defenses (detection, smoothing, prompt engineering).

    Jailbreak attacks

    • GCG (Zou et al., 2023): A pioneering work on token-level jailbreaks; it computes the target LLM's generation loss for an affirmative response, uses its gradient with respect to the one-hot token indicators to find a better token at each position, and constructs a universal adversarial suffix.
    • Manual prompt-level jailbreaks (AIM, Manyshot): Encapsulate malicious instructions into predefined templates; Manyshot inserts multiple fabricated human-machine dialogues before the query.
    • Automatic prompt-level jailbreaks (AutoDAN, PAIR, TAP): AutoDAN uses the target LLM's generation loss as a fitness score to guide optimization; PAIR and TAP use two other LLMs as attacker and evaluator respectively, iteratively rewriting the prompt until the evaluator gives a full score.

    Jailbreak defenses

    • Detection-based (PPL, Erase Check, Gradient Cuff): PPL uses an LLM to compute the input perplexity and rejects high-perplexity queries; Erase Check checks whether the input and its clause-deleted version are harmful; Gradient Cuff proposes Refusal Loss and performs two-stage detection using its value and gradient norm.
    • Smoothing-based (SmoothLLM, Semantic Smoothing): Inspired by randomized smoothing, they perturb the input to generate multiple copies and aggregate the responses; SmoothLLM uses character-level perturbations, and Semantic Smoothing uses semantic transformations such as summarization, paraphrasing, and spell checking.
    • Prompt engineering-based (Self Reminder, etc.): Defend by modifying the system prompt or embedding user input into predefined templates; Self Reminder lets the model remind itself to maintain an aligned perspective.

    Baselines and benchmarks

    • Comparison baselines: PPL, Erase Check, Gradient Cuff, SmoothLLM, Semantic Smoothing, Self Reminder, and the Random Soft Removal constructed by the authors (randomly selecting tokens for soft removal).
    • Evaluation benchmarks: Malicious queries are taken from AdvBench (100 harmful behavior instructions sampled), and utility is evaluated with AlpacaEval.

    Positioning of this paper

    The authors state that existing defenses respectively suffer from being ineffective against fluent jailbreaks, having high false positive rates, or requiring multiple queries; Token Highlighter needs only one additional query to locate and weaken critical tokens, balancing defense effectiveness, utility, and runtime efficiency, and the highlighting results can serve as an explanation for refusal.

  3. How does the paper address this problem?

    Use the gradient of Affirmation Loss to find the tokens with the greatest influence on the affirmative response, then shrink their embeddings via Soft Removal.

    Overall idea: A successful jailbreak depends on inducing the LLM to generate an affirmative opening; Token Highlighter first quantifies each input token's influence on generating an affirmative response, then weakens the embeddings of high-influence tokens, in two steps.

    Affirmation Loss and Critical Token Localization

    • Affirmation Loss definition: Given the target LLM and the embedding matrix of a user query, define Affirmation Loss(x1:n, θ) = −log Pθ(y|x1:n), where y is a predefined affirmative sentence (a single affirmative response expressing willingness to help is used throughout the paper); this loss measures the model's willingness to answer the user query.
    • Token influence: Influence(xi) = |∇xi log Pθ(y|x1:n)|2, i.e., the norm of the gradient of the loss with respect to each token embedding.
    • Critical Set construction: Sort by influence and take the top-nα tokens to form the Critical Set Q, where α∈[0,1] is the highlight percentage.

    Soft Removal Mitigation Mechanism

    • Design motivation: The authors cite prior work stating that directly deleting critical tokens (Hard Removal, equivalent to β=0) can lower ASR but noticeably harms performance on benign queries, so they propose the compromise Soft Removal.
    • Soft Removal operation: For tokens in Q, multiply their embeddings by β∈[0,1], leaving other tokens unchanged; the processed query is called the highlighted user query, and the model's response to this query is the final output.

    Algorithm Flow and Parameters

    1. Step #1: Compute the query's embedding matrix and Affirmation Loss, compute each token's Influence, and take the top-nα to construct Q.
    2. Step #2: Multiply the embeddings of tokens in Q by β, and generate the final response using the modified embeddings.
    • Cost: Step #1 requires only one forward and one backward pass; the authors state the defense computation is lightweight.
    • Experimental parameters: Both models use α=0.25; β is 0.3 on Vicuna-7B-V1.5 and 0.5 on LLaMA-2-7B-Chat to balance Win Rate and ASR; generation uses Nucleus Sampling with temperature=0.6 and top-p=0.9, and the system prompt uses fastchat's default settings.

    Success Determination and Evaluation Method

    • ASR: LLaMA-Guard-2-8B classifies the protected model's response; outputting "Unsafe" means the jailbreak is judged successful.
    • Win Rate: On all 805 AlpacaEval instructions, output quality is compared using text-davinci-003's responses as reference and GPT-4 as judge.
  4. What experiments did the paper conduct?

    Compares 6 defense baselines on 2 aligned LLMs and 6 jailbreak attacks, and conducts parameter trade-off, runtime, adaptive attack, and interpretability analyses.

    Experimental Setup

    • Models tested: LLaMA-2-7B-Chat and Vicuna-7B-V1.5 (referred to in the paper as protected LLM).
    • Malicious queries: 100 harmful behavior instructions sampled from AdvBench, with jailbreak prompts generated using GCG, AutoDAN, PAIR, TAP, AIM, and Manyshot respectively; Manyshot uses 32 fabricated dialogue turns and is combined with GCG.
    • Baselines: PPL, Erase Check, Gradient Cuff, SmoothLLM, Semantic Smoothing, Self Reminder, and a Random Soft Removal constructed by the authors.
    • Metrics: ASR (LLaMA-Guard-2-8B judges whether the response is Unsafe) and AlpacaEval Win Rate (GPT-4 judge, text-davinci-003 as reference, 805 instructions).
    • Token Highlighter parameters: α=0.25; β=0.3 (Vicuna) / 0.5 (LLaMA-2); random seed 100, single A800 GPU.

    Main Results

    According to Table A5 (average ASR is the average over 6 attacks, Win Rate is AlpacaEval):

    Swipe horizontally to read the table

    ModelDefenseAverage ASR ↓Win Rate ↑
    Vicuna-7B-V1.5w/o defense0.7300.772
    Vicuna-7B-V1.5Token Highlighter0.1420.698
    Vicuna-7B-V1.5Random Soft Removal0.5500.743
    Vicuna-7B-V1.5Gradient Cuff0.4080.738
    Vicuna-7B-V1.5Semantic Smoothing0.1320.301
    LLaMA-2-7B-Chatw/o defense0.1150.763
    LLaMA-2-7B-ChatToken Highlighter0.0180.747
    LLaMA-2-7B-ChatSelf Reminder0.0020.501

    (The three rows Erase Check, SmoothLLM, and PPL are omitted; on Vicuna, Erase Check's Win Rate is 0.211, the lowest in the table.)

    • The authors state that Token Highlighter has the lowest ASR among methods maintaining a high Win Rate: on Vicuna, ASR drops from 0.730 to 0.142, while the best baseline Gradient Cuff only drops to 0.243.
    • The authors point out that Semantic Smoothing's ASR can be comparable or even lower (0.132), but its Win Rate drops to 0.301, a large utility loss.
    • On LLaMA-2-7B-Chat, all baselines can push ASR close to zero; the authors attribute this to LLaMA-2 being harder to jailbreak; the comparison with Random Soft Removal is used by the authors to argue for the effectiveness of the Critical Set construction.

    Combination with Self Reminder

    • What was tested: Combining Self Reminder's system prompt with Token Highlighter (Self Reminder (TH)), sweeping β on Vicuna-7B-V1.5 (Table 1, Table A7).
    • Results: At β=0.5, ASR drops from Self Reminder's 0.427 to 0.362, with Win Rate 0.653 (originally 0.684); at β=0.3, ASR 0.023, Win Rate 0.536; at β=0.2, ASR 0.015, Win Rate 0.328.
    • Authors' interpretation: The combined ASR-WIN trade-off is better than Self Reminder alone; reducing β can further lower ASR, at the cost of Win Rate.

    Adaptive Attacks

    • What was tested: Adaptive-GCG and Adaptive-TAP were designed based on GCG and TAP, with the attacker fully aware of the defense mechanism (the algorithm is given in Appendix A.7).
    • Results: Adaptive-GCG increases ASR by 0.1 on Vicuna and 0.02 on LLaMA-2; Adaptive-TAP by 0.04 and 0.01 respectively (Section 4.5, Figure 5).
    • Authors' interpretation: Adaptive attacks can increase ASR to some extent, but the increase is small; the authors state the method is robust to adaptive attacks.

    Runtime and Interpretability

    • Runtime: 25 queries selected from AlpacaEval were used to measure the wall clock time of each defense on Vicuna (Figure 4); the authors state that Token Highlighter is the only method achieving low ASR, high Win Rate, and low runtime simultaneously; each point in the figure is annotated with average time, but the specific values are unreadable in the converted text.
    • Interpretability: For GCG prompts, the highlighted tokens all fall within the inserted adversarial suffix; for TAP prompts, the highlighted tokens correspond to rewriting strategies such as role-playing, content dilution, and instructing to begin with an affirmative sentence (Table A1); for benign queries and original malicious queries, the highlighted tokens are mostly question words or punctuation. The authors argue this can be used to explain the reasons for refusal.

    Other Ablations and Analyses

    • α, β trade-off (Table A6, Vicuna): With α fixed, larger β gives both higher ASR and higher Win Rate; with β fixed, larger α gives both lower, e.g., at α=0.75, β=0.3, ASR 0.097, Win Rate 0.464.
    • Different affirmative sentences (Table A2): With 3 different affirmative sentences, ASR on Vicuna is 0.142–0.145 and Win Rate 0.694–0.715, and on LLaMA-2 ASR is 0.018–0.022; the authors state the performance is stable.
    • Negative/exceptional: On Vicuna, Token Highlighter's Win Rate (0.698) is lower than no defense (0.772) and Gradient Cuff (0.738); the combined version at β=0.2 drops Win Rate to 0.328.
  5. What are some points that can be further explored?

    The paper does not specifically discuss limitations; the experiments cover only 2 7B models, 6 attacks, and a single utility benchmark.

    Limitations and Future Directions Pointed Out by the Authors

    • The paper does not specifically discuss limitations (there is no Limitations or Future Work section; the Conclusion only summarizes contributions).

    Scope of Experimental Coverage

    • Models tested: Only two aligned models at the 7B scale, LLaMA-2-7B-Chat and Vicuna-7B-V1.5 (Section 4.1).
    • Attack coverage: 6 jailbreak attacks (GCG, AutoDAN, PAIR, TAP, Manyshot, AIM), with 100 instructions sampled from AdvBench as malicious queries; adaptive attacks cover only two variants based on GCG and TAP (Section 4.5).
    • Utility evaluation: Only AlpacaEval (805 instructions, GPT-4 judge, text-davinci-003 reference); ASR is judged by LLaMA-Guard-2-8B, and the paper does not report manual review or judge consistency.
    • Runtime measurement: Only 25 AlpacaEval queries and one model, Vicuna-7B-V1.5 (Section 4.4).
    • Hyperparameters: α is fixed at 0.25, and β takes one default value per model; the paper does not report experiments on larger-scale models, multi-turn dialogue, or other languages.
  6. Summarize the main content of the paper

    Token Highlighter defends against jailbreaks by locating and weakening the key tokens that induce the model to give an affirmative response, at low cost and interpretably.

    A jailbreak defense paper whose goal is to protect aligned LLMs at low inference cost without harming benign utility.

    • Problem: Aligned LLMs can still be bypassed by token-level and prompt-level jailbreaks; the authors point out that existing defenses are either ineffective against fluent jailbreaks (PPL), have high false positive rates (detection-based), or require multiple queries (smoothing-based).
    • Method: Define Affirmation Loss to measure the model's willingness to generate an affirmative response, use its gradient norm to select the top-nα critical tokens, then weaken their influence via Soft Removal (multiplying embeddings by β); this requires only one additional forward plus backward pass.
    • Main results: On Vicuna-7B-V1.5, average ASR drops from 0.730 to 0.142, with Win Rate maintained at 0.698; on LLaMA-2-7B-Chat, ASR drops from 0.115 to 0.018 (Table A5).
    • Robustness: When the defense is fully transparent, Adaptive-GCG brings only a 0.1 ASR increase on Vicuna, and Adaptive-TAP 0.04 (Section 4.5).
    • Interpretability: The highlighted tokens of GCG prompts all fall within the adversarial suffix, and the highlighted tokens of TAP prompts correspond to rewriting strategies such as role-playing; the authors argue this can be used to explain refusals.
    • Authors' conclusion: Token Highlighter balances defense effectiveness, benign utility, and runtime efficiency across 2 aligned models and 6 attacks, and the highlighting results can serve as explanations for users and developers.

Related papers

Show 3 more papers
Read originalarxiv.org