Reproduce “kNNGuard: Turning LLM Hidden Activations into a Training-Free Configurable Guardrail” on OpenResearch

Run Claude Code, Codex or any coding agent as a research agent: literature, hypotheses and experiments on your laptop, cluster or cloud GPUs.

Universal app for Apple silicon and Intel. Requires macOS 11 or later.

About this paper

Mahmoud Abdelfattah, Hamid Nasiri, Peter Garraghan

kNNGuard classifies prompts as safe or unsafe without fine-tuning model weights. It compares each prompt with labeled examples using a frozen language model’s internal representations and sentence embeddings, then fuses the two neighbor-based risk scores. Across six domains, its fused version averaged 87.4% F1 and 12.9% false-positive rate, with 46.8 ms latency. These benchmark classifications do not demonstrate attack prevention.

Summary by alphaXiv.

Tip: change arxiv.org to autoarxiv.org in any arXiv abstract link to open the paper here.