CertPrep
Domain 7 · Lesson 7.1 · 7 min read

Runtime Guardrail Systems

Exam skillRuntime Guardrail Systems

Evaluating layered guardrail architectures against a production agent's risk profile, including input/output filtering, PII redactors, hook-based policy enforcement, destructive-action prevention, sandboxing that grants tool and web access without exposing production systems, approval gates, refusal handling and safety fallbacks, deterministic enforcement for irreversible actions, and false-positive/false-negative tuning.

Layer guardrails to fit an agent's risk profile, with input and output filtering, PII redaction, hooks and permission rules, sandboxes, approval gates, refusal handling and deterministic limits on irreversible actions, and tune each layer for both false positives and false negatives.

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

LayerWhat it doesExample
Input screeningDetects prompt-injection patterns and policy violations in untrusted inputScreening incoming emails before the agent reads them
RedactionMasks PII at boundariesCard and social security numbers masked before logs and analytics
Capability scopingThe agent never holds what it should not useA read-only database role; no ownership-change tool
Deterministic limitsHard rules in codeReject any transfer over $250,000, whatever the agent sends
Hooks and permission rulesAllow, deny or ask before a tool call runsA PreToolUse hook blocking destructive commands on protected paths
SandboxingGrants tool and network access without exposing productionEgress only to the package registry; no production credentials
Approval gatesA person decides before an irreversible stepTransfers over $10,000 or to new payees pause for an approver
Output checksCatch leaks and violations before display or storageInternal data classes checked before a summary is shared
Refusal handlingA safe fallback when the model declinesReplace 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; ask hands the decision to the user; updatedInput can 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

Question 1

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.

Question 2

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.

Question 3

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

Exercise · about 30 minCase: Granite Federal Bank

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.

  1. List the layers you would put around the transfer tool, in the order a request meets them.
  2. Decide what is enforced in code and what is advisory.
  3. Design the redaction for card numbers.
  4. Define how you will tune the input screening without blocking normal questions.
Check your work
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.

Key termsGuardrailHookPII

Sources