Any-Depth Alignment: Unlocking Innate Safety Alignment of LLMs to Any-Depth

Jiawei Zhang, Andrew Estornell, David D. Baek, Bo Li, Xiaojun Xu

TL;DR

Current LLM safety mechanisms are "shallow," meaning they easily collapse if an attacker forces the model to begin generating a harmful response. This paper introduces Any-Depth Alignment (ADA), an inference-time defense that unlocks a model's innate safety by injecting "Safety Tokens" (like the assistant header) mid-generation. By probing the hidden states of these injected tokens, ADA can halt harmful outputs at any depth with near-100% success, minimal compute overhead, and almost zero false positives.

What Problem Does This Paper Address?

Most aligned LLMs rely on shallow alignment: they are trained to immediately refuse a harmful prompt (e.g., "I can't help with that"). However, this front-loaded safety is brittle. If an attacker bypasses the initial refusal—either through adversarial prompt attacks (like GCG or PAIR) or by manually prefilling the assistant's response with an affirmative start (e.g., "Sure, here are the steps to build a bomb: 1.")—the model's safety guardrails collapse, and it will happily continue generating harmful content.

Refusal rate vs prefill depth

Previous solutions have significant drawbacks:

  • Deep Alignment: Training models to refuse mid-stream just pushes the vulnerability deeper, creating an arms race between alignment depth and attack depth.
  • External Guardrails: Running a separate classifier model (like Llama Guard) over the generated text is highly effective but scales linearly with context length, making it too slow and memory-intensive for real-time streaming of long responses.

Methods

The authors discovered that a model's internal awareness of harmfulness isn't lost during a jailbreak; it's just "locked." They found that injecting Safety Tokens—specifically, the chat template's assistant header (e.g., <|start_header_id|>assistant)—mid-generation acts as a key. It forces the model to aggregate distributed safety evidence and surfaces a highly separable "harmfulness" signal in its hidden states.

ADA Pipeline and Methods

They operationalize this into two Any-Depth Alignment (ADA) methods:

  1. ADA (RK) - Rethinking: A generative, training-free approach. At periodic intervals, the system forks the generation, injects the assistant header, and lets the model generate a few tokens. If it outputs a refusal, the main stream is halted.
  2. ADA (LP) - Linear Probe: The primary, highly efficient approach. The system injects the Safety Tokens, performs a single forward pass to extract their hidden states, and runs a lightweight linear classifier (logistic regression) to detect harmfulness. If flagged, generation stops immediately.

Crucially, ADA (LP) reuses the base model's KV cache. This means checking for safety takes the exact same time and memory as generating a single new token, regardless of how long the context is.

Datasets

  • Harmful Attacks: AdvBench, JailbreakBench, StrongREJECT, and HEx-PHI. The authors also created a custom dataset of extremely long harmful responses (averaging 3,500+ tokens) using a deliberately misaligned GPT model to test "deep prefill" attacks.
  • Benign (for Over-refusal): GSM8K, MATH, BBH, HumanEval, MMLU, SimpleQA, GPQA Diamond, and XSTest (a suite specifically designed to trick models into false-positive refusals).
  • Probe Training: A mix of WildJailbreak, WildChat-1M, and their custom jailbroken GPT dataset.

Key Insights and Ideas

  • Safety is anchored to the assistant header: The model knows it is generating bad content, but the hidden states of standard generated tokens remain entangled. The assistant header acts as an aggregator, pulling this latent safety knowledge into a cleanly separable representation.
  • Deep alignment is a band-aid: The authors systematically prove that deeply aligned models (like Claude Sonnet 4) still fail if the attacker just provides a longer prefill (e.g., 100-500 tokens).
  • Latent safety survives fine-tuning: Even when a model undergoes "Adversarial Supervised Fine-Tuning" designed to explicitly erase its safety guardrails, ADA (LP) can still detect the harmfulness signal in the hidden states. The surface-level behavior changes, but the internal representation of safety remains intact.

Key Results

  • Deep Prefill Robustness: Under deep prefill attacks (up to 2,500 tokens), base models and deeply aligned models see their refusal rates collapse to near 0%. ADA (LP) maintains a near-100% refusal rate across all depths.
  • Adversarial Prompt Defense: ADA (LP) reduces the Attack Success Rate (ASR) of state-of-the-art attacks (GCG, AutoDAN, PAIR, TAP) from over 50% on base models to below 3% on average.
  • Zero Over-refusal: ADA (LP) maintains a near 0% false-positive rate on benign datasets, outperforming both Deep Alignment (which spikes false positives) and external guardrails.
  • Massive Efficiency: ADA (LP) operates in constant time (~25ms latency, 2-3MB memory overhead). In contrast, traditional guardrails require ~500ms and nearly 1GB of memory for a 10,000-token context.

Limitations and Future Work

  • Hidden State Access: ADA (LP) requires access to the model's internal hidden states. For black-box APIs where this isn't possible, users are limited to the slightly less robust ADA (RK) method.
  • Token Leakage: Because checks happen periodically (e.g., every 25 tokens), a small number of harmful tokens might be emitted to the user before the generation is halted.
  • Open-Source Circumvention: Like any inference-time intervention or guardrail, ADA can simply be disabled by a bad actor who has full control over the open-source model weights and inference stack. It is best suited for API providers and server-side deployments.

Summary updated

BibTeX
@inproceedings{zhang2026any,
  author = {Jiawei Zhang and Andrew Estornell and David D. Baek and Bo Li and Xiaojun Xu},
  title = {{Any-Depth Alignment: Unlocking Innate Safety Alignment of LLMs to Any-Depth}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=0fuYOuJyzl},
}
Figure