Manuscript Offprint
arXiv:2608.27580LongGuard: Mechanistic Analysis and Training-Free Mitigation of Long-Context Failure in Safety Guardrails
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.
1 Introduction
Safety guardrails serve as real-time moderators of LLM inputs and outputs and have become indis-

Figure 1: Long-context attacks (on the input side) and long reasoning outputs (on the output side) pose new challenges for safety guardrails trained on short text.
pensable for LLM safety, with multiple generations (Inan et al., 2023; Han et al., 2024; Zeng et al., 2024; Kumar et al., 2025; Zhao et al., 2025; Lin et al., 2026) widely deployed in short-text scenarios. The sequences they moderate, however, are growing longer (Figure 1): Many-shot Jailbreaking (Anil et al., 2024) and NINJA Attack (Shah et al., 2025) distribute harmful instructions across long prompts to bypass safety alignment, and reasoning models such as DeepSeek-R1 (Guo et al., 2025) and Qwen3 (Yang et al., 2025) produce thousands of intermediate tokens that may carry latent risks. Together, they shift the deployment distribution of guardrails from short text to long context. While long-context safety of LLMs themselves has begun to receive attention (Lu et al., 2025; Huang et al., 2025), whether guardrails still play the role of the last line of defense under long context remains open.
We organize the paper around three research questions. (RQ1) Does guardrail detection degrade systematically with context length? (RQ2) If so, what is the internal mechanism? (RQ3) Can the mechanism guide training-free mitigations? We answer them in LongGuard, a unified evaluation, analysis, and mitigation framework with three contributions (Figure 2).
Corresponding author.
https://github.com/caskcsg/LongGuard

Figure 2: Overview of LongGuard: evaluation, mechanistic analysis, and training-free mitigation.
Evaluation. We formulate the task as Safety Needle-in-a-Haystack (SafetyNIAH) and synthesize a benchmark over a 0.25k–32k length grid with controlled needle type, position, and haystack type; a paired Benign-Fill / Needle-Repeat design separates proportional dilution from absolute length. Across 15 guardrails, unsafe recall declines monotonically, while safe recall remains flat—an asymmetric degradation driven mainly by dilution.
Analysis. On six guardrails, a three-layer attention–logit–behavior framework localizes the failure to dilution of unsafe evidence by the haystack. It isolates a sparse set of guard-specialized retrieval heads that exhibit partial specificity relative to their base models.
Mitigation. Two training-free methods follow: Chunked Detection (CD) chunks the input to raise local evidence density, and Attention-Head Sharpening (AHS) sharpens the softmax temperature on the retrieval heads; Context-Aware Hyperparameter Routing (CAHR) selects hyperparameters by context length and audit side. Across five benchmarks, they restore long-context detection and form a performance-cost trade-off.
Safety guardrails and benchmarks. Open-source guardrails have evolved along data, taxonomy, and modality axes – spanning fine-tuned harmful-content classifiers, reasoning-chain guards, multilingual variants, and configurable strict/loose modes – and the safety benchmarks evaluating them now cover jailbreak, harmful instructions, toxicity, refusal, and output risks (full lists in Appendices B and A). Both substantially improve detection in standard settings, yet they remain almost exclusively limited to short text; LongGuard targets this shared blind spot, and SafetyNIAH reuses their safety semantics while injecting controlled length, position, and haystack dimensions.
Attention and safety mechanisms. Recent mechanistic studies identify sparse attention heads tied to safety behavior and probe them via entropy or realignment (Zhou et al., 2025; Ostmeier et al., 2026), but mainly on short inputs of general LLMs. We extend this perspective to long-input guardrail detection and use base–guard comparison to localize the shaping effect of guard fine-tuning.
3 SafetyNIAH: Task and Benchmark
This section defines the task and the construction of long-context guardrail samples used in RQ1.
3.1 Task Formulation
We formulate long-context harmful content detection as the Safety Needle-in-a-Haystack (SafetyNIAH) task: a short, labeled sample (needle) is embedded in a neutral long context (haystack); the guardrail must keep the original decision from being diluted. Let the guardrail be
where is the text space to moderate: at the input side, is a prompt, and at the output side, is the concatenation of the user query and the model response. Given a needle pool with labels and audit sides , SafetyNIAH controls three variables: context length , needle position , and haystack type , and synthesizes
checking whether still agrees with .
The construction decomposes long-context degradation into two external factors: proportional dilution (the share of needle tokens decreases) and absolute-length effect (instability induced by length itself). To separate them, we build two paired sets. The Benign-Fill main benchmark surrounds a needle with a neutral haystack so that dilution and length grow together. The Needle-Repeat negative control replicates an unsafe needle to the target length, removing dilution and isolating the length.
3.2 Needle Pool
We collect samples from 17 guardrail benchmarks (Appendix A). We then stratify by target length words, label, and audit side, sampling up to 50 instances per cell. The resulting needle pool contains around 15.2k samples.
3.3 Neutral Haystack Pool
To prevent the haystack from carrying safety risks that contaminate the needle label, we build a neutral haystack pool as follows. We uniformly sample 500k articles from English Wikipedia, concatenate consecutive sentences into chunks of at most 2,048 characters, and apply strict filtering with a set of guardrails (Appendix B): every chunk is scored independently under both prompt and response settings, and a chunk is dropped if any guardrail under any setting marks it unsafe. The cleaned pool is denoted .
3.4 Long-Context Sample Synthesis
Benign-Fill main benchmark. Given a needle , context length , needle position , and haystack type , we form
where the word budgets are and . Both and are produced by concatenating chunks from . Random and Related share the same and form strict pairs: Random samples chunks uniformly without replacement from with a needle-specific seed; Related encodes needle and candidate chunks with jina-embeddings-v3 (Sturua et al., 2024) and retrieves the most similar chunks as the haystack. The final Benign-Fill set has 30,400 samples; the full distribution is summarized in Appendix A.
Needle-Repeat negative control. Benign-Fill couples dilution with length. To isolate length, we replicate each unsafe needle to the target length, so that the full context consists of copies of the needle. The self-fill zeroes out dilution while keeping length, and the needle position/haystack-type axes are no longer applicable. Needle-Repeat uses only unsafe needles, yielding 8,800 samples.
4 Long-Context Degradation and Causal Decomposition
This section answers RQ1. Section 4.1 reports an asymmetric degradation of unsafe recall across 15 guardrails. Section 4.2 decomposes the external cause into proportional dilution and an absolute-length residual through Benign-Fill / Needle-Repeat. Additional ablations are deferred to Appendix C.
https://huggingface.co/datasets/wikimedia/wikipedia/viewer/20231101.en
| Model | 0.25k | 1k | 4k | 16k | 32k | inv@32k | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| WildGuard-7B | 86.36 | 83.75 | 76.32 | 87.25 | 13.73 | 66.00 | 2.27 | 58.94 | 0.09 | 56.94 | -86.27 | -26.81 | 39.71% |
| GPT-OSS-SafeGuard-20B | 83.73 | 81.12 | 81.59 | 79.56 | 81.27 | 80.38 | 78.59 | 79.44 | 68.91 | 79.94 | -14.82 | -1.19 | 6.50% |
| NemotronGuardV2-8B | 64.41 | 92.12 | 47.27 | 87.88 | 17.09 | 81.19 | 21.68 | 86.12 | 25.09 | 85.00 | -39.32 | -7.13 | 7.45% |
| NemotronGuardV3-8B | 78.05 | 86.31 | 69.14 | 74.00 | 36.91 | 61.06 | 14.09 | 54.87 | 16.86 | 54.06 | -61.18 | -32.25 | 36.03% |
| NemotronReasoning-4B | 77.23 | 89.25 | 59.77 | 94.50 | 23.55 | 97.69 | 19.77 | 98.56 | 14.55 | 98.94 | -62.68 | +9.69 | 0.03% |
| LlamaGuard3-8B | 66.14 | 92.12 | 37.73 | 95.81 | 25.86 | 97.31 | 15.68 | 98.06 | 14.50 | 98.25 | -51.64 | +6.13 | 0.00% |
| LlamaGuard4-12B | 55.50 | 92.62 | 25.05 | 97.94 | 9.09 | 99.00 | 6.95 | 99.06 | 7.27 | 98.62 | -48.23 | +6.00 | 0.29% |
| ShieldGemma-9B | 41.45 | 95.75 | 21.55 | 98.44 | 6.73 | 99.19 | 0.00 | 100.00 | 0.00 | 100.00 | -41.45 | +4.25 | 0.00% |
| PolyGuard-7B | 91.86 | 67.19 | 89.23 | 69.75 | 86.95 | 71.12 | 74.41 | 73.38 | 50.32 | 77.81 | -41.55 | +10.62 | 0.00% |
| GuardReasoner-8B | 88.36 | 81.50 | 78.45 | 83.75 | 63.32 | 86.25 | 50.18 | 89.19 | 44.50 | 89.12 | -43.86 | +7.63 | 0.29% |
| Qwen3Guard-Gen-8B (strict) | 87.86 | 84.75 | 84.55 | 84.00 | 79.95 | 86.31 | 62.82 | 91.31 | 33.45 | 95.25 | -54.41 | +10.50 | 0.00% |
| Qwen3Guard-Gen-8B (loose) | 56.50 | 96.38 | 44.45 | 96.44 | 39.27 | 96.00 | 31.14 | 96.56 | 10.32 | 98.94 | -46.18 | +2.56 | 0.00% |
| Qwen3Guard-Stream-8B (strict) | 84.59 | 78.50 | 79.82 | 80.44 | 68.68 | 83.00 | 27.55 | 93.00 | 18.36 | 95.19 | -66.23 | +16.69 | 0.00% |
| Qwen3Guard-Stream-8B (loose) | 51.45 | 89.44 | 38.95 | 91.44 | 34.41 | 90.94 | 12.45 | 96.19 | 8.09 | 97.12 | -43.36 | +7.69 | 0.00% |
| YuFeng-XGuard-8B | 83.00 | 89.44 | 77.50 | 90.69 | 70.09 | 91.25 | 50.14 | 94.31 | 32.41 | 94.56 | -50.59 | +5.13 | 0.18% |
Table 1: Unsafe/Safe recall of 15 guardrails on Benign-Fill at five representative context lengths. The columns report 32k–0.25k; inv@32k is the fraction of unparseable outputs at 32k mapped to the opposite class. Three-class models with a controversial tier are split into -strict/-loose variants.

Figure 3: Two external causes of long-context degradation. (a) Benign-Fill vs. Needle-Repeat. (b) Relationship between needle share and in Benign-Fill.
4.1 Asymmetric Degradation of Unsafe Recall
Across the 15 rows of Table 1, decreases monotonically from 0.25k to 32k with a cross-model mean , while averages . Long context primarily weakens the detection of unsafe content rather than producing a uniform drop in both classes. The negative outliers come from parsing failures: four models have inv@32k outputs, which are counted as false alarms on safe ground truth. Long-context guardrail failures manifest in two patterns: unsafe samples being judged safe, and certain models failing to produce protocol-conforming outputs.
4.2 Proportional Dilution vs. Absolute Length
Table 1 confirms the degradation but does not separate proportional dilution from absolute-length effects. We use the Benign-Fill / Needle-Repeat pair as a decomposition.
Dilution is the dominant cause. As Figure 3(a) shows, Benign-Fill falls from 76.04% at 0.25k to 25.10% at 32k (), while Needle- Repeat falls from 85.41% to 67.50% ( ). The Needle-Repeat – Benign-Fill gap widens from +9.4% to +42.4%, indicating that natural long-context degradation is mainly driven by dilution; the residual drop of Needle-Repeat reflects length-related effects (e.g. context-window limits, positional extrapolation).
Needle share monotonically tracks . Define the needle share as , i.e. the fraction of words taken up by the unsafe needle in the final -word input. Figure 3(b) shows that lower predicts lower : as decreases from [50%, 100%] to [0, 0.5%), prompt-side drops from 73.7% to 31.7% and response-side from 83.5% to 33.6%. This further supports dilution as the primary cause.
Dilution causes a substantially larger loss than absolute length and is concentrated on unsafe samples. The remainder of the paper therefore focuses on dilution-induced failure and centers its analysis on the unsafe class.
5 Mechanism of Dilution-Driven Failure
This section answers RQ2. Section 4 attributes the degradation to dilution at the behavior level. We now analyze its internal mechanism on six representative full-attention guardrails. All metrics are computed on unsafe samples and weighted by sample counts when merging prompt and response audit sides.
5.1 From Attention to Logit to Behavior
The decision token. We use for the decision token of each sample, defined as the last non-padding query token in the input rendered by the

Figure 4: Attention mass of the decision token over the three spans across context lengths (log scale). For each model, left: Benign-Fill, right: Needle-Repeat; the annotation indicates the change from 0.25k to 32k.
native chat template of each guardrail; its position is the index at which the model produces the classification logits in the forward pass.
5.1.1 Attention: needle attention is diluted
We decompose the attention of over the input sequence into three spans: needle (annotated unsafe needle tokens), haystack (distractor content around the needle), and context = (needle haystack) (e.g., BOS, system prompt, chat template). For each layer and head, we take the attention weights from to all tokens, average across heads, sum within each span , and average across layers, obtaining sample-level , the total mass that allocates to span (with ).
In Figure 4 (left), the of all six models drops by from 0.25k to 32k under Benign-Fill, while rises monotonically and slightly decreases in most models. This is a consistent dilution signature: unsafe-needle attention is taken away by the growing haystack rather than by template anchors. The Needle-Repeat counterpart on the right gives the reverse evidence: once dilution is removed, at 32k is higher than at 0.25k, confirming that absolute length itself does not actively steal attention.
5.1.2 Logit: unsafe margin is compressed
We define the logit margin at as
taking the maximum logit over the unsafe/safe token sets specified by each guardrail's output protocol (e.g. safe/unsafe for LlamaGuard3-8B (Inan et al., 2023), no/yes for PolyGuard-

Figure 5: Per-model logit-margin distribution on unsafe samples: 0.25k (gray) vs. 32k (red on Benign-Fill, purple on Needle-Repeat); dashed lines mark medians.
7B (Kumar et al., 2025)). A positive margin means the argmax is unsafe.
In Figure 5 (left), all six Benign-Fill 32k distributions shift left relative to 0.25k, and several cross into the safe (<0) region; the sample-mean margin is uniformly compressed from 0.25k to 32k. The Needle-Repeat counterpart on the right shows no systematic left shift, with most models stable or slightly increasing across length, fully consistent with the attention-level and behavior-level Needle-Repeat results.
5.1.3 Mediation consistency
Beyond directional agreement, we verify that the three layers co-move beyond a common length covariate. On the 48 (model, length) units of Benign-Fill / unsafe, the Pearson partial correlations after controlling for are +0.65 (attention→logit), +0.83 (logit→behavior), and +0.56 (attention→behavior), all with (Appendix D). Together with the Needle-Repeat null (no dilution → no compression → no recall drop), this supports proportional dilution as the leading mechanism candidate.
5.2 Guard-Specialized Retrieval Heads
The previous section characterizes dilution at the average level. We now decompose it to (layer, head) granularity to see whether the evidence is read uniformly or by a few specialized heads.
Figures 6 and 7 show that unsafe-needle attention is sparsely concentrated on a few heads. These heads exhibit much higher density on the needle than on the haystack and persist across lengths. Quantitatively, the top-1 head carries 0.77%–2.84% of the needle attention; top-5% heads cumulatively account for 28.3%–52.4% across six models (top-10% reaches 43.6%–70.9%).
We formalize needle-selectivity + cross-length stability as the criterion that defines guard-

Figure 6: Per-head heatmaps at vs. 32k (shared vmax). Sparse middle-late heads darken at 32k; full sweep in Appendix E.

Figure 7: Cumulative needle-attention contribution of the top-k heads. The horizontal axis is the fraction of heads sorted by (descending, log scale); the vertical axis is the cumulative attention share. Top-5% heads per guardrail contribute at .
specialized retrieval heads . For each (sample, head), we compute the per-token attention density ratio between the needle and the haystack:
where indicates a needle-specific head and indicates a broadcast head. For each guardrail and each , we rank heads by in descending order , and define the cross-length stability score
We take the top-K% heads of each guardrail by S as . Throughout this section, we set . Figure 8 shows that concentrates in the 40%-70% middle-late depth and is sparse in width.
Partial specificity vs. base. A base-guard control on six pairs (Appendix F) shows that the top-5% heads of exhibit partial specificity: the

Figure 8: Distribution of on the (layer, head) plane. Background color: the cross-length stability score . Yellow circles: top-5% by S, falling in the 40%-70% middle-late depth.
cross-length rank correlation between guard and base remains (the head identity largely overlaps with what already exists in the base), yet at 32k the guard's top-5% share is +7.9% to +19.9% higher than the base's, and per-head selectivity is larger in median. Guard fine-tuning, therefore, does not create new retrieval pathways but amplifies the per-head magnitude and cross-length concentration of needle-specific heads on the existing retrieval topology of the base.
5.3 Sufficiency Interventions
Two positive interventions verify the chain’s operability. Token-level: restricting visible context to the unsafe needle (needle-only) lifts from the 47.8% full baseline to 70.2% (+22.5%), while keeping an equal amount of random haystack instead drops it to 24.0% (-23.8%) – recovery comes from preserving unsafe evidence, not from shortening the input. Head-level: post-hoc amplifying ’s attention to the needle on with multipliers monotonically raises by +1.5%, +3.8%, +6.4% on all six guardrails, while the same operation on an equal number of random heads stays within [-0.3%, -0.1%]. Token-level evidence preservation and head-level evidence amplification both contribute functionally to long-context safety judgment under dilution. The full intervention design, formulas, and dose-response curves are deferred to Appendix G.
6 Training-Free Mitigations
Targeting RQ3, this section turns the analysis into two training-free mitigations – Chunked Detection (CD), which chunks the input to raise the local needle share, and Attention-Head Sharpening (AHS), which applies a softmax temperature on – and a deployment protocol, Context-Aware Hyperparameter Routing (CAHR), that unifies their hyperparameter selection.
6.1 Chunked Detection (CD)
Section 4.2 localizes the dominant cause to dilution. The simplest counter-intervention is to chunk the long input so that the local needle share returns from the diluted regime to the dense regime. CD splits the input into non-overlapping segments of words, queries the guardrail on each segment independently, and aggregates by OR: any segment marked unsafe yields an unsafe verdict. The tunable hyperparameter is words.
6.2 Attention-Head Sharpening (AHS)
AHS reparameterizes the hard amplification of Section 5.3 – which requires needle annotations and is not deployable – as a softmax-temperature sharpening ( ) on that no longer needs labels. The feasibility is directly supported by Section 5.2: the needle-vs-haystack selectivity on holds at every length, so dilution compresses the absolute magnitude of needle attention but not its relative ranking. Temperature sharpening amplifies the pre-softmax logit gap and converts the residual relative advantage into absolute attention mass, thereby achieving label-free directed amplification. Partial specificity offers two layers of safety. First, AHS sharpens heads that fine-tuning has already strengthened, thereby avoiding triggering out-of-distribution behavior unseen in the base. Second, selecting the sparse top-5% subset by selectivity naturally excludes attention-sink heads (whose weights are routed to BOS/system tokens, ), avoiding the sink-collapse side effect of network-wide sharpening.
Concretely, AHS scales the pre-softmax logits of each by temperature during forward computation while leaving the other heads intact:
is reused directly from Section 5.2; the tunable hyperparameters are and .
6.3 Context-Aware Hyperparameter Routing (CAHR)
The length-wise sweep in Appendix H shows that the optimal configuration of a guardrail differs across context lengths, so any fixed configuration is suboptimal in some range. CAHR formalizes configuration selection as a routing table over length×audit side; the table is fitted on SafetyNIAH and frozen at deployment.
Offline fitting. For each guardrail and method family , SafetyNIAH is split into cells indexed by ; on each cell we record over all candidates, including the no-operation option .
Online inference. For each input x with known audit side t, CAHR first runs the base prediction, length bucket, and routing lookup,
and returns if (base-cascade gating, preventing chunk voting or attention sharpening from flipping a correctly detected unsafe case back to safe) or ; otherwise it returns . All three features (length, audit side, base prediction) are deployment-observable, and Appendix H.2 confirms that none of them is redundant.
7 Evaluation of Mitigations
This section continues to answer RQ3 by checking whether the two methods consistently restore detection across long-context distributions without significantly inflating false alarms on safe samples.
7.1 Experimental Setup
Benchmarks. We evaluate on five test sets across three categories.
In-domain synthetic: the SafetyNIAH main benchmark (30,400 samples). We split SafetyNIAH at the needle level into a 7:3 dev/test split. The routing table is fitted on the dev split; SafetyNIAH scores are computed on the test split. Appendix H.3 reports 5-fold cross-validation.
OOD input-side long-context attacks: MSJ (Anil et al., 2024) (320 samples) prepends multi-turn harmful demonstrations to a target query,
| Model / Method | In-domain synthetic | OOD input-side long-context attacks | OOD output-side long outputs | Avg. Δ | |||
|---|---|---|---|---|---|---|---|
| SafetyNIAH | MSJ | NINJA | Qwen3G-long | RShield-long | |||
| LlamaGuard3-8B | 50.00 | 75.00 | 60.31 | 49.34 | 44.93 | - | |
| + CAHR-CD | 77.42 | 100.00 | 99.27 | 67.54 | 67.16 | +26.36 | |
| + CAHR-AHS | 63.50 | 80.94 | 80.73 | 57.80 | 53.92 | +11.46 | |
| NemotronGuardV2-8B | 48.38 | 75.62 | 35.21 | 16.47 | 19.60 | - | |
| + CAHR-CD | 79.60 | 100.00 | 67.71 | 78.37 | 69.52 | +39.98 | |
| + CAHR-AHS | 75.01 | 76.56 | 53.02 | 69.11 | 61.99 | +28.08 | |
| NemotronGuardV3-8B | 53.84 | 80.62 | 53.54 | 13.93 | 11.60 | - | |
| + CAHR-CD | 82.75 | 100.00 | 70.00 | 84.43 | 76.42 | +40.01 | |
| + CAHR-AHS | 75.59 | 90.00 | 66.56 | 63.31 | 51.88 | +26.76 | |
| PolyGuard-7B | 80.77 | 99.69 | 75.73 | 77.46 | 78.07 | - | |
| + CAHR-CD | 82.83 | 100.00 | 75.73 | 76.92 | 75.85 | -0.08 | |
| + CAHR-AHS | 82.11 | 100.00 | 80.62 | 78.99 | 76.45 | +1.29 | |
| Qwen3Guard-Gen-8B (strict) | 80.29 | 100.00 | 92.50 | 79.71 | 83.62 | - | |
| + CAHR-CD | 85.19 | 100.00 | 96.35 | 79.71 | 83.62 | +1.75 | |
| + CAHR-AHS | 83.25 | 100.00 | 95.73 | 80.58 | 84.34 | +1.56 | |
| YuFeng-XGuard-8B | 75.85 | 72.71 | 73.99 | 83.68 | - | ||
| + CAHR-CD | 84.39 | 100.00 | 78.44 | 83.84 | 83.59 | +22.68 | |
| + CAHR-AHS | 78.97 | 31.56 | 74.38 | 78.66 | 84.32 | +6.21 | |
| six-guard mean | 64.86 | 73.59 | 65.00 | 51.82 | 53.58 | - | |
| + CAHR-CD | 82.03 | 100.00 | 81.25 | 78.47 | 76.03 | +21.79 | |
| + CAHR-AHS | 76.41 | 79.84 | 75.17 | 71.41 | 68.81 | +12.56 | |
Table 2: Cross-distribution performance on five long-context benchmarks; “Avg. ” is the mean improvement over the original. YuFeng-XGuard-8B’s low MSJ baseline reflects 88.1% invalid parses hijacked by the in-context demonstrations, not detection collapse.
and NINJA (Shah et al., 2025) (960 samples) embeds harmful instructions into LLM-generated benign haystacks with front/middle/end positions; both reuse 80 HarmBench-val harmful goals as targets.
OOD output-side long outputs: Qwen3G-long (1,059 samples) and RShield-long (1,866 samples) extend Qwen3GuardTest (Zhao et al., 2025) and ReasoningShieldTest (Li et al., 2025) (avg. tokens) by treating each original response as a needle and filling Wikipedia chunks up to , mirroring the SafetyNIAH response-side construction.
Metrics. For benchmarks containing both unsafe and safe samples (SafetyNIAH, Qwen3G-long, RShield-long), we report as the primary metric, which jointly constrains precision and recall and prevents inflating recall by safe→unsafe misclassification. For the attack-only benchmarks (MSJ, NINJA), we report the unsafe recall .
7.2 Results
Consistent gains across benchmarks. On the six-guard mean (Table 2), CAHR-CD and CAHR-AHS surpass the base on every primary column by +21.79% and +12.56% on average. Routing tables are fitted on the dev split of SafetyNIAH only, yet the consistent gains on the four frozen OOD benchmarks (MSJ, NINJA, Qwen3G-long, RShield-long) suggest these are not surface patterns of synthetic needle-haystack pairs.

Figure 9: Effect-cost trade-off of CAHR. Horizontal: relative processed-token budget ( original); vertical: six-guard mean of the five primary metrics.
Length-wise recovery. By length, the base drops monotonically on every benchmark (SafetyNIAH 82.7→40.2 at 0.25k→32k; MSJ 93.3→39.4 at 4k→64k), while the CAHR-CD and CAHR-AHS curves flatten (CAHR-CD on SafetyNIAH: 85.0→79.4, ~1/8 of the base drop). The gains target the long-context dimension specifically; per-length curves are in Appendix I.
Effect-cost trade-off. CAHR-CD attains the larger gain at higher token cost, though the gain shrinks toward zero on already-robust guards (PolyGuard -0.08, Qwen3Guard +1.75), while CAHR-AHS gives milder gains ([+1.29, +28.08]) at a cost close to the base; the two fit different deployment budgets (Figure 9).
8 Generalization Across Filler Domains
Sections 4 and 7 establish two findings on SafetyNIAH, whose haystack is drawn from English Wikipedia: unsafe recall degrades monotonically with length, and CAHR-CD/CAHR-AHS consistently recover it. Here we check whether both findings persist when the filler is replaced by natural text from other domains and languages.
Construction. We uniformly sample 800 needles from the SafetyNIAH needle pool, balanced across length, label, and source benchmark, and hold the needle/position/length grid fixed as in Section 3. We replace the English-Wikipedia haystack with three natural sources:
- conversation – real multi-turn chats from WildChat (Zhao et al., 2024);
-
code – multi-language source code from The Stack (Kocetkov et al., 2022);
-
Chinese – non-English text from Chinese Wikipedia, a language that has dedicated safety moderators (Chen et al., 2025).
This yields 2,400 samples, which we evaluate on the six guardrails from Section 5 under the base guard, CAHR-CD, and CAHR-AHS.
Both conclusions hold across domains. Table 3 shows that base unsafe recall degrades monotonically with length in every domain (six-guard mean from 0.25k to 32k: conversation, code, Chinese), matching the Wikipedia-filler result of Section 4.1. Table 4 shows that CAHR-CD and CAHR-AHS raise over the base in every domain, with CD giving the larger gain (+12.1 to +24.0) and AHS the cheaper one (+8.6 to +12.0), mirroring the effect-cost ordering of Section 7. These results indicate that both the degradation and the mitigation gains generalize beyond English-Wikipedia filler to conversational, code, and non-English text.
9 Conclusion
We present LongGuard, a unified framework for evaluating, analyzing, and mitigating long-context guardrail failure. SafetyNIAH shows that across 15 guards, unsafe recall drops by over on average, driven by proportional dilution of the unsafe needle rather than absolute length. A three-layer attention→logit→behavior analysis localizes the mechanism to a sparse set of guard-specialized retrieval heads with partial specificity to their base models. Two training-free methods (CD, AHS) under CAHR routing then improve five cross-distribution benchmarks by +21.79% and +12.56% on average. Both the degradation and the mitigation effects also generalize across domains and languages. We hope these results push guardrail training and evaluation to treat context length as a first-class axis.
| Domain | 0.25k | 0.5k | 2k | 8k | 32k | |
|---|---|---|---|---|---|---|
| conversation | 68.7 | 59.3 | 44.0 | 30.3 | 27.3 | -41.3 |
| code | 83.7 | 77.0 | 66.0 | 57.0 | 49.0 | -34.7 |
| Chinese | 71.7 | 63.7 | 51.0 | 44.3 | 38.7 | -33.0 |
Table 3: Unsafe recall by filler domain and context length (six-guard mean, %).
| Domain | base | CAHR-CD | CAHR-AHS |
|---|---|---|---|
| conversation | 47.0 | 71.0 (+24.0) | 59.0 (+12.0) |
| code | 67.9 | 80.0 (+12.1) | 76.5 (+8.6) |
| Chinese | 57.4 | 74.1 (+16.7) | 67.9 (+10.5) |
Table 4: by filler domain: base vs. CAHR-CD vs. CAHR-AHS (six-guard mean, %, over all lengths).
Limitations
This paper primarily bases its experimental analysis on controllably synthesized samples. Future research will further develop long-context safety datasets that more faithfully reflect real-world scenarios and are collected from naturally occurring interactions, enabling more comprehensive testing and analysis of the phenomena under investigation. In addition, the mitigation strategies studied in this paper are deliberately positioned as training-free, inference-time methods; approaches that require fine-tuning the guard model lie outside the scope of this paper.
Ethical Considerations
Our findings are double-edged: they can inform guardrail improvement, but they could also be exploited by attackers. SafetyNIAH is a diagnostic stress test, not a training corpus: needles inherit 17 public benchmarks (Appendix A) under their original licenses, haystacks are guardrail-filtered, and access is restricted to safety research with upstream takedowns honored.
https://huggingface.co/datasets/wikimedia/wikipedia/viewer/20231101.zh
Acknowledgements
This work is supported by the National Natural Science Foundation of China (No. U24A20335).
References
Cem Anil, Esin Durmus, Nina Panickssery, Mrinank Sharma, Joe Benton, Sandipan Kundu, Joshua Batson, Meg Tong, Jesse Mu, Daniel Ford, and 1 others. 2024. Many-shot jailbreaking. Advances in Neural Information Processing Systems, 37:129696–129742.
Patrick Chao, Edoardo Debenedetti, Alexander Robey, Maksym Andriushchenko, Francesco Croce, Vikash Sehwag, Edgar Dobriban, Nicolas Flammarion, George J Pappas, Florian Tramer, and 1 others. 2024. Jailbreakbench: An open robustness benchmark for jailbreaking large language models. Advances in Neural Information Processing Systems, 37:55005–55029.
Ziyang Chen, Huimu Yu, Xing Wu, Dongqin Liu, and Songlin Hu. 2025. Libra: Large chinese-based safeguard for ai content. In CCF International Conference on Natural Language Processing and Chinese Computing, pages 567–580. Springer.
Justin Cui, Wei-Lin Chiang, Ion Stoica, and Cho-Jui Hsieh. 2024. Or-bench: An over-refusal benchmark for large language models. arXiv preprint arXiv:2405.20947.
Shaona Ghosh, Prasoon Varshney, Erick Galinkin, and Christopher Parisien. 2024. Aegis: Online adaptive ai content safety moderation with ensemble of llm experts. arXiv preprint arXiv:2404.05993.
Shaona Ghosh, Prasoon Varshney, Makesh Narsimhan Sreedhar, Aishwarya Padmakumar, Traian Rebedea, Jibin Rajan Varghese, and Christopher Parisien. 2025. Aegis2. 0: A diverse ai safety dataset and risks taxonomy for alignment of llm guardrails. In Proceedings of the 2025 Conference of the Nations of the Americas Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 1: Long Papers), pages 5992–6026.
Daya Guo, Dejian Yang, Haowei Zhang, Junxiao Song, Peiyi Wang, Qihao Zhu, Runxin Xu, Ruoyu Zhang, Shirong Ma, Xiao Bi, and 1 others. 2025. Deepseek-r1: Incentivizing reasoning capability in llms via reinforcement learning. arXiv preprint arXiv:2501.12948.
Seungju Han, Kavel Rao, Allyson Ettinger, Liwei Jiang, Bill Yuchen Lin, Nathan Lambert, Yejin Choi, and Nouha Dziri. 2024. Wildguard: Open one-stop moderation tools for safety risks, jailbreaks, and refusals of llms. Advances in neural information processing systems, 37:8093–8131.
Mianqiu Huang, Xiaoran Liu, Shaojun Zhou, Mozhi Zhang, Qipeng Guo, Linyang Li, Pengyu Wang, Yang
Gao, Chenkun Tan, Linlin Li, and 1 others. 2025. Longsafety: Enhance safety for long-context llms. In Proceedings of the The First Workshop on LLM Security (LLMSEC), pages 26–47.
Hakan Inan, Kartikeya Upasani, Jianfeng Chi, Rashi Rungta, Krithika Iyer, Yuning Mao, Michael Tontchev, Qing Hu, Brian Fuller, Davide Testuggine, and 1 others. 2023. Llama guard: Llm-based input-output safeguard for human-ai conversations. arXiv preprint arXiv:2312.06674.
Jiaming Ji, Donghai Hong, Borong Zhang, Boyuan Chen, Josef Dai, Boren Zheng, Tianyi Alex Qiu, Jiayi Zhou, Kaile Wang, Boxun Li, and 1 others. 2025. Pku-saferlhf: Towards multi-level safety alignment for llms with human preference. In Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 31983–32016.
Jiaming Ji, Mickel Liu, Josef Dai, Xuehai Pan, Chi Zhang, Ce Bian, Boyuan Chen, Ruiyang Sun, Yizhou Wang, and Yaodong Yang. 2023. Beavertails: Towards improved safety alignment of llm via a human-preference dataset. Advances in Neural Information Processing Systems, 36:24678–24704.
Liwei Jiang, Kavel Rao, Seungju Han, Allyson Ettinger, Faeze Brahman, Sachin Kumar, Niloofar Mireshghallah, Ximing Lu, Maarten Sap, Yejin Choi, and 1 others. 2024. Wildteaming at scale: From in-the-wild jailbreaks to (adversarially) safer language models. Advances in Neural Information Processing Systems, 37:47094–47165.
Denis Kocetkov, Raymond Li, Loubna Ben Allal, Jia Li, Chenghao Mou, Carlos Muñoz Ferrandis, Yacine Jernite, Margaret Mitchell, Sean Hughes, Thomas Wolf, and 1 others. 2022. The stack: 3 tb of permissively licensed source code. arXiv preprint arXiv:2211.15533.
Priyanshu Kumar, Devansh Jain, Akhila Yerukola, Liwei Jiang, Himanshu Beniwal, Thomas Hartvigsen, and Maarten Sap. 2025. Polyguard: A multilingual safety moderation tool for 17 languages. arXiv preprint arXiv:2504.04377.
Changyi Li, Jiayi Wang, Xudong Pan, Geng Hong, and Min Yang. 2025. Reasoningshield: Safety detection over reasoning traces of large reasoning models. arXiv preprint arXiv:2505.17244.
Lijun Li, Bowen Dong, Ruohui Wang, Xuhao Hu, Wangmeng Zuo, Dahua Lin, Yu Qiao, and Jing Shao. 2024. Salad-bench: A hierarchical and comprehensive safety benchmark for large language models. In Findings of the Association for Computational Linguistics: ACL 2024, pages 3923–3954.
Junyu Lin, Meizhen Liu, Xiufeng Huang, Jinfeng Li, Haiwen Hong, Xiaohan Yuan, Yuefeng Chen, Long-tao Huang, Hui Xue, Ranjie Duan, and 1 others. 2026. Yufeng-xguard: A reasoning-centric, interpretable, and flexible guardrail model for large language models. arXiv preprint arXiv:2601.15588.
Zi Lin, Zihan Wang, Yongqi Tong, Yangkun Wang, Yuxin Guo, Yujia Wang, and Jingbo Shang. 2023. Toxicchat: Unveiling hidden challenges of toxicity detection in real-world user-ai conversation. In Findings of the Association for Computational Linguistics: EMNLP 2023, pages 4694–4702.
Yue Liu, Hongcheng Gao, Shengfang Zhai, Yufei He, Jun Xia, Zhengyu Hu, Yulin Chen, Xihong Yang, Jiaheng Zhang, Stan Z Li, and 1 others. 2025. Guardreasoner: Towards reasoning-based llm safeguards. arXiv preprint arXiv:2501.18492.
Yida Lu, Jiale Cheng, Zhexin Zhang, Shiyao Cui, Cunxiang Wang, Xiaotao Gu, Yuxiao Dong, Jie Tang, Hongning Wang, and Minlie Huang. 2025. Longsafety: Evaluating long-context safety of large language models. In Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 31705–31725.
Todor Markov, Chong Zhang, Sandhini Agarwal, Florentine Eloundou Nekoul, Theodore Lee, Steven Adler, Angela Jiang, and Lilian Weng. 2023. A holistic approach to undesired content detection in the real world. In Proceedings of the AAAI conference on artificial intelligence, volume 37, pages 15009–15018.
Mantas Mazeika, Long Phan, Xuwang Yin, Andy Zou, Zifan Wang, Norman Mu, Elham Sakhaee, Nathaniel Li, Steven Basart, Bo Li, and 1 others. 2024. Harmbench: A standardized evaluation framework for automated red teaming and robust refusal. arXiv preprint arXiv:2402.04249.
OpenAI. 2025. Introducing gpt-oss-safeguard. https://openai.com/index/introducing-gpt-oss-safeguard/. OpenAI Blog.
Sophie Ostmeier, Brian Axelrod, Maya Varma, Asad Aali, Yabin Zhang, Magdalini Paschali, Sanmi Koyejo, Curtis Langlotz, and Akshay Chaudhari. 2026. Attention head entropy of llms predicts answer correctness. arXiv preprint arXiv:2602.13699.
Paul Röttger, Hannah Kirk, Bertie Vidgen, Giuseppe Attanasio, Federico Bianchi, and Dirk Hovy. 2024. Xstest: A test suite for identifying exaggerated safety behaviours in large language models. In Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 1: Long Papers), pages 5377–5400.
Rishi Rajesh Shah, Chen Henry Wu, Shashwat Saxena, Ziqian Zhong, Alexander Robey, and Aditi Raghunathan. 2025. Jailbreaking in the haystack. arXiv preprint arXiv:2511.04707.
Alexandra Souly, Qingyuan Lu, Dillon Bowen, Tu Trinh, Elvis Hsieh, Sana Pandey, Pieter Abbeel, Justin Svegliato, Scott Emmons, Olivia Watkins, and 1 others. 2024. A strongreject for empty jailbreaks. Advances in Neural Information Processing Systems, 37:125416–125440.
Makesh Narsimhan Sreedhar, Traian Rebedea, and Christopher Parisien. 2025. Safety through reasoning: An empirical study of reasoning guardrail models. In EMNLP (Findings), pages 21862–21880.
Saba Sturua, Isabelle Mohr, Mohammad Kalim Akram, Michael Günther, Bo Wang, Markus Krimmel, Feng Wang, Georgios Mastrapas, Andreas Koukounas, Nan Wang, and 1 others. 2024. jina-embeddings-v3: Multilingual embeddings with task lora. arXiv preprint arXiv:2409.10173.
Bertie Vidgen, Nino Scherrer, Hannah Rose Kirk, Rebecca Qian, Anand Kannappan, Scott A Hale, and Paul Röttger. 2023. Simplesafetytests: a test suite for identifying critical safety risks in large language models. arXiv preprint arXiv:2311.08370.
An Yang, Anfeng Li, Baosong Yang, Beichen Zhang, Binyuan Hui, Bo Zheng, Bowen Yu, Chang Gao, Chengen Huang, Chenxu Lv, and 1 others. 2025. Qwen3 technical report. arXiv preprint arXiv:2505.09388.
Xiaohan Yuan, Jinfeng Li, Dongxia Wang, Yuefeng Chen, Xiaofeng Mao, Longtao Huang, Jialuo Chen, Hui Xue, Xiaoxia Liu, Wenhai Wang, and 1 others. 2025. S-eval: Towards automated and comprehensive safety evaluation for large language models. Proceedings of the ACM on Software Engineering, 2(ISSTA):2136–2157.
Wenjun Zeng, Yuchi Liu, Ryan Mullins, Ludovic Peran, Joe Fernandez, Hamza Harkous, Karthik Narasimhan, Drew Proud, Piyush Kumar, Bhaktipriya Radharapu, and 1 others. 2024. Shieldgemma: Generative ai content moderation based on gemma. arXiv preprint arXiv:2407.21772.
Yi Zeng, Yu Yang, Andy Zhou, Jeffrey Tan, Yuheng Tu, Yifan Mai, Kevin Klyman, Minzhou Pan, Ruoxi Jia, Dawn Song, and 1 others. 2025. Air-bench 2024: A safety benchmark based on regulation and policies specified risk categories. In International Conference on Learning Representations, volume 2025, pages 63997–64031.
Haiquan Zhao, Chenhan Yuan, Fei Huang, Xiaomeng Hu, Yichang Zhang, An Yang, Bowen Yu, Dayiheng Liu, Jingren Zhou, Junyang Lin, and 1 others. 2025. Qwen3guard technical report. arXiv preprint arXiv:2510.14276.
Wenting Zhao, Xiang Ren, Jack Hessel, Claire Cardie, Yejin Choi, and Yuntian Deng. 2024. Wildchat: 1m chatgpt interaction logs in the wild. In International Conference on Learning Representations, volume 2024, pages 34590–34605.
Zhenhong Zhou, Haiyang Yu, Xinghua Zhang, Rongwu Xu, Fei Huang, Kun Wang, Yang Liu, Junfeng Fang, and Yongbin Li. 2025. On the role of attention heads in large language model safety. In International Conference on Learning Representations, volume 2025, pages 84042–84071.
A Benchmark Statistics
Figure 10 shows the composition of the Safety-NIAH main benchmark over context length, needle position, audit side, and haystack type. Tables 5 and 6 summarize the raw candidate sources and the six long-context evaluation sets, respectively.
B Full Model List
Table 7 lists the 15 open-source safety guardrails benchmarked in this paper. Inference is deterministic (temperature 0). The strict-filtering subset used to construct the neutral haystack pool (Section 3) and the six full-attention guardrails used for mechanistic analysis (Section 5) are both drawn from this list.
C Behavior-Side Ablations
C.1 Haystack Type: Priming Effect
Contrary to intuition, Figure 11 (a–b) shows that Related haystacks yield consistently higher than Random across all eight lengths: the cross-model gap is between -1.73% and -4.45% (largest at 1k–2k), and the effect on response is 2–3× that on prompt. Figure 11 (c) shows that the effect is stable across the 15 models with only one positive outlier (GPT-OSS-SafeGuard-20B). We interpret it as a priming effect: a haystack of the same topic as the needle keeps the “risk-related” semantic backdrop active and sustains a higher safety activation, whereas a Random haystack injects the needle into an unrelated semantic flow and lets attention dilute more easily.
C.2 Needle-Position Sensitivity: Lost-in-the-Middle and Endpoint Asymmetry
As shown in Figure 12 (a–b), at is higher than at the three middle positions across all lengths, exhibiting a typical lost-in-the-middle pattern. Taking the edge-middle gap as average) minus average), the gap grows monotonically from at to at on the prompt side, and from to on the response side. At , the prompt side shows an extra collapse at ( ) and the cross-model edge-middle gap falls from at to at . To avoid the mixed regime where endpoint advantage fails together with parsing failure, Figure 12 (c) restricts the slice to . The endpoint pattern is asymmetric: the prompt side is roughly bimodal, while the response side prefers the head is the highest at all lengths and falls to the middle. This matches the chat-template structure (prompt detection anchors both ends of a user turn to localize instructions; response detection mainly anchors the beginning of the assistant reply for safety cues). Figure 12 (c) further splits the models into three groups: (i) lost-in-the-middle (NemotronReasoning-4B 44.06%, GuardReasoner-8B 38.04%, YuFeng-XGuard-8B 37.58%); (ii) long-context robust (GPT-OSS-SafeGuard-20B, PolyGuard-7B); (iii) total collapse (WildGuard-7B, ShieldGemma-9B), where all positions are near zero at .
C.3 Failure Modes and Archetypes
To consolidate the observations at the model level, Figure 13 merges five failure axes into a single radar: Dilution ( on Benign-Fill), Parsing (inv@32k), Asymmetry (absolute difference of prompt/response ), Lost-mid (edge-middle gap at 8k–16k), and Priming (Random–Related). The shapes split the 15 guardrails into five archetypes: (i) total collapse (WildGuard, Shield-Gemma); (ii) parsing failure (NemotronGuardV3, WildGuard); (iii) lost-in-the-middle (Nemotron-Reasoning, GuardReasoner, YuFeng-XGuard); (iv) asymmetric drift (Qwen3Guard-Stream, LlamaGuard4); (v) long-context robust (GPT-OSS-SafeGuard, PolyGuard), which serves as a natural upper-bound reference for our methods.
D Mediation Consistency Across the Three Layers
We further check that the three layers move together beyond a common length covariate. On the 48 (model, length) units of Benign-Fill / unsafe, we pair the layer-level scalars (sample-mean , sample-mean logit margin, ) and compute Pearson partial correlations after controlling for . The evidence is mediation consistency, not strict causality: partial correlation rules out length as the most salient confounder but not other unobserved variables.
Figure 14 shows that both legs of the chain are highly significant: attention→logit ( ); logit→behavior ( ) with a near-sigmoidal shape; end-to-end attention→behavior . Partial
(a) Data sources

(b) Audit Side

(c) Sample label

(d) Haystack type

(e) Context length

(f) Needle position

Figure 10: Composition of the SafetyNIAH main benchmark.
| Source benchmark | Use | Audit side | #Samples | Label ratio | Avg. length (words) | License |
|---|---|---|---|---|---|---|
| OpenAIModeration (Markov et al., 2023) | SafetyNIAH needle pool | input | 1,680 | safe 68.93% / unsafe 31.07% | prompt 111.0 | MIT |
| ToxicChat (Lin et al., 2023) | SafetyNIAH needle pool | input | 5,083 | safe 92.88% / unsafe 7.12% | prompt 28.2 | CC-BY-NC-4.0 |
| SimpleSafetyTests (Vidgen et al., 2023) | SafetyNIAH needle pool | input | 100 | unsafe 100.00% | prompt 11.4 | CC-BY-2.0 |
| WildJailbreak (Jiang et al., 2024) | SafetyNIAH needle pool | input | 2,210 | safe 9.50% / unsafe 90.50% | prompt 120.6 | ODC-BY |
| SaladBench (Li et al., 2024) | SafetyNIAH needle pool | input | 26,318 | unsafe 100.00% | prompt 94.0 | Apache-2.0 |
| AirBench (Zeng et al., 2025) | SafetyNIAH needle pool | input | 5,694 | unsafe 100.00% | prompt 120.6 | CC-BY-4.0 |
| StrongReject (Souly et al., 2024) | SafetyNIAH needle pool | input | 313 | unsafe 100.00% | prompt 25.9 | MIT |
| Aegis (Ghosh et al., 2024) | SafetyNIAH needle pool | input | 1,199 | safe 46.96% / unsafe 53.04% | prompt 130.9 | CC-BY-4.0 |
| OR-Bench (Cui et al., 2024) | SafetyNIAH needle pool | input | 1,974 | safe 66.82% / unsafe 33.18% | prompt 17.0 | CC-BY-4.0 |
| S-Eval (Yuan et al., 2025) | SafetyNIAH needle pool | input | 110,000 | unsafe 100.00% | prompt 182.1 | CC-BY-NC-SA-4.0 |
| JailbreakBench (Chao et al., 2024) | SafetyNIAH needle pool | input | 200 | safe 50.00% / unsafe 50.00% | prompt 12.9 | |
| output | 300 | safe 63.33% / unsafe 36.67% | prompt 79.7 / response 99.4 | MIT | ||
| WildGuardTest (Han et al., 2024) | SafetyNIAH needle pool | input | 1,699 | safe 55.62% / unsafe 44.38% | prompt 75.4 | |
| output | 1,709 | safe 83.38% / unsafe 16.62% | prompt 75.1 / response 272.0 | ODC-BY | ||
| XSTest (Röttger et al., 2024) | SafetyNIAH needle pool | input | 446 | safe 55.83% / unsafe 44.17% | prompt 8.4 | |
| output | 446 | safe 82.51% / unsafe 17.49% | prompt 8.4 / response 139.4 | ODC-BY | ||
| HarmBench (Mazeika et al., 2024) | SafetyNIAH needle pool | input | 320 | unsafe 100.00% | prompt 64.8 | |
| output | 602 | safe 54.65% / unsafe 45.35% | prompt 160.2 / response 218.1 | MIT | ||
| Aegis2.0 (Ghosh et al., 2025) | SafetyNIAH needle pool | input | 1,964 | safe 46.08% / unsafe 53.92% | prompt 44.9 | |
| output | 813 | safe 51.54% / unsafe 48.46% | prompt 12.9 / response 115.7 | CC-BY-4.0 | ||
| BeaverTails (Ji et al., 2023) | SafetyNIAH needle pool | output | 3,021 | safe 42.63% / unsafe 57.37% | prompt 13.1 / response 59.8 | CC-BY-NC-4.0 |
| SafeRLHF (Ji et al., 2025) | SafetyNIAH needle pool | output | 16,422 | safe 47.69% / unsafe 52.31% | prompt 22.2 / response 86.1 | CC-BY-NC-4.0 |
| Qwen3GuardTest (Zhao et al., 2025) | OOD long output | output | 1,059 | safe 46.27% / unsafe 53.73% | prompt 13.2 / response 681.0 | CC-BY-NC-4.0 |
| ReasoningShieldTest (Li et al., 2025) | OOD long output | output | 2,200 | safe 56.27% / unsafe 28.55% / ambig. 15.18% | prompt 83.5 / response 809.6 | CC-BY-NC-4.0 |
Table 5: Source benchmarks used in this paper.
| Benchmark | #Samples | #Safe / #Unsafe | #Prompt / #Response | Length (words) | |||
|---|---|---|---|---|---|---|---|
| Avg. | Median | p90 | Max | ||||
| SafetyNIAH (Benign-Fill) | 30,400 | 12,800 / 17,600 | 19,200 / 11,200 | 8,160 | 3,072 | 32,768 | 32,768 |
| SafetyNIAH (Needle-Repeat) | 8,800 | 0 / 8,800 | 6,000 / 2,800 | 8,160 | 3,072 | 32,768 | 32,768 |
| MSJ | 320 | 0 / 320 | 320 / 0 | 26,278 | 21,120 | 56,217 | 58,004 |
| NINJA | 960 | 0 / 960 | 960 / 0 | 4,558 | 3,502 | 10,232 | 10,403 |
| Qwen3G-long | 1,059 | 490 / 569 | 0 / 1,059 | 6,264 | 4,084 | 16,373 | 16,381 |
| RShield-long | 1,866 | 1,238 / 628 | 0 / 1,866 | 6,319 | 4,073 | 16,363 | 16,381 |
Table 6: Statistics of the six long-context evaluation sets.
correlations after controlling for are +0.65, +0.83, and +0.56 (all ), so the three layers continue to move together on the residual structure of the (model, length) grid.
E Per-Head Needle-Attention Heatmap: Full Length Sweep
Figure 18 expands Figure 6 to all five lengths. Three patterns consistent with the main text are visible: (i) bright pixels remain sparsely concen-
| Model | Size | Backbone | Detection | Output format | License |
|---|---|---|---|---|---|
| LlamaGuard3 (Inan et al., 2023) | 8B | Llama-3.1-8B | input+output | safe/unsafe | Llama 3.1 Community License |
| LlamaGuard4 (Inan et al., 2023) | 12B | Llama-4-Scout | input+output | safe/unsafe | Llama 4 Community License |
| WildGuard (Han et al., 2024) | 7B | Mistral-7B-v0.3 | input+output+refusal | safe/unsafe | Apache-2.0 |
| NemotronGuardV2 (Ghosh et al., 2025) | 8B | Llama-3.1-8B-Instruct | input+output | safe/unsafe | NVIDIA OML + Llama 3.1 |
| NemotronGuardV3 (Ghosh et al., 2025) | 8B | Llama-3.1-8B-Instruct | input+output | safe/unsafe | NVIDIA OML + Llama 3.1 |
| NemotronReasoning (Sreedhar et al., 2025) | 4B | Gemma-3-4b-it | input+output | safe/unsafe + rationale | NVIDIA OML + Gemma Terms |
| ShieldGemma (Zeng et al., 2024) | 9B | Gemma2-9B | input+output | safe/unsafe | Gemma Terms of Use |
| GuardReasoner (Liu et al., 2025) | 8B | Llama-3.1-8B | input+output+refusal | safe/unsafe + chain | Apache-2.0 |
| PolyGuard (Kumar et al., 2025) | 7B | Qwen2.5-7B-Instruct | input+output+refusal | safe/unsafe | CC-BY-4.0 |
| Qwen3Guard (Zhao et al., 2025) | 8B | Qwen3-8B | input+output+refusal | safe/unsafe/controversial | Apache-2.0 |
| GPT-OSS-SafeGuard (OpenAI, 2025) | 20B | gpt-oss-20b | custom | custom | Apache-2.0 |
| YuFeng-XGuard (Lin et al., 2026) | 8B | Qwen3-8B | input+output | safe/unsafe (threshold) | Apache-2.0 |
Table 7: Guardrails used in this paper.


Figure 11: Effect of haystack type on . (a–b) Cross-model average under prompt/response, Random vs. Related. (c) Per-model heatmap of gap = , averaged over the two audit sides; negative (blue) means Related > Random.


Figure 12: Sensitivity to needle position. (a–b) as a function of needle position under prompt/response; one curve per length. (c) Per-model heatmap of at , averaged over audit side and haystack type.
trated on the same middle-late layers across all lengths, so the retrieval heads are structurally stable; (ii) the band darkens monotonically from 0.25k to 32k with no rebound; (iii) the band width differences across models correspond exactly to the vertical separation in the top-5% cumulative curves of Figure 7.
F Base vs. Guard Control Experiment
The sparsity of in Section 5.2 could reflect a generic long-tail property of transformer attention (attention sinks, induction heads) rather than something specific to guard fine-tuning. This appendix runs a base-guard differential control to reject this null.
Setup. For each guard in Section 5 we read its base from Appendix B; the three Llama guards share Llama-3.1-8B-Instruct (NemotronGuardV2 is in fact a LoRA adapter on this base), and PolyGuard/YuFeng-XGuard reuse the YaRN rope_scaling (factor = 4) so that bases do not collapse from naive RoPE extrapolation. Inputs (the Section 4 unsafe-needle samples; Benign-Fill, 8 lengths, prompt and response) and attention extraction (Section 5, aligned with the guard side) are identical for base










Figure 13: Radar of 15 guardrails over five failure axes. All axes are min–max normalized within the 15 models to [0, 1] (outside = more brittle on that axis); subplots are sorted by the normalized total score, colored by archetype.

LlamaGuard3-8B
NemotronGuardV2-8B
NemotronGuardV3-8B
PolyGuard-7B
Qwen3Guard-Gen-8B
YuFeng-XGuard-8B
.25k
2k
32k
Figure 14: Correlations among attention, logit, and behavior on 48 (model, length) units. Each point is a unit; color encodes the model, and marker size scales with . Each panel reports Pearson , Spearman , and the partial correlation .
| Guard model | C1 top-5%@256 (b/g/Δ) | C1 top-5%@32k (b/g/Δ) | C2 ρ@32k | C2 Jaccard@32k | C3 |β| ratio g/b | C3 MWU p | Verdict |
|---|---|---|---|---|---|---|---|
| LlamaGuard3-8B | 0.288 / 0.335 / +4.7 | 0.200 / 0.337 / +13.7 | 0.746 | 0.130 | 2.49 | < 10-15 | Partial |
| NemotronGuardV2-8B | 0.432 / 0.513 / +8.1 | 0.306 / 0.445 / +14.0 | 0.960 | 0.465 | 1.32 | 6×10-4 | Partial |
| NemotronGuardV3-8B | 0.440 / 0.524 / +8.4 | 0.313 / 0.512 / +19.9 | 0.875 | 0.465 | 0.74 | 0.98 | Partial |
| PolyGuard-7B | 0.307 / 0.330 / +2.3 | 0.279 / 0.429 / +15.0 | 0.875 | 0.356 | 1.48 | < 10-15 | Partial |
| Qwen3Guard-Gen-8B | 0.286 / 0.283 / -0.3 | 0.309 / 0.388 / +7.9 | 0.821 | 0.398 | 2.03 | < 10-15 | Partial |
| YuFeng-XGuard-8B | 0.316 / 0.366 / +5.0 | 0.259 / 0.389 / +13.1 | 0.787 | 0.094 | 2.19 | < 10-15 | Partial |
Table 8: Base vs. guard head-specificity comparison. Bold values reach the strong-specificity threshold (C1 ; C3 ratio with ).
and guard; no logit/behavior is compared since the base lacks safe/unsafe surface forms. We measure three differentials, with outcomes (strong/partial / no specificity) pre-registered:
-
C1: head concentration. Share of needle attention taken by top-k heads () per (model, length).
-
C2: ranking consistency. Spearman rank

LlamaGuard3-8B NemotronGuardV2-8B NemotronGuardV3-8B PolyGuard-7B Qwen3Guard-Gen-8B YuFeng-XGuard-8B

Figure 15: Shaping effect of guard fine-tuning on retrieval heads. (a) Top-5% head share of per (model, length); solid: guard, dashed: base. (b) Paired violin of on top-5% heads at .
| Guard model | base@32k | guard@32k | guard/base@32k |
|---|---|---|---|
| LlamaGuard3-8B | 0.0178 | 0.0938 | 5.28× |
| NemotronGuardV2-8B | 0.0173 | 0.0390 | 2.26× |
| NemotronGuardV3-8B | 0.0175 | 0.0323 | 1.84× |
| PolyGuard-7B | 0.0571 | 0.1469 | 2.57× |
| Qwen3Guard-Gen-8B | 0.0362 | 0.1092 | 3.02× |
| YuFeng-XGuard-8B | 0.0314 | 0.1361 | 4.33× |
Table 9: Absolute mean at 32k on each side's own top-5% retrieval heads (sample-weighted merge over prompt and response).
correlation between guard and base head rankings of at ; means the guard has not moved attention to different heads.
- C3: per-head dilution slope. Regressing on over gives slope ; we run a Mann–Whitney test between base and guard.
Result: partial specificity (6/6). All six pairs satisfy C2 (head identity highly overlaps, far above the strong threshold ), yet the guard top-5% share at 32k is systematically to above the base, and C3 is significant on 5/6 pairs (Table 8, Figure 15 (a)). When base and guard each use their own top-5% retrieval heads (a fairer absolute measurement), the guard is strictly larger on every pair, with cross-model audit-side ratios of (Table 9, Figure 15 (b)). Guard fine-tuning therefore does not reassign attention to different heads but amplifies the magnitude on existing retrieval-bearing heads and steepens their long- dilution slopes – the basis for restricting AHS's sharpening target (Section 6.2) to .

Figure 16: Sufficiency interventions (six-guard weighted, , ). (a) Attention masking: full vs. random vs. needle-only. (b) Retrieval-head amplification at vs. random-K.
G Token-Level and Head-Level Sufficiency Interventions
This appendix gives the full design of the two interventions summarized in Section 5.3. Both run on Benign-Fill unsafe samples at lengths 8k/16k/32k and aggregate by sample count.
Attention masking. Three visibility conditions are compared on the same inputs: full (the original long context); needle-only (only the unsafe needle plus template tokens); random (an equal token budget filled with random haystack instead of the needle).
Retrieval-head amplification. Only is modified. We post-hoc amplify the softmax-output attention from to the unsafe-needle span on the selected heads and renormalize:
where , , and is the renormalization constant. We fix and use an equal number of random heads (random-K) as the control.
Figure 16 (a): relative to the full baseline, needle-only climbs to while random falls to . The recovery comes from preserving unsafe evidence rather than from shortening the input, so unsafe evidence itself is a sufficient signal for long-context safety judgment. Figure 16 (b): retrieval-K monotonically improves with at on all six guardrails, while the matched random-K stays within . provides a functional contribution to unsafe-evidence reading; arbitrary attention perturbations do not produce comparable gains.
| Variant | use length | use type | use cascade | SafetyNIAH | MSJ | NINJA | Qwen3G-long | RShield-long | 5-bench mean |
|---|---|---|---|---|---|---|---|---|---|
| S0 original | - | - | - | 64.86 | 73.59 | 65.00 | 51.82 | 53.58 | 61.77 |
| S1 fixed_safety (single best) | - | - | - | 80.37 | 99.95 | 80.42 | 78.15 | 71.90 | 82.16 |
| S2 +length (length-only) | ✓ | - | - | 81.15 | 100.00 | 80.21 | 78.44 | 73.34 | 82.63 |
| S3 +length +cascade | ✓ | - | ✓ | 82.04 | 100.00 | 80.82 | 78.39 | 73.34 | 82.92 |
| S4 +length +type | ✓ | ✓ | - | 81.79 | 100.00 | 80.85 | 78.49 | 76.06 | 83.44 |
| S5 +length +type +cascade = CAHR | ✓ | ✓ | ✓ | 82.03 | 100.00 | 81.25 | 78.47 | 76.03 | 83.56 |
Table 10: Component ablation of CAHR on the CD family; the AHS family gives the same conclusion (CAHR 5-bench mean = 74.33).
H Hyperparameter Sweep and CAHR Ablation
H.1 Length-Wise Sweep on SafetyNIAH
Tables 11 and 12 give the of 17 candidate configurations (base + CD ×4 + AHS ×12) on the 8 length buckets of SafetyNIAH.
| Candidate | 0.25k | 0.5k | 1k | 2k | 4k | 8k | 16k | 32k |
|---|---|---|---|---|---|---|---|---|
| orig () | 82.71 | 80.67 | 73.75 | 66.74 | 59.76 | 52.68 | 49.16 | 40.21 |
| CD-64 | 81.47 | 81.01 | 79.86 | 79.84 | 79.53 | 78.45 | 77.28 | 76.06 |
| CD-128 | 81.92 | 80.93 | 79.90 | 79.95 | 79.77 | 79.04 | 78.38 | 77.36 |
| CD-256 | 81.70 | 80.93 | 79.20 | 79.21 | 79.37 | 78.82 | 78.27 | 78.10 |
| CD-512 | 81.70 | 79.95 | 77.78 | 78.03 | 78.24 | 77.78 | 77.71 | 77.54 |
Table 11: CD sweep (six-guard mean ); per-column bold is the CD-family argmax. The orig row is bold as the reference.
| 0.25k | 0.5k | 1k | 2k | 4k | 8k | 16k | 32k | |
|---|---|---|---|---|---|---|---|---|
| (1%, 0.1) | 83.86 | 82.00 | 76.97 | 72.18 | 68.60 | 61.61 | 56.50 | 48.86 |
| (1%, 0.3) | 84.07 | 82.31 | 77.29 | 72.44 | 68.57 | 61.83 | 56.74 | 49.85 |
| (1%, 0.5) | 84.00 | 82.21 | 77.14 | 71.96 | 67.88 | 61.20 | 56.37 | 49.60 |
| (1%, 0.7) | 83.64 | 81.83 | 76.76 | 71.11 | 66.75 | 59.76 | 54.98 | 48.10 |
| (5%, 0.1) | 82.25 | 80.36 | 78.10 | 73.92 | 71.40 | 66.39 | 62.29 | 50.78 |
| (5%, 0.3) | 83.83 | 82.51 | 79.20 | 75.48 | 71.81 | 66.85 | 63.62 | 52.41 |
| (5%, 0.5) | 84.32 | 83.03 | 79.57 | 75.36 | 71.86 | 66.16 | 62.00 | 51.45 |
| (5%, 0.7) | 84.12 | 82.64 | 78.64 | 73.91 | 70.47 | 63.83 | 58.95 | 49.83 |
| (10%, 0.1) | 79.04 | 77.16 | 73.99 | 70.68 | 65.84 | 62.66 | 60.51 | 48.60 |
| (10%, 0.3) | 82.11 | 81.29 | 78.93 | 74.29 | 70.57 | 65.38 | 65.11 | 54.45 |
| (10%, 0.5) | 83.67 | 83.06 | 80.39 | 76.84 | 74.20 | 67.73 | 65.36 | 56.22 |
| (10%, 0.7) | 84.08 | 82.97 | 79.60 | 75.23 | 72.30 | 65.24 | 61.21 | 52.65 |
Table 12: AHS sweep (six-guard mean ); per-column bold is the AHS-family argmax.
No single configuration is universally optimal. In the CD family the argmax is on and switches to at . In the AHS family the argmax shifts from at to at . At , orig even outperforms all four CD configurations (82.71 vs. ). The length-conditional CAHR routing table (with included as a candidate) is designed to absorb such drift. We only show the six-guard mean here; per-guard drift is larger.
H.2 Component Ablation of CAHR
We split CAHR into six independently switchable routing strategies, from the most naive original (no method) to the full CAHR (length×type table + base-cascade) layered one at a time. All routing tables are fitted on SafetyNIAH only; the five evaluation benchmarks (SafetyNIAH / MSJ / NINJA / Qwen3G-long / RShield-long) are frozen across variants. All numbers are six-guard averages; SafetyNIAH / Qwen3G-long / RShield-long report , and MSJ / NINJA report . The last column is the 5-benchmark mean.
Reading by component.
-
S0→S1 (+20.4%). A single best configuration on SafetyNIAH already brings most of the gain; this is the zero-order benefit of any long-context guardrail method.
-
S1→S2 (+0.5%). Replacing the single global best with per-length-bucket bests adds 0.3%–1.5% on long-context dual-class benchmarks (Qwen3G-long, RShield-long), confirming the cross-length drift.
-
S2→S3 (+0.3%). Base-cascade rescues samples whose base unsafe decision would be flipped by the routed method on attack-only benchmarks (NINJA +0.6%).
-
S2→S4 (+0.8%). Adding the type dimension lifts the response-heavy RShield-long by +2.7% (the largest single-item gain).
-
S4→S5 = CAHR (+0.1%). Cascade and type stacking take the last small bites of NINJA and SafetyNIAH.
H.3 5-Fold Cross-Validation on SafetyNIAH
Section 7 fits the CAHR routing table on the dev split of SafetyNIAH but evaluates it only on the held-out test split. Table 14 corroborates this fixed split with an independent 5-fold cross-validation.

Figure 17: Length-wise gain of CAHR on the five primary benchmarks (six-guard mean). The three curves are base, CAHR-CD, and CAHR-AHS; the horizontal axis is context length (words, log), and the vertical axis is the primary metric. Annotations in the longest bucket show the base drop and the CAHR recovery relative to the same-length base.
| Benchmark | Method | Unsafe precision | Safe recall | FPR | |
|---|---|---|---|---|---|
| SafetyNIAH (test) | base | 64.86 [64.2, 65.7] | 82.39 [81.5, 83.3] | 83.08 [82.4, 83.8] | 16.92 [16.2, 17.7] |
| CAHR-CD | 82.03 [81.4, 82.6] | 80.31 [79.4, 81.2] | 70.60 [69.6, 71.5] | 29.40 [28.5, 30.4] | |
| CAHR-AHS | 76.41 [75.8, 77.0] | 82.65 [81.8, 83.5] | 78.06 [77.2, 78.9] | 21.94 [21.1, 22.8] | |
| Qwen3G-long | base | 51.82 [49.6, 53.8] | 66.74 [64.8, 68.6] | 73.67 [72.1, 75.1] | 26.33 [24.9, 27.9] |
| CAHR-CD | 78.47 [76.4, 80.2] | 77.14 [74.8, 79.4] | 68.47 [66.3, 70.7] | 31.53 [29.3, 33.7] | |
| CAHR-AHS | 71.41 [69.2, 73.4] | 80.61 [78.6, 82.8] | 79.56 [78.0, 81.2] | 20.44 [18.9, 22.0] | |
| RShield-long | base | 53.58 [51.8, 55.2] | 62.71 [61.0, 64.3] | 75.15 [74.3, 76.0] | 24.85 [24.0, 25.7] |
| CAHR-CD | 76.03 [74.3, 77.7] | 67.77 [65.5, 70.1] | 76.27 [74.9, 77.7] | 23.73 [22.3, 25.1] | |
| CAHR-AHS | 68.81 [66.9, 70.4] | 70.81 [68.5, 73.1] | 84.21 [83.3, 85.3] | 15.79 [14.7, 16.7] |
Table 13: Full panel on dual-class benchmarks (six-guard mean, %). Each cell is the point estimate with its 95% sample-level bootstrap CI in brackets. SafetyNIAH is the held-out test split.
| Method | Dev | Test | 5-fold CV (mean±std) |
|---|---|---|---|
| CAHR-CD | 82.37 | 82.03 | 82.19±0.38 |
| CAHR-AHS | 76.97 | 76.41 | 76.64±0.32 |
Table 14: CAHR on SafetyNIAH: fixed dev/test split vs. 5-fold cross-validation ( , six-guard mean, %).
The fixed-split test number and the 5-fold CV mean agree closely for both families (CD: 82.03 vs. ; AHS: 76.41 vs. ), well within one cross-validation standard deviation, so the Table 2 numbers are stable across held-out partitions of SafetyNIAH.
I Length-wise Gain
Figure 17 resolves the gains of Table 2 by context length. The base drops monotonically with length across all benchmarks; CAHR-CD and CAHR-AHS recover most of that drop, confirming that the methods primarily restore the long-context dimension.
We take 1k words as the short-context cutoff based on Table 5 (the maximum average length of existing guardrail benchmarks). Figure 17 likewise shows that CAHR-CD and CAHR-AHS stay at or above the base guard up to 1k, so the methods do not degrade short-context performance.
J Deployment Metrics, Cost, and Robustness
Full metric panel. Table 13 reports , unsafe precision, safe recall, and FPR on the three dual-class benchmarks. rises under both CAHR-CD and CAHR-AHS, while unsafe precision stays close to or above the base guard.
Cost by length. Table 15 reports the relative processed-token budget ( a single original call) of the deployed CAHR policy on SafetyNIAH. Cost rises with length: CAHR-CD grows from at 0.25k to at 32k, while CAHR-AHS stays cheaper ( to ). AHS is the cost-conservative option; CD costs more and yields the larger gains of Table 13.
CD false-alarm growth. Table 16 shows that CD FPR on SafetyNIAH rises monotonically with the chunk count . This is a controlled trade-off rather than a net regression: CD trades some safe recall for a large gain (Table 13), while AHS keeps FPR closer to the base. CAHR's per-length window selection avoids the small-window / many-chunk settings that drive the worst FPR growth.
| L | CAHR-CD | CAHR-AHS |
|---|---|---|
| 0.25k | 1.44 | 1.48 |
| 1k | 1.97 | 1.55 |
| 4k | 2.86 | 1.65 |
| 16k | 2.88 | 1.74 |
| 32k | 2.94 | 1.76 |
Table 15: Relative processed-token budget of CAHR on SafetyNIAH by context length (× a single original call).
| L | W=64 | W=128 | W=256 | W=512 |
|---|---|---|---|---|
| 0.25k | 21.78 (4) | 17.77 (2) | 14.22 (1) | 14.22 (1) |
| 1k | 30.78 (16) | 24.94 (8) | 20.76 (4) | 16.61 (2) |
| 4k | 44.27 (64) | 35.15 (32) | 27.79 (16) | 22.15 (8) |
| 16k | 64.20 (256) | 48.88 (128) | 39.08 (64) | 29.72 (32) |
| 32k | 75.45 (512) | 57.72 (256) | 45.40 (128) | 34.93 (64) |
Table 16: CD FPR on SafetyNIAH by length (six-guard mean, %); the chunk count is in parentheses.
When to use CD vs. AHS. CD and AHS trade off differently. CD treats the guard as a black box, applies to most guardrails, and yields the larger gain at higher token cost and higher FPR (Tables 13–16). AHS requires white-box access to attention, applies only to open-weight guards, and is the cheaper, lower-FPR option ( tokens; Table 15). Prefer AHS when the latency or token budget is tight; prefer CD when the guard is closed or when maximizing recall is the priority.
K Use of AI Assistants
This work uses AI assistants in a limited capacity for language refinement and academic polishing. Their use is restricted to improving readability and presentation and does not influence the research methodology, data analysis, or scientific claims. The authors make all substantive contributions.
LlamaGuard3-8B
NemotronGuardV2-8B
NemotronGuardV3-8B
PolyGuard-7B
Qwen3Guard-Gen-8B
YuFeng-XGuard-8B

Figure 18: Per-head needle-attention heatmap, full length sweep (6 models × 5 lengths). Each row is one model; columns are . Horizontal axis: head index; vertical axis: layer index; color: (fill = Benign with Random and Related pooled, label = unsafe, prompt+response sample-level pooled). Each row shares its vmax and colorbar, so colors are directly comparable across lengths.