Token Highlighter: Inspecting and Mitigating Jailbreak Prompts for Large Language Models

Xiaomeng Hu, Pin-Yu Chen, Tsung-Yi Ho

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.

Figure 1: Examples of successful jailbreak attacks using adversarial suffixes and role-playing scenarios, which trick the model into providing harmful instructions.

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.

Figure 2: The Token Highlighter framework identifies jailbreak-critical tokens using Affirmation Loss gradients and neutralizes them via Soft Removal, effectively preventing harmful outputs while maintaining response quality.

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

BibTeX
@inproceedings{hu2025token,
  author = {Xiaomeng Hu and Pin-Yu Chen and Tsung-Yi Ho},
  title = {{Token Highlighter: Inspecting and Mitigating Jailbreak Prompts for Large Language Models}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2025},
  doi = {10.1609/aaai.v39i26.34943},
}
Figure