kNNGuard: Turning LLM Hidden Activations into a Training-Free Configurable Guardrail
On the map: LLM safety and security → Safety alignment, refusal and guardrails
Abstract (arXiv)
Large language models (LLMs) are increasingly deployed in domains requiring guardrails to detect unsafe, off-topic, or adversarial prompts. Existing guardrails predominantly rely on fine-tuning to build classifiers, which often suffer from low generalization and high inference latency. We present kNNGuard, a training-free guardrail that utilizes the activation space of an off-the-shelf LLM. Given a small bank of 50 safe and unsafe prompts, kNNGuard extracts hidden activations and performs multi-layer kNN fusing activation-space and embedding-space scores for classification. Across six domains spanning topical and security prompts, kNNGuard achieves competitive or superior F1 compared to fine-tuned state-of-the-art guardrails while running 2.7x faster than the best comparable guardrail, and 10x faster than a fine-tuned safety classifier without gradient updates or fine-tuning. Domain adaptation requires only updating the labeled bank, which can be constructed in under 10 seconds and several orders of magnitude faster than established guardrails. We also analyze the impact of system prompts, layer selection, and integration into production LLM pipelines as a configurable, low-latency guardrail.
Key facts. No citing papers in the map yet (data through 7 Oct 2026). Placed in Safety alignment, refusal and guardrails, one of 12 directions in LLM safety and security. Builds on 17 of its 33 references that are in the map. First posted on arXiv 2 Jul 2026.
Builds on
17 of 33 references.
Closest ancestors · 7
Same direction, newest first
- 2026Enhancing Safety of Large Language Models via Embedding Space Separation1 Mar
- 2025The Structural Safety Generalization Problem13 Apr
- 2025SafeSwitch: Steering Unsafe LLM Behavior via Internal Activation Signals3 Feb
- 2025Aegis2.0: A Diverse AI Safety Dataset and Risks Taxonomy for Alignment of LLM Guardrails15 Jan
- 2024A Flexible Large Language Models Guardrail Development Methodology Applied to Off-Topic Prompt Detection20 Nov
- 2024WildGuard: Open One-Stop Moderation Tools for Safety Risks, Jailbreaks, and Refusals of LLMs26 Jun
- 2024Refusal in Language Models Is Mediated by a Single Direction17 Jun
Other references · 10
- 2024The Llama 3 Herd of Modelscited by 14,192
- 2021Program Synthesis with Large Language Modelscited by 3,509
- 2024Phi-3 Technical Report: A Highly Capable Language Model Locally on Your Phonecited by 1,883
- 2020MiniLM: Deep Self-Attention Distillation for Task-Agnostic Compression of Pre-Trained Transformerscited by 1,414
- 2023ChatDoctor: A Medical Chat Model Fine-Tuned on a Large Language Model Meta-AI (LLaMA) Using Medical Domain Knowledgecited by 324
- 2025The Attacker Moves Second: Stronger Adaptive Attacks Bypass Defenses Against Llm Jailbreaks and Prompt Injectionscited by 108
- 2025Red Teaming the Mind of the Machine: A Systematic Evaluation of Prompt Injection and Jailbreak Vulnerabilities in LLMscited by 34
- 2025Bypassing LLM Guardrails: An Empirical Analysis of Evasion Attacks against Prompt Injection and Jailbreak Detection Systemscited by 24
- 2024CantTalkAboutThis: Aligning Language Models to Stay on Topic in Dialoguescited by 15
- 2024PromptSet: A Programmer's Prompting Datasetcited by 9
Built on by
Not cited yet.