Injection and guardrails, 4 of 5, about 6 h 15 min of reading
Guardrails & Semantic Firewalls
About 5 h 59 min left
Concept. A guardrail is the layer that inspects what goes into and comes out of a model. It filters prompts, masks personally identifiable information (PII), blocks off-topic or malicious content, and scans tool traffic. The attack weeks break models; this week teaches you to wrap them. The hard lesson of 2026 is that a guardrail is a layer and never the boundary. Two independent results now prove that a static filter can always be bypassed and can itself be attacked, and a third shows that the model's own refusal training can be surgically removed. Defense has to be external, layered and continuously monitored. A filter you install once and forget does not meet that bar.
🎯 Objectives
By the end of this unit you can:
- Explain the two proven structural failure modes of guardrails, bypass (the NIST result built on Gödel's theorems) and availability (reasoning denial of service), and why a better filter fixes neither.
- Build a real NeMo Guardrails and Colang 2.0 rail stack (input, output, dialog, retrieval and execution rails) and measure its bypass rate with your Prompt Hacking MasterclassInjection and guardrails, 1 of 5, about 7.8 h–10 attacks.
- Compare the 2026 guardrail toolchain (NeMo, Lakera, SingGuard-NSFA, Opir, Rebuff and guardrails-ai) on latency and detection, and say where each fits.
- Apply the Tool Input/Output Firewall pattern (a Minimizer and a Sanitizer) to block indirect prompt injection at the agent-tool boundary.
- Explain why open-weight model safety is cosmetic (Heretic abliteration) and design defenses that survive weight-level tampering.
- (Go deeper) Run the attacks the guardrail stack answers (character smuggling against an input classifier, a cascade against the Sanitizer, and gaps in a tool-call policy), then write that policy as code in Rego or Cedar so each gap ends in deny (arXiv 2504.11168 and Cedar).
The big picture: a guardrail is one layer, not the wall
Guardrails come in two shapes. Content filters (Lakera, Llama Guard, OpenAI Moderation) classify a single message as safe or unsafe. Programmable rails (NeMo Guardrails) wrap the whole conversation in deterministic flows. Both are useful and both are incomplete. The 2026 research converges on one design rule, and you should internalize it before you deploy anything:
🔑 Design rule. Treat a guardrail as one defense-in-depth layer with monitoring and per-tenant isolation, and never as the security boundary. A guardrail in front of a shared fleet can be bypassed and can also amplify a denial of service (DoS). Layer it with input firewalls, output scanning and sandbox confinement, and assume it will eventually fail.
Failure mode 1: bypass is mathematically guaranteed
NIST's Apostol Vassilev applies Gödel's incompleteness theorems to guardrails. No finite, consistent axiom system can be complete, and in the same way no finite guardrail set can be "universally robust against adversarial prompts." For any fixed ruleset some prompt defeats it, and patching that gap only opens the next one (NIST). Stacking scanners does not escape this. Hackett and Garraghan's BRANCH runs a tree search against a multi-scanner guardrail (LLM Guard, LlamaFirewall and Guardrails AI among the six they tested), perturbing the prompt for each scanner and keeping the changes that lower the blocking confidence summed across all of them. It found a bypass in all 120 scenarios, and the bypasses also raised attack success against guardrails it never optimized on, commercial black-box guardrails among them (arXiv 2610.10742). The search climbs on each scanner's confidence score, and the authors expect it to work less well where scores are hidden, so return only the decision to callers, and do not count on that alone: the bypasses still transferred to commercial black-box guardrails. The paper's title says it plainly: "Robust AI Security and Alignment: A Sisyphean Endeavor?" The practical consequence is a shift in security model, and it is no reason for despair. Stop chasing impenetrability, and aim for an economic equilibrium where exploitation costs more than it is worth. The right posture is a continuous loop with three parts:
- Red-team: hunt for undiscovered bypasses before attackers do.
- Monitor and update: harden against newly found gaps as they surface.
- Recover: prioritize damage limitation and fast recovery when a bypass lands.
Failure mode 2: the shield becomes the target
Reasoning-based guardrails introduced a new attack surface: their own reasoning. The paper From Shield to Target uses beam-search-optimized natural-language payloads (plus schema-aware structural mutations) to trap a reasoning guardrail in extended loops (arXiv 2606.14517). The measured damage is severe and portable:
- Token use grows 13–63× across backbones.
- End-to-end latency grows by up to 148× in real deployments.
- Payloads optimized on one surrogate transfer to 8 leading backbones (Claude, GPT, Gemini, DeepSeek and Qwen).
- A single poisoned document can saturate a shared guardrail and starve every co-located agent, which is a resource-exhaustion DoS that cascades to the whole system.
This lesson builds on failure mode 1. If a guardrail can be dodged and also weaponized for denial of service, then a shared reasoning guardrail in front of a multi-tenant fleet is the worst place to concentrate trust. Isolate it per tenant. Do not expect a cap on the guardrail's reasoning budget to close the hole either: the authors find that a hard token budget only shifts the failure mode, because failing open on a truncated verdict lets unreviewed actions through and failing closed blocks legitimate ones (arXiv 2606.14517).
Fail open
untrusted The looping payload uses up the guardrail's token budget. The verdict is truncated, so the action goes through. The attacker has turned a denial of service into a bypass.
Fail closed
The looping payload uses up the guardrail's token budget. The verdict is truncated, so the action is blocked. Legitimate requests are blocked the same way, so the attack is still a denial of service.
A hard budget only moves the failure from one side to the other, so isolate a reasoning guardrail per tenant and never make it the security boundary.
The 2026 guardrail toolchain
Enforcing at the agent boundary
Model-internal safety is cosmetic: the Heretic problem
🧪 Build it and try to break it
🛡️ OWASP 2026: Misinformation and Improper Output Handling
Go deeper: attacking the guardrail stack
✅ Check yourself
📇 Guardrail and tooling reference
Finish Guardrails & Semantic Firewalls
About 5 h 59 min left in this unit.
From memory first
Write the main points of this unit, in your own words.
What you set out to be able to do
Check each one against what you can do now.
- Explain the two proven structural failure modes of guardrails, bypass (the NIST result built on Gödel's theorems) and availability (reasoning denial of service), and why a better filter fixes neither.
- Build a real NeMo Guardrails and Colang 2.0 rail stack (input, output, dialog, retrieval and execution rails) and measure its bypass rate with your Prompt Hacking MasterclassInjection and guardrails, 1 of 5, about 7.8 h–10 attacks.
- Compare the 2026 guardrail toolchain (NeMo, Lakera, SingGuard-NSFA, Opir, Rebuff and guardrails-ai) on latency and detection, and say where each fits.
- Apply the Tool Input/Output Firewall pattern (a Minimizer and a Sanitizer) to block indirect prompt injection at the agent-tool boundary.
- Explain why open-weight model safety is cosmetic (Heretic abliteration) and design defenses that survive weight-level tampering.
- (Go deeper) Run the attacks the guardrail stack answers (character smuggling against an input classifier, a cascade against the Sanitizer, and gaps in a tool-call policy), then write that policy as code in Rego or Cedar so each gap ends in deny (arXiv 2504.11168 and Cedar).
The unit is done when you have answered the check and marked the required sources.
1 Check yourself
Do the check2 Required sources
Go to the sources
Sources in this unit
- NIST: Mathematical Proof Supports Transition to Continuous-Monitor-and-Update Security for AI
- From Shield to Target: DoS Attacks on LLM-Based Agent Guardrails (arXiv 2606.14517)
- NeMo Guardrails: Colang 2.0 Getting Started
- Tool Input/Output Firewall (arXiv 2510.05244)
- AI Thinker Lab: Heretic Abliteration Benchmarks 2026
- Spracklen et al.: "We Have a Package for You!" Package Hallucinations by Code-Generating LLMs (USENIX Security 2025)
- Lakera Guard Documentation
- Domain Generalizable AI Guardrails with Augmented Policy Training (ACL 2026)
- Unit 42: Comparing LLM Guardrails Across GenAI Platforms
- Microsoft Agent Governance Toolkit
- pipelock
- Heretic GitHub
- autoguardrails
- OWASP GenAI: Top 10 for LLM Applications
- NVIDIA SkillSpector
- hol-guard
- SingGuard-NSFA: agentic-AI guardrail framework (inclusionAI / Ant)
- agentshield
- OWASP AI Security Solutions Landscape Q2 2026
- Opir-multitask-large-v1.0 (Knowledgator)
- Rebuff: LLM Prompt Injection Detector
- guardrails-ai/guardrails
- TechCrunch: How AI Guardrails Are Impeding Offensive Cybersecurity Researchers (Jul 23, 2026)
- Canary Tokens for RAG
- Lenny's Podcast: Why Securing AI is Harder Than Anyone Expected (HackAPrompt CEO)
- Qwen3.8-27B-OBLITERATED (complementary abliteration)
- Qwen3.8-27B Uncensored Cyber (GGUF)
- BRANCH: Bypassing Multi-Scanner AI Guardrails (arXiv 2610.10742)
Checklist
It does not count toward done.
- Explain the two proven guardrail failure modes in your own words: bypass (NIST's Gödel-incompleteness result) and availability (reasoning denial of service, 13–63× tokens and 148× latency, arXiv 2606.14517).
- Write the design rule as one sentence: a guardrail is one monitored layer with per-tenant isolation, never the boundary.
- Build a NeMo Guardrails and Colang 2.0 stack with a PII-masking output rail, a topic-boundary input rail and a prompt-injection rail, and confirm each rail fires on a test message.
- Measure the bypass rate with your Prompt Hacking MasterclassInjection and guardrails, 1 of 5, about 7.8 h–10 attacks, and run Garak with and without NeMo to record the detection difference.
- Compare NeMo, Lakera, SingGuard-NSFA, Opir, Rebuff and guardrails-ai on latency, detection and deployment model in one table.
- Configure Lakera Guard for real-time detection of prompt injection (PI) and jailbreaks, and capture one blocked request.
- Implement the Tool Input/Output Firewall (a Minimizer and a Sanitizer) from arXiv 2510.05244 at the agent-tool boundary, and show a tool result with the injected instruction removed.
- Study Heretic directional ablation, then test whether an abliterated model bypasses your external rails. If your defense collapses, it depended on model-internal safety that can be removed.
- Plant canary tokens in the RAG vector store and show that one surfacing in an answer raises your exfiltration alert.
- Evaluate two agent scanners, SkillSpector (development time) and hol-guard (runtime), and review the OWASP AI Security Solutions Landscape Q2 2026 for tools you missed.
- Apply structural enforcement instead of prompt-level rules: use the Microsoft Agent Governance Toolkit for deterministic policy before the wire, and pipelock for capability separation (the agent has secrets, the firewall has the network).
- Run the NIST monitor-and-update loop with autoguardrails: let it tune policy.md to lower the attack success rate (ASR) under a benign-pass floor, and watch it roll back a regression.
- Scan your own Claude Code configuration with agentshield (102 rules, A–F grade) and record the grade. Rebuff is archived, so do not deploy it.
- Write down the dual-use tension: inconsistent refusals and vetted access (Mythos 5 and Fable 5) will shape which offensive tools you can use.
- Summarize the 2026 collapse in abliteration cost in three sentences: a complementary-blend Qwen (OBLITERATUS) reaches near-zero refusal at about 2 points of MMLU, and a downloadable Uncensored-Cyber model (more than 13,000 a month) shows that external rails are the only control that survives weights leaving your custody.
The guard that passed its test, measured again
Attack: Find the adaptive bypass that beats a guardrail that passed its first measurement Defend: Measure block rate and false alarms on unseen inputs, not on the practice set
Nothing to do here yet; the unit is complete without it.
Practise this in the lab, Make a filter read what the model will read.40 to 55 min estimate
Practise this in the lab, Capstone: one engagement, replayable findings and a scope log.1 h 40 min estimate
Study notes
None yet
Sign in to take notes.
Your additions
None yet
More for this unit
21 readings
Readings no section cites. They do not count toward the unit.
Further reading21 readings
- docs.lakera.aitool
Lakera Guard is a hosted content classifier with latency under 30ms and support for more than 100 languages. It detects prompt injection (PI), jailbreaks and data leakage. Read it to see the fast single-message layer you compare NeMo against.
Sign in to mark it done, keep it for later and open its questions.
- aclanthology.orgpaper
Liu, Baldini, Rabinowitz, Rosenberg, Gehrmann and Dredze (Bloomberg) compare Llama-Guard-3-1B/8B, Granite-Guardian-8B and ShieldGemma-2B/9B with their instruct bases on Aegis 2.0 and AILuminate (seen, MLCommons), Do-Not-Answer (mixed) and FinancialRisk (unseen). Guardrails overfit the training policy, generally lose to their bases on unseen policies and favor precision over recall. Augmented Policy Training (category deletion and guideline editing) lifts a Llama-3.2-1B to 0.83 F1 on FinancialRisk, level with Granite-Guardian-8B. Read it for the benchmark to run on your own policy before you pick a classifier.
Sign in to mark it done, keep it for later and open its questions.
- unit42.paloaltonetworks.compaper
Unit 42 benchmarks hosted platforms on detection against false-positive rate (about 92% detection at 13.1% false positives, against about 91% at 0.6%). Output filters rarely catch harmful content, because model alignment does the work. Read it to learn how to tune for your false-positive tolerance.
Sign in to mark it done, keep it for later and open its questions.
- github.comtool
Deterministic policy (YAML, OPA or Cedar) applied before the request reaches the wire, SPIFFE, DID and mTLS identity, four privilege rings and a kill-switch. Its thesis is that "prompt-level safety is not a control surface," and it covers all 10 OWASP agentic risks (ASI) with 992 conformance tests (about 5.8K stars). Read it for what structural enforcement looks like in code.
Sign in to mark it done, keep it for later and open its questions.
- github.comtool
A verifiable-egress agent firewall built on capability separation: the agent has secrets and the firewall has the network. It scans for data-loss patterns (65), prompt injection patterns (33), SSRF, DNS tunnelling and MCP poisoning, and it signs action receipts. The license is Apache-2.0. Read it to see capability separation applied to the network.
Sign in to mark it done, keep it for later and open its questions.
- github.comtool
The source is AGPL v3.0. Its TPE/Optuna optimizer minimizes refusals and KL divergence together, using float-interpolated directions and component-specific weights, and v1.2.0 (February 2026) can emit LoRA adapters. Read it when you want to see how the abliteration works before you run it.
Sign in to mark it done, keep it for later and open its questions.
- github.comlab
alignment-research scaffold that auto-tunes a single mutable policy.md to minimize attack success rate against a frozen eval suite with a benign-pass floor and auto-rollback on regression; stdlib-only, offline stub mode
Sign in to mark it done, keep it for later and open its questions.
- genai.owasp.orgpaper
The primary source for LLM07 Misinformation (Claim-Check-Act, ground-before-action, groundedness and consistency signals, omission detection, cross-agent propagation, forged evidence) and LLM10 Improper Output Handling (model output is untrusted until validated in trusted code; parameterized queries, context-aware encoding, control-character sanitization, disabled auto-rendering). Read both entries before the OWASP section of the chapter.
Sign in to mark it done, keep it for later and open its questions.
- github.comtool
A development-time security scanner for AI agent skills (Claude Code, Codex, Gemini CLI) with 64 vulnerability patterns in 16 categories. Its research found 26.1% of skills vulnerable and 5.2% with malicious intent. Run it on a skill before you install the skill.
Sign in to mark it done, keep it for later and open its questions.
- github.comtool
An "AI antivirus" for more than 12 agents (Claude Code, Cursor, Codex, MCP) that intercepts tool actions before they run. It has four levels from Gentle to Paranoid, a local receipts dashboard and an Apache-2.0 license. Read it as the runtime counterpart to a development-time scanner.
Sign in to mark it done, keep it for later and open its questions.
- github.comtool
It targets operational agent threats, not just single-turn prompt injection, across 7 threat domains and 185 risk variants. Its Qwen3.5 classifiers range from 0.8B to 9B parameters, with generative and real-time modes (45–57ms, F1 above 94% on multilingual sets). Evaluate it as a self-hosted fast pre-filter for an agent.
Sign in to mark it done, keep it for later and open its questions.
- github.comtool
A Claude Code configuration auditor with 102 rules in 5 categories (hooks 34, MCP 23, config 25, secrets, permissions), an A to F grade and a 0 to 100 score, auto-fix and SARIF output. It ships as a CLI and a GitHub Action. Run it on your own configuration.
Sign in to mark it done, keep it for later and open its questions.
- genai.owasp.orgtool
A comprehensive vendor and tool map for red teaming. Use it to find tools beyond the ones in this week.
Sign in to mark it done, keep it for later and open its questions.
- huggingface.cotool
A DeBERTaV3-large GLiClass encoder (candidate labels supplied at inference) that covers binary safety, jailbreak and prompt injection, and toxicity, with a hierarchical taxonomy of 16/126/854 labels. It has 0.4B parameters, runs in about 25ms, scores 0.80 macro-F1 across 12 sets, ranks second on binary safety and runs 4× faster than Nemotron. Try it as a small classifier for the comparison task.
Sign in to mark it done, keep it for later and open its questions.
- github.comtool
ProtectAI's four-tier detector combines heuristics, an LLM, a vector database and canary tokens, and hardens itself over time. It was archived in May 2025, so read it for reference only; it is unmaintained and you should not deploy it.
Sign in to mark it done, keep it for later and open its questions.
- github.comtool
Input and output Guards built from composable validators (the Guardrails Hub), with on-fail actions that run before destructive operations. Its Guardrails Index benchmarks 24 guardrails in 6 categories, and the project has about 7K stars. Read it to see hard pass or fail validators in practice.
Sign in to mark it done, keep it for later and open its questions.
- techcrunch.compaper
NCC Group's Chris Anley explains the dual-use core: the same guardrail that blocks an attacker blocks the defender. Inconsistent refusals and vetted access (Mythos 5 and Fable 5) shape which offensive tools you can use, so read it before you plan your own tooling.
Sign in to mark it done, keep it for later and open its questions.
- canarytokens.orgpaper
A low-cost detection layer. If a planted canary surfaces in an output, it confirms unauthorized retrieval. Read it before you plant canaries in a vector store.
Sign in to mark it done, keep it for later and open its questions.
- youtube.comvideo
Sander Schulhoff explains why guardrails fail, which attack patterns are real and what actually works. Listen to it after the failure-mode papers.
Sign in to mark it done, keep it for later and open its questions.
- huggingface.cotool
refusal removed by blending two weight-surgery methods (aggressive SVD + LEACE) whose failures cancel out: 0.24% refusal (2/842) at 84.32% MMLU (−0.28pp of stock) — the strongest recent data point that abliteration now costs almost no capability, extending the Heretic "safety is cosmetic" thesis
Sign in to mark it done, keep it for later and open its questions.
- huggingface.cotool
a fine-tuned, safety-stripped 27B "tuned to fully answer cyber and offensive-security questions," locally deployable via llama.cpp/vLLM/Ollama — concrete proof that a decensored offensive model is one download away, not just a lab curiosity
Sign in to mark it done, keep it for later and open its questions.
This unit's library holds 50 more readings for readers with access.