[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-0-en-105":3,"doc-seo-327419-105":59,"doc-detail-327419-en":131},{"code":4,"msg":5,"data":6},0,"success",[7,13,18,23,28,33,38,43,48,51,55],{"id":8,"doc_module":4,"doc_module_name":9,"category_name":10,"show_sort_weight":11,"slug":12},1,"Document","Story & Novel",90,"story-novel",{"id":14,"doc_module":4,"doc_module_name":9,"category_name":15,"show_sort_weight":16,"slug":17},2,"Literature",80,"literature",{"id":19,"doc_module":4,"doc_module_name":9,"category_name":20,"show_sort_weight":21,"slug":22},4,"Exam",70,"exam",{"id":24,"doc_module":4,"doc_module_name":9,"category_name":25,"show_sort_weight":26,"slug":27},5,"Comic",60,"comic",{"id":29,"doc_module":4,"doc_module_name":9,"category_name":30,"show_sort_weight":31,"slug":32},6,"Technology",50,"technology",{"id":34,"doc_module":4,"doc_module_name":9,"category_name":35,"show_sort_weight":36,"slug":37},7,"Healthcare",40,"healthcare",{"id":39,"doc_module":4,"doc_module_name":9,"category_name":40,"show_sort_weight":41,"slug":42},8,"Research & Report",30,"research-report",{"id":44,"doc_module":4,"doc_module_name":9,"category_name":45,"show_sort_weight":46,"slug":47},9,"Religion & Spirituality",20,"religion-spirituality",{"id":46,"doc_module":4,"doc_module_name":9,"category_name":49,"show_sort_weight":46,"slug":50},"World Cup","world-cup",{"id":52,"doc_module":4,"doc_module_name":9,"category_name":53,"show_sort_weight":52,"slug":54},10,"Lifestyle","lifestyle",{"id":56,"doc_module":4,"doc_module_name":9,"category_name":57,"show_sort_weight":24,"slug":58},19,"General","general",{"code":4,"msg":60,"data":61},"ok",{"site_id":62,"language":63,"slug":64,"title":65,"keywords":66,"description":67,"schema_data":68,"social_meta":124,"head_meta":126,"extra_data":128,"updated_unix":130},105,"en","knnguard-turning-llm-hidden-activations-into-a-training-free-configurable-guardrail","kNNGuard: Turning LLM Hidden Activations into a Training-Free Configurable Guardrail","","Large language models (LLMs) are increasingly deployed in settings that require guardrails to detect unsafe, off-topic, or adversarial prompts. Existing guardrail systems often depend on fine-tuning classifiers, which can generalize poorly and add significant inference latency. kNNGuard introduces a training-free approach that reuses hidden activation spaces from a frozen LLM. Using a small bank of labeled safe and unsafe prompts, it extracts activations and applies multi-layer kNN fusing scores across activation-space and embedding-space. Experiments across six topical and security domains show competitive or better F1, with 2.7× lower latency than comparable guardrails and up to 10× faster than fine-tuned safety classifiers. It supports fast domain adaptation by updating only the labeled bank, and includes analysis of system prompts, layer selection, and production pipeline integration.",{"@graph":69,"@context":123},[70,84,106],{"@type":71,"itemListElement":72},"BreadcrumbList",[73,77,79,82],{"item":74,"name":75,"@type":76,"position":8},"https://docshare.wps.com","Home","ListItem",{"item":78,"name":9,"@type":76,"position":14},"https://docshare.wps.com/document/",{"item":80,"name":30,"@type":76,"position":81},"https://docshare.wps.com/document/technology/",3,{"item":83,"name":65,"@type":76,"position":19},"https://docshare.wps.com/document/knnguard-turning-llm-hidden-activations-into-a-training-free-configurable-guardrail/327419/",{"url":83,"name":65,"@type":85,"image":86,"author":91,"headline":65,"publisher":94,"fileFormat":97,"inLanguage":63,"description":67,"dateModified":98,"datePublished":99,"encodingFormat":97,"isAccessibleForFree":100,"interactionStatistic":101},"DigitalDocument",{"url":87,"@type":88,"width":89,"height":90},"https://docshare.wps.com/thumbnails/knnguard-turning-llm-hidden-activations-into-a-training-free-configurable-guardrail/327419.png","ImageObject",300,407,{"name":92,"@type":93},"Eliana","Person",{"url":74,"name":95,"@type":96},"DocShare","Organization","application/pdf","2026-11-25","2026-09-21",true,{"@type":102,"interactionType":103,"userInteractionCount":105},"InteractionCounter",{"@type":104},"ViewAction",12,{"@type":107,"mainEntity":108},"FAQPage",[109,115,119],{"name":110,"@type":111,"acceptedAnswer":112},"What problem does kNNGuard address in LLM deployments?","Question",{"text":113,"@type":114},"kNNGuard targets the need for guardrails that can detect unsafe, off-topic, and adversarial prompts such as jailbreaks and prompt injection attempts in real applications.","Answer",{"name":116,"@type":111,"acceptedAnswer":117},"How does kNNGuard work without training a classifier?",{"text":118,"@type":114},"It reuses a frozen LLM as a feature extractor: it caches hidden activations from a small labeled bank of safe and unsafe prompts, then compares incoming prompts via multi-layer kNN in activation space with layer-weighted scoring.",{"name":120,"@type":111,"acceptedAnswer":121},"What performance gains does kNNGuard report compared with fine-tuned guardrails?",{"text":122,"@type":114},"Across six domains, kNNGuard reports competitive or superior F1 while running 2.7× faster than the best comparable guardrail and up to 10× faster than a fine-tuned safety classifier, without gradient updates or fine-tuning.","https://schema.org",{"og:url":83,"og:type":125,"og:title":65,"og:site_name":95,"og:description":67},"article",{"robots":127,"canonical":83},"index,follow",{"doc_id":129,"site_id":62},327419,1790552315,{"code":4,"msg":5,"data":132},{"doc_id":129,"user_id":133,"nickname":92,"user_avatar":134,"doc_module":4,"category_id":29,"category_name":30,"doc_title":65,"doc_description":67,"doc_content":135,"file_id":136,"file_url":137,"file_type":138,"file_size":139,"view_count":105,"is_deleted":4,"is_public":8,"is_downloadable":8,"audit_status":8,"page_count":140,"language":141,"language_code":63,"site_id":62,"html_lang":63,"table_of_contents":142,"faqs":143,"seo_title":144,"seo_description":67,"update_tm":145,"read_time":146,"preview_page_count":19,"preview_urls":147},4398048949847,"https://ap-avatar.wpscdn.com/avatar/400002536579ef2da7f?_k=1778318612642679267","kNNGuard: Turning LLM Hidden Activations into a Training-Free  \nConfigurable Guardrail  \nMahmoud Abdelfattah1 , Hamid Nasiri1 , Peter Garraghan1,2  \n1Lancaster University, 2Mindgard  \n{m.abdelfattah1, [h.nasiri}@lancs.ac.uk](h.nasiri}@lancs.ac.uk), [peter@mindgard.ai](peter@mindgard.ai)  \narXiv :2607 .02072v2 [ cs .LG] 6 Jul 2026  \nAbstract  \nLarge 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.  \nAcross six domains spanning topical and security prompts, kNNGuard achieves competitive or superior F1 compared to fine-tuned stateof-the-art guardrails while running 2.7 × faster than the best comparable guardrail, and 10× 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.  \nKeywords: LLM Guardrails, Prompt Injection, Jailbreak Detection  \n1 Introduction  \nLarge language models (LLMs) are increasingly being integrated into critical applications, from code assistants in software engineering pipelines to internal enterprise copilots and domain-specific customer service chat-bots. In these settings, it isnot sufficient for an LLM to be only capable; it must also resist a growing class of mis-aligned and, more importantly, adversarial prompts including jailbreaks, prompt injection, and evasion attacks  \nthat can lead to models leaking sensitive information, executing harmful instructions, or circumventing organizational security policies (Pathade, 2025) . In response to this, researchers and practitioners have created guardrail systems to detect and block unsafe or out-of-domain prompts, which are a necessity as the attack diversity and sophistication grows (Rebedea et al., 2025) .  \nExisting guardrail approaches can be categorized into two main categories. The first are dedicated classifier models that are fine-tuned on large, curated datasets to recognize harmful content, sensitive topics, or policy violations (Rebedea et al., 2024) . These systems can achieve strong accuracy, however require fine-tuning on curated training data, rely on custom classifiers specialized to specific domains, and incur additional inference latency (Chua et al., 2024) . The second category are lightweight similarity-based methods such as embedding k-nearest neighbors (kNN), whereby user prompts are embedded using a sentence encoder or embedding model (Wang et al., 2020) and compared against a small bank of labeled safe and unsafe examples. While such an approach exhibitslow guardrail latency, it suffers from high falsepositive rates as well as struggles with nuanced safety, security, and topic distinctions from outof-distribution attacks and subtle prompt injection (Chua et al., 2024) .  \nRecent works have highlighted that many widely deployed guardrails are vulnerable to evasion, even when they appear robust on static benchmarks (Hackett et al., 2025) . Simple character-level perturbations, paraphrasing attacks, and algorithmically generated adversarial prompts can bypass popular guardrail systems, achieving high attack success rates while retaining the original prompt’s malicious intent. These findings indicate that guardrails that are heavily dependent on their training distribution are ","cbCaimDMwyUkI7FG","https://ap.wps.com/l/cbCaimDMwyUkI7FG","pdf",695505,17,"English","# Introduction\n## Guardrails need: unsafe and adversarial prompts\n## Two existing approaches: fine-tuned classifiers vs similarity methods\n## Evasion and distribution shift vulnerabilities\n# kNNGuard framework\n## Training-free activation caching\n## Multi-layer kNN with Fisher-discriminant weighting\n## Adaptive fusion with embeddings\n# Evaluation and contributions\n## Domains tested and key performance metrics","[{\"question\":\"What problem does kNNGuard address in LLM deployments?\",\"answer\":\"kNNGuard targets the need for guardrails that can detect unsafe, off-topic, and adversarial prompts such as jailbreaks and prompt injection attempts in real applications.\"},{\"question\":\"How does kNNGuard work without training a classifier?\",\"answer\":\"It reuses a frozen LLM as a feature extractor: it caches hidden activations from a small labeled bank of safe and unsafe prompts, then compares incoming prompts via multi-layer kNN in activation space with layer-weighted scoring.\"},{\"question\":\"What performance gains does kNNGuard report compared with fine-tuned guardrails?\",\"answer\":\"Across six domains, kNNGuard reports competitive or superior F1 while running 2.7× faster than the best comparable guardrail and up to 10× faster than a fine-tuned safety classifier, without gradient updates or fine-tuning.\"}]","kNNGuard: Turning LLM Hidden Activations into a Training-Free Configurable Guardrail | PDF",1789977161,43,[148,152,156,160],{"page_no":8,"url":149,"width":150,"height":151},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-16/d32513720008608d57a7c1fafeed8c94.webp",983,1390,{"page_no":14,"url":153,"width":154,"height":155},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-16/663861136ba3c38b99029ae6d5e2f281.webp",982,1388,{"page_no":81,"url":157,"width":158,"height":159},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-16/7dce6d175d2fb6d44d5b68f6d3a79104.webp",981,1387,{"page_no":19,"url":161,"width":162,"height":163},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-16/e9bf192ca170466bbc4dc1264b032dd0.webp",980,1385]