What you need to know
No single guardrail is perfect, so production agents use layers, each catching what the others miss. The exam asks you to pick layers that fit a specific risk profile, and to tell advisory controls (prompts, instructions, CLAUDE.md) from enforced ones (code, permissions, hooks, sandboxes, gates). When the stakes are irreversible, the answer is enforced.
The layers
| Layer | What it does | Example |
|---|---|---|
| Input screening | Detects prompt-injection patterns and policy violations in untrusted input | Screening incoming emails before the agent reads them |
| Redaction | Masks PII at boundaries | Card and social security numbers masked before logs and analytics |
| Capability scoping | The agent never holds what it should not use | A read-only database role; no ownership-change tool |
| Deterministic limits | Hard rules in code | Reject any transfer over $250,000, whatever the agent sends |
| Hooks and permission rules | Allow, deny or ask before a tool call runs | A PreToolUse hook blocking destructive commands on protected paths |
| Sandboxing | Grants tool and network access without exposing production | Egress only to the package registry; no production credentials |
| Approval gates | A person decides before an irreversible step | Transfers over $10,000 or to new payees pause for an approver |
| Output checks | Catch leaks and violations before display or storage | Internal data classes checked before a summary is shared |
| Refusal handling | A safe fallback when the model declines | Replace partial streamed output with a helpful message; log for review |
Hooks in Claude Code and the Agent SDK
- PreToolUse runs before a tool call and is the enforcement point. Block with exit code 2 or a JSON permission decision of
deny;askhands the decision to the user;updatedInputcan rewrite the call (for example, redact a secret from a command). - Exit code 1 is non-blocking: the call runs. A hook meant to stop something must exit 2.
- PostToolUse runs after the call: right for formatting, linting and logging, too late to prevent anything.
- Stop can refuse to end the turn, for example until tests pass.
Rules that must hold on every machine (no force-push to main) belong in managed settings as deny rules or hooks that engineers cannot override, not in CLAUDE.md or a wiki.
Permission modes and what they guard
Auto mode's classifier reviews actions for dangerous intent; it does not judge whether code is correct. Pair it with a Stop hook that runs the tests. Bypass permissions mode removes checks and belongs only inside isolated containers. Unattended runs use a mode that denies anything not pre-approved.
Sandboxes
A sandbox grants exactly the access a task needs: network egress to an allowlist (the package registry), no production credentials, and OS-level limits on what shell commands can read. Tool-level deny rules on file tools do not stop a shell command reading a credentials file; the sandbox does.
Tuning: two error rates
Every filter has false positives (legitimate requests blocked) and false negatives (bad ones passed). Measure both on labeled samples of real traffic, per entity or category, and tune to the risk:
- an input filter that blocks 8% of legitimate questions to catch 99% of attacks is costing users heavily;
- a PII filter that masks medication doses makes clinical summaries useless, which is a clinical risk of its own;
- refine detection (context-aware rather than keyword patterns), then confirm true positives are still caught.
Adding keywords usually raises false positives; removing a filter entirely raises false negatives.
In the exam
Guardrail items describe an agent, its tools and a failure or risk. Choose the layer that would have prevented it, preferring enforced controls placed before the action, and check that the design does not add needless friction (gating everything) or remove the human step already relied on. Distractors strengthen prompts, log after the fact, use exit code 1, rely on auto mode for correctness, or add keywords.
Check your understanding
An ops agent deleted a shared cache directory although its prompt forbids it. Which control most reliably prevents a repeat?
Show answer
Answer: C. A check before execution holds whatever the model decides; logging afterwards only detects.
A PreToolUse hook exits with code 1 on a forbidden command, but the command still runs. Why?
Show answer
Answer: B. Exit 2 or a JSON deny decision blocks; exit 1 is reported but the call proceeds.
An input filter blocks 99% of malicious prompts and 8% of legitimate questions. What next?
Show answer
Answer: D. Tuning needs both error rates measured; more keywords raise false positives further.
Apply it: Guardrails for Granite's customer assistant
Granite's assistant reads balances and transactions and can transfer money between a customer's own accounts. Transfers over $5,000 need step-up verification, transfers to third parties are not allowed, and card numbers must never appear in logs. A tester got the assistant to attempt a transfer to an account number pasted in a message, which the backend rejected only because the account format was invalid.
- List the layers you would put around the transfer tool, in the order a request meets them.
- Decide what is enforced in code and what is advisory.
- Design the redaction for card numbers.
- Define how you will tune the input screening without blocking normal questions.
Show model answer
1. Layers, in order.
- Input screening of the customer's message for injection patterns (flags, does not block).
- The transfer tool accepts only account IDs from the customer's own account list, returned by
get_accounts; free-text account numbers are rejected by the tool's schema and backend. - A hard limit and rule in code: destination must be an own account; amounts over $5,000 trigger step-up verification before execution.
- An audit event for every transfer attempt, executed or rejected.
- Output check on replies for card numbers and full account numbers.
2. Enforced versus advisory. Enforced: own-account-only destinations, the $5,000 step-up, the absence of any third-party transfer capability, redaction. Advisory: the system prompt's description of the transfer policy, which helps the model explain refusals but enforces nothing.
3. Redaction. A detector for card numbers (pattern plus checksum) masks them in incoming messages before logging and before they reach analytics, and in outgoing replies. The PCI provider handles any real card entry, so no card number needs to reach the model.
4. Tuning. Label 2,000 real messages (including known attack attempts); measure false positives and false negatives of the screen by category; set the threshold so that flagged messages are reviewed in a sample rather than blocked, because the enforced controls already stop the dangerous action.