LLM guardrails are runtime controls that validate, filter, and constrain large language model inputs and outputs against security, safety, and compliance policies before responses reach users or trigger downstream actions. Unlike traditional software guardrails that enforce deterministic rules, LLM guardrails must handle the non-deterministic, probabilistic nature of generative AI—detecting prompt injections, toxic content, hallucinations, PII leaks, and jailbreak attempts in natural language. As of 2026, guardrails have shifted from an optional safety layer to production infrastructure essential for enterprise AI applications, driven by regulatory requirements (GDPR, HIPAA, EU AI Act), security imperatives (OWASP LLM Top 10), and business risk (brand damage, compliance violations). The key mental model: guardrails are defense-in-depth layers applied at input validation, model execution, output filtering, and retrieval—not a single checkpoint. Production systems typically combine 3–7 guardrail types in a layered architecture, trading off latency (5–150ms overhead) for risk reduction. Critical insight: no guardrail is perfect—prompt injection remains unsolved in 2026, and adversarial attacks evolve faster than defenses; effective safety requires treating guardrails as risk reduction layers, not hard security boundaries, backed by monitoring, red teaming, and incident response.
What This Cheat Sheet Covers
This topic spans 12 focused tables and 96 indexed concepts, 87 flashcards. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: Guardrail Rail Types and Execution Layers
Guardrails operate at distinct pipeline stages—input validation runs before the LLM sees the request, output filtering runs after generation, retrieval guardrails inspect external documents, and dialogue rails shape conversational flow. Each layer addresses different threat vectors: input rails block malicious prompts, output rails catch toxic or hallucinated responses, retrieval rails prevent vector database poisoning, and dialogue rails enforce conversation boundaries. The layered approach provides defense-in-depth: if prompt injection bypasses input filters, output validation may still catch the malicious result. Production systems typically deploy 3–5 rail types simultaneously—the tradeoff is latency (each layer adds 10–50ms) versus coverage. Most enterprises start with input PII and output toxicity filters (highest ROI), then add prompt injection detection, RAG validation, and topic guardrails based on risk assessment. Architecture matters: running rails in parallel reduces latency but misses cross-layer dependencies; sequential execution catches more threats but increases response time.
| Type | Example | Description | |
|---|---|---|---|
if detect_injection(user_msg): return "Blocked" | Run before the LLM sees the request — validate input syntax, detect prompt injections, redact PII, check topic boundaries, enforce content policies, and sanitize user queries to prevent manipulation or data leakage before inference. | ||
if toxic_score > 0.8: response = fallback_msg | Run after generation completes — filter toxic language, detect hallucinations, verify factual grounding, redact sensitive data, enforce structured schemas, and validate citation accuracy before the response reaches users or downstream systems. | ||
if relevance_score < 0.5: reject_document() | Validate external documents before context injection — check retrieval relevance, detect corpus poisoning, verify source trustworthiness, enforce context length limits, and prevent indirect prompt injection via RAG document manipulation. | ||
if off_topic(user_turn): redirect_to_scope() | Shape multi-turn conversation flow — enforce topic boundaries, manage state transitions, detect goal hijacking, limit conversation depth, prevent jailbreaks via multi-step exploits, and ensure the agent stays within its intended role across turns. | ||
if action == "delete_db": require_approval() | Control agent tool access and execution — enforce least-privilege permissions, validate function arguments, detect unauthorized API calls, sandbox code execution, rate-limit tool invocations, and prevent agents from performing destructive actions without human oversight. | ||
if latency > 5s: timeout_request() | Monitor system behavior during execution — detect infinite loops, enforce cost limits, track token budgets, measure latency spikes, identify anomalous request patterns, and trigger circuit breakers to prevent cascading failures or runaway costs. |