Skip to content

LongGuard: Mechanistic Analysis and Training-Free Mitigation of Long-Context Failure in Safety Guardrails

Aug 2026 · 0 citations · 26 references
Computer Science

TL;DR

LongGuard is presented, a framework that evaluates, mechanistically analyzes, and mitigates long-context guardrail failure, and proposes two training-free mitigations - Chunked Detection and Attention-Head Sharpening (AHS) - and a deployment protocol that selects configurations by context length and audit side.

Abstract

Safety guardrails serve as the last line of defense against harmful inputs and outputs of large language models (LLMs), yet they are trained and evaluated almost exclusively on short text. We present LongGuard, a framework that evaluates, mechanistically analyzes, and mitigates long-context guardrail failure. We formulate the task as Safety Needle-in-a-Haystack (SafetyNIAH) over a 0.25k-32k length grid; across 15 mainstream guardrails, unsafe recall drops monotonically by more than 50% on average, and a paired Benign-Fill vs. Needle-Repeat design attributes the failure to proportional dilution of the unsafe needle rather than to absolute length. A three-layer attention-logit-behavior analysis on six guardrails locates the mechanism: attention mass on the unsafe needle is diluted, the unsafe-over-safe logit margin is compressed in lockstep, and the detection decision collapses accordingly, with this attention->logit->behavior chain remaining consistent after partialling out length. We further isolate a sparse set of guard-specialized retrieval heads that exhibit partial specificity relative to their base models. Building on the analysis, we propose two training-free mitigations - Chunked Detection (CD) and Attention-Head Sharpening (AHS) - and a deployment protocol, Context-Aware Hyperparameter Routing (CAHR), that selects configurations by context length and audit side. Across five benchmarks spanning synthetic data, long-context attacks, and reasoning-model outputs, CAHR-CD and CAHR-AHS improve the six-guardrail average by 22% and 13%, respectively. Code and data are available online.

View source

Similar papers

Preprint Aug 2026

When Refusal Looks Safe: The Refusal-Cue Shortcut in Safety Guard Models

To mitigate the refusal-cue shortcut, sparse complementary masking is adapted as a lightweight post-hoc intervention that identifies and suppresses a small set of shortcut-associated attention heads and MLP neurons without retraining and achieves an approximately 79% relative reduction in response-initial detection fai...

Yu Feng, Chun-Ting Zang, Chen Shen et al. · 1 citation
#artificial intelligence Preprint Sep 2026

SRD-GUARD: A Defense Framework of LLMs via Semantic Rewriting and Joint Multi-Model Scoring for Latent Intent Exposure

Large language models (LLMs) are increasingly deployed in safety-critical applications, yet jailbreak attacks can conceal harmful intent through role-playing, fictional scenarios, or seemingly benign motivations. Existing inference-time defenses may miss disguised attacks or excessively refuse legitimate requests. We p...

Qi Wang, Cheng-Cheng Wan, Jiang-Tao Wang · 0 citations
Preprint Aug 2026

Safety in Batches? Understanding and Mitigating Safety Failures in Batch Prompting

This work identifies batch prompting as a distinct safety failure mode, not reducible to known vulnerabilities such as in-context learning or long-context effects, and analyzes its causes from two complementary perspectives: alignment signal weakening and refusal signal dilution.

Kihyun Kim, Heeseon Kim, Wonjun Lee et al. · 0 citations
Preprint Aug 2026

Fool's Gold: Defensive Deception Against Safety-Removal Attacks on Open-Weight Models

The defense, decoy hardening ("Fool's Gold"), concedes the refusal strip and poisons its payoff: once refusal is stripped, most answers to hazardous operational requests are confident, fluent decoys whose critical elements are falsified.

M. Russinovich · 0 citations
#artificial intelligence Preprint Sep 2026

SEAL: Reinforcing Global Safety in Mixture-of-Experts through Shared Expert ALignment

Mixture-of-Experts (MoE) is a scaling architecture for large language models that activates only a small subset of expert modules per token, enabling massive parameter growth with nearly constant computation. Recent Hybrid MoE architecture adds \textit{shared experts} to capture consistently useful representations, fur...

Qingyu Meng, Yiwei Zha, Jia-Huan Pei et al. · 0 citations

Related blog posts

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.