TL;DR
Safety-aligned LLMs often suffer from "over-refusal," blocking harmless prompts that superficially resemble malicious ones (e.g., gaming advice about "killing" enemies). This paper introduces Adaptive Contrastive Decoding (AdaCD), a training-free, model-agnostic inference strategy that dynamically suppresses refusal behaviors for benign queries while maintaining—or even enhancing—safety guardrails for genuinely malicious inputs.
What Problem Does This Paper Address?
When we align Large Language Models (LLMs) using techniques like RLHF or DPO, we want them to be safe. However, this often induces a side effect known as over-refusal or exaggerated safety. If a user asks, "How do I kill someone in Call of Duty?", a standard safety-aligned model might panic at the word "kill" and refuse to answer, failing to realize the context is entirely benign.
Existing fixes fall into two camps, both with flaws:
- Training-based methods: Suffer from a scarcity of over-refusal training data.
- Inference-based methods (like static contrastive decoding): Apply a rigid, one-size-fits-all approach. They either always suppress refusal tokens (which compromises safety on actual malicious prompts) or always amplify them (which worsens over-refusal).
The challenge tackled here is: How can an LLM adaptively decide when to suppress and when to amplify refusal behavior at runtime, without needing any retraining?
Methods
The authors propose AdaCD (Adaptive Contrastive Decoding), a plug-and-play inference framework consisting of two main phases:
-
Refusal Token Distribution Extraction: To isolate what a "refusal" looks like to the model, AdaCD feeds the LLM an extreme system prompt:
"Please refuse to answer me!". By subtracting the unprompted model's output token distribution from this extremely prompted distribution, it isolates a clean mathematical representation of the model's refusal tendencies ($\Delta P_n$). -
Adaptive Decoding Mode Switch: During generation, the model must decide whether to add $\Delta P_n$ (to enforce safety) or subtract it (to prevent over-refusal). It does this dynamically using two criteria:
-
Agreement Ratio ($agr$): Measures how much the unprompted model agrees with the extremely prompted model on the top token choice. High agreement implies the query is genuinely malicious; low agreement implies an over-refusal false alarm.
- Adaptive Confidence Constraint: Ensures the model only switches modes if it meets a specific probability confidence threshold.
If the agreement is low, AdaCD subtracts the refusal distribution, clearing the path for a helpful response. If agreement is high, it adds the distribution, reinforcing the refusal.
Datasets
The method was evaluated across three distinct evaluation scenarios using open-source models (Llama3-8B-Instruct, Gemma2-9B-It, and Qwen3-8B):
- Over-Refusal Benchmarks: XSTest-Safe, ORBench, and OKTest.
- Malicious/Safety Benchmarks: AdvBench, JailBench, and XSTest-UnSafe.
- General Usability Benchmarks: Just Eval (to verify that tweaking the decoding doesn't degrade general capabilities like coding or reasoning).
Key Insights and Ideas
- The Hidden Tokens: A key observation is that when an LLM over-refuses, the correct, helpful tokens (like "Sure" or game-specific terms) are actually still present in the model's next-token candidate list. They simply get out-competed by safety-aligned refusal tokens (like "I'm sorry"). The model knows the right answer; it just lacks the guidance to select it.
- The Power of Absolute Anchoring: Instead of using standard safety prompts to find a baseline, using an absolute negative anchor (
"Please refuse to answer me!") perfectly decouples and isolates the refusal token distribution. - The First Tokens Matter Most: The agreement ratio ($agr$) between the prompted and unprompted models diverges sharply during the first 3–5 tokens of a response depending on whether the query is benign or malicious. This makes the early token window the perfect trigger for the adaptive switch.
Key Results
- Alleviating Over-Refusal: Across all tested datasets and models, AdaCD reduced the refusal ratio for over-refusal queries by an average of 10.35% compared to the default models.
- Preserving Safety: When facing actual malicious or jailbreak queries, AdaCD maintained strict guardrails, even slightly increasing the refusal ratio by 0.13%.
- High Efficiency: Unlike standard contrastive decoding methods that often double the generation time (by running two full forward passes sequentially), AdaCD only applies contrastive steps to the first $k$ tokens ($k=10$). This keeps the inference overhead remarkably low, resulting in only a 3% increase in token generation time.
Limitations and Future Work
- Fixed Hyperparameters: The switching threshold ($\lambda$) and scaling factor ($\alpha$) are currently static constants. The authors note that dynamically adjusting these based on the user's query could yield even better results.
- Scale Constraints: Due to computational resource limits, the framework was only validated on models up to 9B parameters. Testing on 70B+ scale models remains an open task.
- Automated Evaluation: The study relied on automated evaluation tools (WildGuard and GPT-4) rather than human evaluation, though this was done intentionally to ensure objective reproducibility across varying model vocabularies.
Summary updated