32.1 Guardrail Types
1. Input Guardrails
- Validate incoming requests/alerts are genuine (not injection attempts)
- Sanitize user input before it reaches the LLM
- Rate-limit agent activations to prevent cascading automation
2. Output Guardrails
- Validate LLM output against expected schemas
- Block dangerous commands via pattern match (
DROP TABLE,rm -rf,kubectl delete namespace, etc.) - Verify every proposed action against a whitelist of allowed operations
- Detect and redact sensitive data (PII/PHI) before it leaves the system
3. Process Guardrails
- Maximum action count per task (prevents infinite loops)
- Time-based limits (agent halts after N minutes without resolution)
- Budget limits (max API/token cost, max compute)
- Blast-radius limits (agent cannot affect more than N services/records)
4. Semantic Guardrails
- LLM-based review of the agent’s own proposed action for safety (“critic” pass)
- Domain-specific hard rules (e.g., “never scale below 2 replicas”, “never approve a claim above $X without human sign-off”)
- Compliance checks (data residency, access control, regulatory constraints)
32.2 Safety Layers Pipeline
Agent Proposed Action
│
▼
┌──────────────────┐
│ Schema Validation │ ─── Reject if output format is wrong
└────────┬─────────┘
▼
┌──────────────────┐
│ Command Blocklist │ ─── Reject if it matches a dangerous pattern
└────────┬─────────┘
▼
┌──────────────────┐
│ Scope Validation │ ─── Reject if it exceeds blast-radius limits
└────────┬─────────┘
▼
┌──────────────────┐
│ Risk Assessment │ ─── Route to approval if risk is medium/high
└────────┬─────────┘
▼
┌──────────────────┐
│ Dry Run (if │ ─── Execute in simulation mode first
│ applicable) │
└────────┬─────────┘
▼
Execute Action
┌────────────────────┐
│ Post-Execution │ ─── Monitor health, auto-rollback on regression
│ Monitoring │
└────────────────────┘
32.3 Production Guardrails Checklist
Input: rate limiting per user/session · input length limits · prompt-injection detection · content-safety screening
Process: maximum iteration count · token/cost budget per task · time limits per step and in total · blast-radius limits
Output: PII/PHI detection and redaction · factuality checking against sources · format validation · toxicity/harm detection
Action: explicit action allowlist · per-action parameter validation · dry-run before execution where possible · automatic rollback on failure
32.4 Defense-in-Depth for Production Actions
Layer 1 — Principle of Least Privilege: agent service accounts default to read-only; write access is granted per-action via short-lived tokens; permission scope tightens from dev → staging → production.
Layer 2 — Action Allowlisting: an explicit, versioned allowlist of actions the agent can take, each with name, allowed parameters, required approvals, and blast-radius limit. Unknown actions are always rejected — never default-allow.
Layer 3 — Pre-Execution Validation: parse the proposed action into a structured format; validate against a rules engine (is the target in scope? is the action type allowed? are parameters within acceptable range?); dry-run when the underlying system supports it (e.g., kubectl apply --dry-run=server).
Layer 4 — Human-in-the-Loop: all production-mutating actions require human approval, with the proposed action, justification, risk assessment, and rollback plan all shown; timeout auto-escalates.
Layer 5 — Post-Execution Monitoring: monitor affected systems after execution; auto-rollback if health checks fail within a defined window (e.g., 5 minutes); alert a human if unexpected side effects appear.
Layer 6 — Audit & Learning: log every action with timestamp, agent reasoning, approval chain, and outcome; regularly review agent actions for safety improvements; feed human corrections back as training signal for prompts/guardrails.
Section 32 — Interview Q&A
Q1: How do you prevent an agent from taking a genuinely harmful action in production, end to end? Defense-in-depth across six layers: least-privilege service accounts, an explicit action allowlist (reject-by-default), pre-execution schema/business-rule validation with dry-run where possible, mandatory human approval for anything production-mutating, post-execution health monitoring with auto-rollback, and a full audit trail feeding a continuous-improvement loop. No single layer is trusted alone — the design assumes any one layer can fail.
Q2: What’s the difference between output guardrails and semantic guardrails, and why do you need both? Output guardrails are mechanical — schema conformance, blocked command patterns, PII redaction — and can be checked with simple code, deterministically and cheaply. Semantic guardrails require judgment — “is this action safe given the current context, even though it’s syntactically valid?” — and typically use a second LLM pass (a “critic”) or an explicit domain rule engine. You need both because a mechanically valid action (correct schema, not on the blocklist) can still be semantically unsafe (e.g., scaling a critical service to zero replicas is a syntactically valid API call but a catastrophic action).
Q3: How do you stop an agent from silently degrading in behavior over weeks without anyone noticing? Continuous evaluation against a golden dataset run on a schedule (not just at deployment), drift monitoring on action-type distribution and approval/override rates, and alerting when the override rate or failure rate on a specific action type crosses a threshold. Treat “the agent’s proposed action was overridden by a human” as a first-class signal, not just a UI event — feed it into a weekly review process.