Alignment-Enhanced Decoding: Defending Jailbreaks via Token-Level Adaptive Refining of Probability Distributions

Quan Liu, Zhenhong Zhou, Longzhu He, Yi Liu, Wei Zhang, Sen Su

Abstract

Large Language Models (LLMs) are increasingly integrated into critical applications, yet they remain vulnerable to "jailbreak" attacks—adversarial prompts designed to bypass safety alignments. We introduce Alignment-Enhanced Decoding (AED), a novel inference-time defense mechanism that detects and mitigates these attacks by monitoring the internal "indecision" of a model. By calculating a Competitive Index based on token-level probability distributions, AED identifies when a model is experiencing a conflict between its helpfulness and harmlessness objectives. Our results demonstrate that AED significantly improves safety across multiple architectures (Llama2, Vicuna, Gemma) with negligible impact on generation speed or performance on benign tasks.

Introduction

Despite rigorous safety alignment techniques such as Reinforcement Learning from Human Feedback (RLHF), Large Language Models (LLMs) are still susceptible to sophisticated jailbreak prompts. These attacks often exploit the inherent tension within a model's objective function: the drive to be helpful (answering the user's query) versus the requirement to be harmless (adhering to safety guidelines).

Existing defenses typically rely on input filtering or output monitoring. However, these methods can often be bypassed by clever prompt engineering or introduce significant latency. We propose that the most reliable signal of a jailbreak attempt lies within the model's own decoding process. When faced with a conflicting prompt, the model's internal probability distribution for the next token becomes unusually competitive. AED leverages this signal to adaptively refine the decoding process in real-time.

Methodology: Alignment-Enhanced Decoding (AED)

AED operates during the inference stage, requiring no additional training or fine-tuning of the base model. The process is divided into three primary phases:

  1. Quantifying Conflict via the Competitive Index: The core innovation of AED is the Competitive Index ($I$). During standard top-$p$ sampling, the model identifies a set of candidate tokens. In normal, harmless interactions, the model is typically "certain," resulting in a small number of high-probability candidates. During a jailbreak, the model's distribution flattens as it struggles between semantically opposing responses (e.g., starting with "Sure" to be helpful vs. "Sorry" to be safe). We define $I$ as the ratio of the current candidate count ($S$) to a baseline count ($S_t$) derived from harmless queries.
  2. Self-Evaluation Logits: When a potential conflict is detected (i.e., the Competitive Index exceeds a calibrated threshold), the model performs a lightweight "self-reflection" step. It generates a secondary set of probability distributions (logits) specifically focused on safety and alignment.
  3. Adaptive Refining: AED dynamically mixes the original "helpful" distribution with these "safe" logits. If the Competitive Index is low, the model proceeds with standard decoding. If the index is high, the safety-aligned distribution is given more weight, steering the model toward a refusal.
Figure 2: Overview of the AED mechanism compared to standard decoding. AED monitors the candidate count to trigger a self-evaluation and regulate the final output distribution.

Empirical Evidence and Results

We evaluated AED across five popular open-source models, including Llama2-7B, Vicuna-7B, and Gemma-7B. The defense was tested against a variety of jailbreak attacks, such as GCG (Greedy Coordinate Gradient) and AutoDAN, alongside standard benchmarks like MMLU and Alpaca to ensure general utility was preserved.

The "Identity Crisis" Signal

Our analysis confirms that the Competitive Index serves as a robust discriminator between benign and adversarial inputs. As shown in the distribution plots, harmless tasks (MMLU, GSM8K) consistently produce low index values, while jailbreak attacks cause a distinct and measurable "spike" in the index.

Figure 4: Probability density of the Competitive Index for Vicuna-7B. Harmless datasets (green) cluster below the threshold, while jailbreak attacks (orange) show a clear separation, peaking around an index of 2.0.

Performance Metrics

  • Security Gains: On Llama2-7B, AED increased the rejection rate of GCG attacks from 75.5% (undefended) to 92.5%.
  • Preserving Helpfulness: The defense demonstrated high precision, with the "Not Rejection Rate" (NRR) on harmless datasets remaining virtually unchanged. For instance, on MMLU, the NRR only shifted from 2.5% to 3.0%, indicating that the defense rarely triggers false positives.
  • Efficiency: Because AED only intervenes when a conflict is detected and primarily focuses on the initial tokens of a response, the computational overhead is minimal. The Average Token Generation Time ratio (ATGR) was approximately 1.04x, representing only a 4% increase in latency.

Discussion and Limitations

AED's surgical precision allows it to defend against jailbreaks without the heavy-handedness of traditional filters. One interesting finding is that the presence of a standard system prompt (e.g., "You are a helpful and harmless assistant") acts as a stabilizer, naturally lowering the baseline Competitive Index and making the model more resilient to competition.

However, the defense does require a small amount of per-model calibration to set the candidate count threshold ($S_t$). Additionally, in some extreme jailbreak scenarios, we observed index values reaching 100 times the threshold; further research is needed to understand the mechanics of these high-intensity conflicts.

Conclusion

Alignment-Enhanced Decoding provides a highly effective, low-overhead defense against LLM jailbreaks by monitoring the model's internal state. By identifying the "identity crisis" that occurs during adversarial attacks, AED can adaptively steer models back toward their safety training, ensuring they remain both helpful and harmless in real-world deployments.

Summary updated

BibTeX
@inproceedings{liu2024alignment,
  author = {Quan Liu and Zhenhong Zhou and Longzhu He and Yi Liu and Wei Zhang and Sen Su},
  title = {{Alignment-Enhanced Decoding: Defending Jailbreaks via Token-Level Adaptive Refining of Probability Distributions}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.emnlp-main.164},
}
Figure