AI Systems Reference/Reliability & Safety

Guardrails & Content Policy

Input/output filters, policy classifiers, PII redaction, and defense-in-depth beyond the model vendor's safety layer.

4/5Overview: 30m

Defense in depth for LLM products

Vendor safety (OpenAI moderation, Anthropic constitutional AI) is necessary, not sufficient. Your product context — internal data, brand voice, regulated domains — needs application-layer guardrails.

OWASP LLM Top 10: prompt injection, insecure output handling, training data poisoning — design assuming attackers probe your surface.

Policy stack layers

User input → [Client filter] → [Gateway] → [Pre-model policy] → Model → [Post-model policy] → User
LayerExamplesLatency budget
InputPII redaction, prompt injection heuristics, length caps< 10ms (rules)
Pre-modelModeration API, blocklist, jailbreak classifier50–200ms
ModelVendor safety tuning(in inference)
Post-modelOutput moderation, citation check, format validation50–200ms
AuditLog policy decisions (not always full prompt)Async

Fail closed for high-risk domains (medical, financial advice); fail open with flag only when UX demands it and legal approves.

Prompt injection vs jailbreaking

AttackVectorMitigation
Direct injectionUser text overrides system promptDelimiter discipline, instruction hierarchy, input sandboxing
Indirect injectionMalicious content in retrieved docsSanitize retrieval, separate system/user channels
Tool abuseModel tricked into calling dangerous toolsAllowlisted tools, human-in-loop for writes

No silver bullet — combine rules, classifiers, and least-privilege tools.

PII and data leakage

  • Scan inputs for SSN, credit cards, secrets before sending to vendor
  • Redact logs — prompts often contain user PII
  • Block model from echoing training-like secrets (API keys in user paste)

Enterprise contracts require zero retention — verify vendor tier, don't assume.

Content policy dimensions

Beyond "toxicity":

  • Competitor mentions
  • Legal claims without disclaimer
  • Copyrighted text reproduction
  • Off-brand tone

Maintain a policy config versioned like code — rollbacks when new rules over-block.

Human review queues

For borderline scores, route to human before display. Queue depth is an SLO — backlog = delayed UX.

Interview framing

"Secure a customer support bot with tool access":

  1. Read-only tools by default; writes need confirmation
  2. Retrieved tickets sanitized; metadata ACL enforced
  3. Post-model check for PII in outbound email tool args
  4. Rate limit and anomaly detection on policy blocks

Senior signal: Distinguish security (injection → data exfil) from safety (harmful content) — different teams, different metrics.

Link forward

Failure Modes & Degradation covers runtime behavior when policy or model layers fail — not just what to block.

Further Reading

Hands-On Tasks (Optional)

Design drills and architecture sketches — gateway SLOs, eval gates, rollout plans. Assumes AI Engineering fundamentals are already in place.

  • Layer a policy stack for a customer-facing bot

    Define checks at: client, API gateway, pre-model, post-model, and audit log. For each layer, list blocked vs flagged vs logged behaviors and latency budget.

    20m