Recipe: the guarded model call
Redact, guard the input, call, guard the output. The fake model is scripted to be fooled so the output guard has work to do.
Copy-ready recipes: a guarded model call (redact, input guard, output guard), a tool gate with argument checks, approval and an audit log, a guard-model call, and the security checklist to run before you ship.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write output_guard(reply, canary, prefix) that returns "system prompt marker" if the canary is in the reply, "unexpected reply shape" if the reply does not start with the prefix, else None. Test with three replies.
Write audit_line(call_id, tool, result) returning "<id> <tool> <result>", and count_denied(lines) returning how many lines contain "denied".
Explain it without notes
Walk through the guarded call and say why each step is in its place.
How does the tool gate limit what a steered model can do?
When should you use a guard model, and how do you combine it with rule guards?
What belongs on a pre-ship security checklist for an LLM feature?
Expected output
Noted: Contact [EMAIL] about my order
refused (override phrase)
withheld (unexpected reply shape)
withheld (system prompt marker)