mlsanityData to 14 Oct 2026

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

arXiv 2608.27580 ↗First posted 27 Aug 2026cs.AIcited by 0

On the map: LLM safety and security → Safety alignment, refusal and guardrails

Abstract (arXiv)

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.

Key facts. No citing papers in the map yet (data through 14 Oct 2026). Placed in Safety alignment, refusal and guardrails, one of 12 directions in LLM safety and security. Builds on 15 of its 26 references that are in the map. First posted on arXiv 27 Aug 2026.

Builds on

15 of 26 references.

Closest ancestors · 6

Same direction, newest first

  1. 2025Safety Through Reasoning: An Empirical Study of Reasoning Guardrail Models26 May
  2. 2025Aegis2.0: A Diverse AI Safety Dataset and Risks Taxonomy for Alignment of LLM Guardrails15 Jan
  3. 2024LongSafety: Enhance Safety for Long-Context LLMs11 Nov
  4. 2024On the Role of Attention Heads in Large Language Model Safety17 Oct
  5. 2024WildGuard: Open One-Stop Moderation Tools for Safety Risks, Jailbreaks, and Refusals of LLMs26 Jun
  6. 2024PKU-SafeRLHF: Towards Multi-Level Safety Alignment for LLMs with Human Preference20 Jun

Other references · 9

  1. 2023BeaverTails: Towards Improved Safety Alignment of LLM via a Human-Preference Datasetcited by 860
  2. 2024WildChat: 1M ChatGPT Interaction Logs in the Wildcited by 629
  3. 2022A Holistic Approach to Undesired Content Detection in the Real Worldcited by 356
  4. 2024ShieldGemma: Generative AI Content Moderation Based on Gemmacited by 243
  5. 2023ToxicChat: Unveiling Hidden Challenges of Toxicity Detection in Real-World User-AI Conversationcited by 231
  6. 2024AEGIS: Online Adaptive AI Content Safety Moderation with Ensemble of LLM Expertscited by 136
  7. 2025PolyGuard: A Multilingual Safety Moderation Tool for 17 Languagescited by 59
  8. 2026Gradient-Stable Attention Heads Signal LLM Correctnesscited by 5
  9. 2025Libra: Large Chinese-based Safeguard for AI Contentcited by 2

Built on by

Not cited yet.

Similar, not cited

Close in wording, no citation either way

  1. 2026Triaging Threats to Specialized Guardrails
  2. 2025SafeRoute: Adaptive Model Selection for Efficient and Accurate Safety Guardrails in Large Language Models
  3. 2025Protect: Towards Robust Guardrailing Stack for Trustworthy Enterprise LLM Systems
  4. 2026Beyond Unsafe Detection: Counterfactually Anchored Evidence Attribution for Multi-Turn LLM Safety Failures
  5. 2026ADVERSA: Measuring Multi-Turn Guardrail Degradation and Judge Reliability in Large Language Models
  6. 2026Safety Beyond the Interface: Detecting Harm via Latent States in Large Language Models
  7. 2026Robust and Efficient Guardrails with Latent Reasoning
  8. 2025ThinkGuard: Deliberative Slow Thinking Leads to Cautious Guardrails