Auditing and Adapting kNNGuard for Long-Context Prompts
Niccolò Ronchetti
Abstract
Training-free activation guardrails such as kNNGuard score prompts by comparing last-token LLM hidden states (the Layer Ensemble branch, kNNGuard LE) and sentence embeddings (all-MiniLM-L6-v2, Embedding-kNN) against a small reference bank (50 examples per class), combining the two branches into a Fused Ensemble (kNNGuard FE). While effective on short inputs (up to 256 tokens), standard kNNGuard degrades substantially on long inputs (over 1000 tokens): averaged across Qwen3.5-4B and Gemma-4-E4B-it, kNNGuard LE AUROC drops from 0.742 (0.777 and 0.706) to 0.554 (0.587 and 0.521) on Content Harm Moderation (Aegis-2.0), and from 0.994 (0.995 and 0.992) to 0.556 (0.598 and 0.513) on RAG Hallucination Detection (HaluBench). We trace this degradation to three causes: (1) hidden-state drift as sequence length increases, (2) hard 256-token truncation in MiniLM, and (3) signal dilution when a long document is compressed into a single final-token vector. We then evaluate three training-free adaptations: a Length-Routed Dual Bank, a long-context embedding model (Qwen3-Embedding-0.6B), and Strided Window Pooling across intermediate token positions. On Content Harm Moderation, dual-bank routing and strided window pooling raise long-context kNNGuard LE AUROC from 0.554 to 0.828 (+0.274 AUROC) and fused kNNGuard FE AUROC from 0.721 to 0.886 (+0.164 AUROC) with no latency overhead from bank routing. On RAG Hallucination Detection, where the guardrail must verify logical consistency between a generated answer and a retrieved passage, sentence-embedding kNN remains near random chance across all lengths, while length-matched LLM hidden states (kNNGuard LE) recover medium-length detection (AUROC = 0.853) but remain limited on over-1000-token passages (AUROC = 0.607) due to final-token dilution over long contexts.
Create a lesson
Related papers
DTS: Delta-Based Tile Scoring for Efficient Long-Context Sparse Attention
Shared title terminology · Emre Uğur, Jiawen Qi, Qinyu Chen
Beyond Sample Hardness: Adaptive Data Selection through Learning Dynamics
Shared title terminology · Hai Gan, Suorong Yang, Guang Li et al.
Adapting AI Weather Foundation Models to a Changing Climate
Shared title terminology · Xinlei Xiong, Wenbo Hu, Shuxun Zhou et al.
Turnout: Adaptive Attention Switching for Efficient Reasoning
Shared title terminology · Anna Kuzina, Mart van Baalen, Paul N. Whatmough et al.
Composable Soft-Prompt Distillation of RL Experts: Toward Continual Post-Training
Shared title terminology · Zhen Zhang, Changyi Yang, Xuehai He et al.
Structure Over Scale: Rethinking Adaptation for Reinforcement Learning with Verifiable Rewards
Shared title terminology · Allan Kazakov, Abdurrahman Javat