kNNGuard classifies unsafe prompts without training, matching or beating fine-tuned guards
kNNGuard achieves competitive or superior F1 compared to fine-tuned guardrails
AI/ML arXiv 2 Jul 2026 Defense Prototype evidence
Published as “kNNGuard: Turning LLM Hidden Activations into a Training-Free Configurable Guardrail”
Why it matters
kNNGuard enables fast, low-latency safety filtering that can be retuned on-the-fly for new threat categories without costly fine-tuning.
Summary
kNNGuard FE attains the highest average F1 of 87.4% and the lowest overall false-positive rate of 12.9% while running at 45.9 ms per prompt, 2.7× faster than the best fine-tuned guardrail. It works without any model fine-tuning by leveraging multi-layer hidden activations of a frozen LLM and fusing them with sentence-embedding scores. Using only a 100-example reference bank, the guardrail can be built in 7.95 seconds, enabling rapid domain adaptation. The paper provides extensive evaluation across six domains, but it does not include an explicit limitations section.
What they found 2
- kNNGuard FE achieves the highest average F1 and lowest FPR among evaluated guardrails.
“kNNGuard FE achieves the highest average F1 score of 87.4% and the lowest overall FPR (12.9%) among all guardrails, operating at 45.9 ms per prompt, 2.7× faster than Llama Nemotron Topic Guard V1 and an order of magnitude faster than Nemotron Safety Guard V2.”
- A 100-sample reference bank can be constructed in under 8 seconds.
“the 100-sample bank (50 per class), which is the recommended sample number for kNNGuard, required 7.95 seconds to construct”
Caveats 1
- The No System Prompt variant achieves the lowest ASR on this domain (6.1%, a 20.1% reduction relative to kNNGuard FE) but at an FPR 64.9% higher
What’s new here 4
- Uses frozen LLM hidden activations as a non-parametric feature space for safety classification.
- Combines activation-space and embedding-space kNN with confidence-adaptive fusion.
- Achieves training-free guardrails that can be reconfigured in under 10 seconds.
- Provides a multi-layer Fisher-weighted ensemble to improve separability.