Abstract
Large Language Models (LLMs) are susceptible to jailbreak attacks that bypass safety alignments through adversarial prompts. We present Token Highlighter, a lightweight and interpretable defense mechanism. By identifying "jailbreak-critical" tokens through the gradient of an "Affirmation Loss" and applying "Soft Removal" to dampen their influence, our method significantly reduces attack success rates while maintaining model utility and low latency.
Introduction
Despite rigorous safety training, state-of-the-art LLMs remain vulnerable to adversarial prompts designed to elicit harmful content. These "jailbreaks" range from token-level suffixes to complex role-playing scenarios. Existing defenses often suffer from high computational overhead, excessive false positives, or vulnerability to fluent adversarial text. There is a critical need for a defense that is fast, precise, and robust enough for real-time production environments.
Methodology: The Token Highlighter Framework
Token Highlighter operates in two primary stages: identification and neutralization.
1. Identifying Critical Tokens via Affirmation Loss
The core insight of this work is that successful jailbreaks typically force the model into an "affirmative state," characterized by responses beginning with phrases like "Sure, I can help with that." We define Affirmation Loss as the negative log-likelihood of the model generating a predefined affirmative string given the input prompt. By calculating the gradient of this loss with respect to the input token embeddings, we can pinpoint tokens that disproportionately drive the model toward compliance with harmful requests. This gradient-based approach allows for a "white-box" inspection of the prompt, targeting tokens that the model itself perceives as instructions to be helpful in a harmful context.
2. Neutralizing Threats with Soft Removal
Traditional defenses often employ "Hard Removal" (deletion), which can disrupt the semantic coherence of benign queries. Instead, Token Highlighter uses Soft Removal. We scale the embeddings of identified critical tokens by a factor $\beta \in [0, 1]$. This "shrinks" the adversarial signal's influence on the model's internal representations while preserving enough context for the model to process the query and issue a standard refusal. This method provides a superior trade-off between safety and linguistic integrity.
Experimental Results
We evaluated Token Highlighter against six major jailbreak methods (including GCG, TAP, and PAIR) using the AdvBench dataset on LLaMA-2-7B-Chat and Vicuna-7B-V1.5.
Defense Effectiveness and Efficiency
On the Vicuna-7B model, Token Highlighter reduced the Attack Success Rate (ASR) from 0.730 to 0.142, significantly outperforming baseline defenses like Gradient Cuff. Crucially, the defense is highly efficient, requiring only a single additional forward and backward pass. The average processing time per query was approximately 0.549 seconds, compared to over 4 seconds for smoothing-based methods. Even against "Adaptive Attacks" designed to circumvent the defense, the increase in ASR was negligible (~0.1).
Utility Preservation
To ensure the defense does not impede normal functionality, we tested it on AlpacaEval. Token Highlighter maintained a high win rate, indicating that it rarely triggers false positives on benign, safe queries. This balance between safety and utility is a key advantage over more aggressive filtering techniques that often degrade the user experience by over-refusing safe requests.
Conclusion
Token Highlighter provides a robust, interpretable, and efficient defense against LLM jailbreaking. By leveraging the model's own internal signals to identify malicious triggers, it offers a surgical approach to prompt mitigation. While currently requiring white-box access to gradients, it represents a significant step toward secure and reliable LLM deployment. Future work will focus on expanding the set of affirmation targets and exploring dynamic parameter tuning to further enhance resilience against evolving adversarial strategies.
Summary updated