Skip to main content
ZICQ

Wiki Security

AI Guardrails

Security
Aliases: Guardrails Safety Guardrails Input/Output Filtering ·2026-11-18

AI Guardrails

AI guardrails are runtime control layers—combining deterministic rules, access checks, and specialized safety classifiers—placed around foundation model calls to validate, redact, or block inputs, retrieved context, tool invocations, and outputs. Because instructions written inside a system prompt are probabilistic nudges rather than hard security boundaries, production systems rely on independent guardrails in application code.

Defense Layers in an LLM Pipeline

User Input ──► [Input Rails: Injection/Jailbreak Scan · PII Redaction]
                    │
                    ▼
             [Retrieval Rails: ACL Filtering · Untrusted Text Isolation] ──► Primary LLM
                                                                                  │
                                                                                  ▼
Caller     ◄── [Output Rails: Policy Classifier · Schema Validation · Grounding]
                    ▲
                    │
             [Tool Rails: Parameter Allowlists · Sandboxing · Human Approval]
  1. Input Rails: Screen incoming requests for jailbreak or prompt injection patterns, enforce payload budgets, and redact credentials or PII before sending text to external model APIs.
  2. Retrieval Rails: Enforce document-level access controls (ACLs) inside RAG pipelines before context reaches the prompt, ensuring unauthorized records are never retrieved or leaked.
  3. Tool & Execution Rails: Validate tool call arguments against strict allowlists, confine code/shell calls inside sandboxes, and gate destructive or state-changing actions behind human-in-the-loop confirmation.
  4. Output Rails: Run lightweight safety classifiers (such as Llama Guard), verify schema conformance, and flag unsupported claims before returning responses to users or downstream automation.

Choosing Guardrail Mechanisms

Mechanism Latency & Cost Best Suited For Blind Spots
Regex / DLP / Schema Validators Sub-millisecond, deterministic Secret/token leaks, PII patterns, SQL/path restrictions, JSON type contracts Paraphrased intent, multilingual evasion, semantic policy violations
Compact Safety Classifiers (e.g., Llama Guard) Tens of milliseconds; self-hostable Standardized risk taxonomies (self-harm, cyber abuse, hate, toxicity) Domain-specific enterprise policies require custom fine-tuning
Secondary LLM Policy Judge High latency & token cost Nuanced compliance checks and groundedness verification against sources Vulnerable to long-context dilution and adversarial phrasing

Engineering Guidelines

  • Separate Syntax from Authorization: Schema validation confirms a JSON payload has the expected fields, not that the caller is authorized to mutate a database record. Enforce permissions deterministically in backend services.
  • Measure False Positives Alongside Recall: Overly broad keyword filters break legitimate coding, security research, and medical queries. Benchmark precision and false-positive rates on clean production samples and log structured trigger reasons.
  • Pair with Red-Teaming & Telemetry: Continuously probe rails through red-teaming and monitor trigger rates and latency overhead via observability pipelines.

Further Reading