Skip to content
AgenticAIWiki
  1. Learn
  2. Part 12
  3. 64. Guardrails in depth
  4. 64.8

Lesson 64.8 · 8 of 11 · 5 min read · Reviewed 24 Nov 2026

Worked example: hooks, permissions and moderation prompts

By the end, you can

  • Put Claude-specific guardrail tools together.
  • Combine hooks, permissions and a moderation prompt.

Here’s how the layers map onto Claude tooling.

Layer Claude tooling
Input check A fast model classifier with a fixed output schema; a UserPromptSubmit hook in Claude Code
Tool access allowedTools, permission rules (allow / ask / deny), permission modes
Action policy PreToolUse hooks, the SDK’s canUseTool callback
Result checks PostToolUse hooks (validate, redact)
Done checks Stop hooks that verify the work
Output check Schema validation, a grader call for grounding, redaction
Context safety Tags marking untrusted content; system-prompt guidance

A moderation prompt sketch

Classify the user message for a banking support assistant.
Return JSON: {"category": "on_topic" | "off_topic" | "abuse" | "injection_attempt",
              "confidence": "high" | "medium" | "low", "reason": "<one sentence>"}
<message>{{text}}</message>

Force the shape with a tool or structured outputsStructured outputs: Making a model return data that matches a defined schema, such as JSON with required fields and types. (chapter 14), and route anything that isn’t high-confidence on_topic to a stricter path.

Key points

  • Claude Code and the Agent SDK give you permission rules, permission modes, hooks and canUseTool for action checks.
  • A small, fast Claude model makes a good input or output classifier with a strict schema.
  • Combine them: classify input, enforce policy on tools, validate output, and log every decision.
Hands-on labOn your own machine

Wire hooks and permissions in Claude Code

Layer permission rules and a PreToolUse hook in a test project so risky commands are denied or asked about.

You will have: A project .claude/settings.json with allow, ask and deny rules and one hook script, plus a short log of what each test prompt triggered.

Steps

  1. In a throwaway test folder, create .claude/settings.json with a deny rule for reading .env files and an ask rule for git push.
  2. Add a PreToolUse hook for the Bash tool that runs a small script; the script reads the tool input as JSON and blocks commands containing 'rm -rf'.
  3. Start Claude Code in that folder and ask it to read .env, to push, and to delete a folder; note what happens each time.
  4. Run /permissions to confirm which rules are active, and keep any API key in an environment variable, never in the settings file.
  5. Write down which layer (rule, mode or hook) made each decision.

Done when

  • Reading .env is denied, git push asks first, and the rm -rf command is blocked by the hook.
  • Your log names the layer behind each of the three decisions.

Docs: Hooks reference (Claude Code docs) · Claude Code settings (Claude Code docs)

Do it Add a guard to the support agent in the Playground. No API key needed.

Quick checkIn an Agent SDK app, where's the best place to block a refund above $500 that lacks approval?
How sure are you?
Pick an answer and how sure you are