I wrote a post that does what most guardrail articles don't — shows the actual before/after model outputs for four failure modes (toxic output, hallucination, PII leakage, role drift), with the production-grade tools you'd use for each in a real system.
Each experiment is a system prompt change on the same model. The difference in output is immediate and visible. All four are runnable in a free Colab notebook using Groq's API (open models, no credit card). Two-line swap to use any other OpenAI-compatible provider.
Production tool pointers: Llama Guard for classification, Guardrails AI for output validation, Microsoft Presidio for PII, NeMo Guardrails for conversation flow control.
The underlying point: guardrails aren't a safety feature bolted on at the end — they're an architectural layer. Most teams find this out after the first incident.
The pattern across all four: guardrails are not a feature you add at the end. They're an architectural layer you design from the start.
This post was originally published at sriharshacr.github.io. Reading it here? The canonical version — with all formatting, citations, and the companion notebook — lives at [https://sriharshacr.github.io/blogs/ai-guardrails-in-action/].
Experiment 1 — Toxic output
No guardrail: model writes genuinely aggressive workplace messages on request.
With guardrail: redirects to a constructive alternative. Same model. One system prompt.
Experiment 2 — Hallucination
No guardrail: the model invents company revenue figures. Confidently. With percentages.
With guardrail: "I don't have verified information on this. Please check a trusted source."
A refusal is more valuable than a confident lie.
Experiment 3 — PII leakage
No guardrail: model surfaces contact details when asked.
With guardrail: declines, cites policy, redirects to the right channel.
Experiment 4 — Role drift (jailbreak)
No guardrail: one "ignore previous instructions" prompt, and the persona is gone.
With guardrail: role holds. Override attempt declined.
All experiments are runnable in a free Colab notebook (Groq API, no credit card). Swap 2 lines to use Anthropic, OpenAI, or Kimi instead.
Which of these four would you add to something you're building right now — and what's actually stopping you?
→ Full post + notebook: [https://sriharshacr.github.io/blogs/ai-guardrails-in-action/]

Top comments (0)