Workflow Enforcement & Handoff

When a single failure means financial loss or a compliance breach, prompting is not enough. Learn deterministic enforcement, prerequisite gates, and complete handoffs.

Lesson 4 of 3013% of the guide
Prefer to learn by doing?

There are two fundamentally different ways to control agent behavior. Prompt-based guidance is probabilistic: instructions in the system prompt work perhaps 90-95% of the time, but the model can still skip, reorder, or misread steps. Programmatic enforcement is deterministic: code-level checks and gates physically block an incorrect sequence before it executes, every time, regardless of what the model decides.

The high-stakes rule

If a single failure would cause financial loss, a security breach, or a compliance violation, use programmatic enforcement. Prompting can reduce an 8% failure rate to 3-4%, but never to 0%. Only code enforcement reaches zero.

The enforcement decision matrix

Operation typeRiskRequired approach
Financial (refunds, transfers, payments)HighProgrammatic
Security (identity, access control)HighProgrammatic
Compliance (AML, regulatory checks)HighProgrammatic
Low-stakes (formatting, style, ordering)LowPrompt-based is acceptable

Prerequisite gates

A prerequisite gate is a code-based mechanism that blocks a tool until prior conditions are met. Consider a refund flow with get_customer, lookup_order, and process_refund. The gate checks whether get_customer has returned a verified customer ID this session. If yes, process_refund runs; if not, it returns a blocking error telling the agent to verify identity first. The model cannot reason its way past the gate - even a direct process_refund call is blocked until the prerequisite completes. In production, an 8% unverified-refund rate under prompting dropped to 0% once a gate was added.

Enforcing "verify identity before refunding"
Don't

Relying on a system-prompt instruction ("always call get_customer before process_refund"). Prompting is probabilistic - it trims the ~8% unverified-refund rate to 3-4%, never to zero, so money still leaks.

SYSTEM = "Always verify identity before any refund."
Do

Add a code-level prerequisite gate (or PreToolUse hook). The model cannot reason past it; the unverified-refund rate goes to 0%.

if tool == "process_refund" and not session.get("verified_customer_id"):
    return {"decision": "block", "reason": "Verify identity first."}

Subagent lifecycle hooks

The Agent SDK exposes two lifecycle hooks specific to subagents. They are easy to confuse, and the exam tests the distinction:

  • SubagentStart - fires when a subagent is spawned. It is observational: it can log the spawn and inject extra context, but it cannot block or modify the invocation. To deny or rewrite a spawn, attach a PreToolUse hook to the Agent tool itself.
  • SubagentStop - fires when a subagent returns. It can validate the output schema, log metrics, and return decision: "block" with a reason to send the subagent back for more work. It does not transform output - use PostToolUse on the Agent tool (via updatedToolOutput) to reshape or redact.
Subagent-scoped hooks enable per-agent policy

Subagents can define their own PreToolUse and PostToolUse hooks in their AgentDefinition. These only intercept that subagent's tool calls - so a billing subagent can block refunds above a threshold while a technical-support subagent has no such restriction. Stop hooks defined in a subagent auto-convert to SubagentStop events at runtime.

Structured handoff to humans

When an agent escalates to a human, remember the constraint that trips up so many designs: the human agent does not have access to the conversation transcript. They see only the handoff summary. If a field is empty or a placeholder, the human must make the customer repeat everything. A complete handoff carries all of:

  1. 1Customer ID - so the human can pull the account immediately.
  2. 2Conversation summary - what the customer wanted and what the agent tried.
  3. 3Root cause analysis - the agent's assessment of the underlying issue.
  4. 4Refund amount (if applicable) - a specific figure, never vague.
  5. 5Recommended action - exactly what the human should do next.
# PreToolUse gate: process_refund is blocked until identity is verified.
def pre_tool_use(tool_name, tool_input, session):
    if tool_name == "process_refund":
        if not session.get("verified_customer_id"):
            return {
                "decision": "block",
                "reason": "Customer identity not verified. Call "
                          "get_customer first.",
            }
    return {"decision": "allow"}
"Just strengthen the prompt" is the distractor

Whenever a scenario involves money, security, or compliance and the failure is intermittent, answers proposing stronger prompts, few-shot examples, or a routing classifier are distractors. Better prompting stays probabilistic; few-shot improves averages but not guarantees; routing decides which agent runs, not what happens inside it. The answer is code-level enforcement.

One more handling note: for compound requests ("return my order, update my address, and check my loyalty points"), decompose into distinct items, investigate them in parallel using shared account context, and synthesize a single unified response. Handling one item and forgetting the rest, or spinning up separate sequential conversations, both fail the requirement.

How the exam will try to trick you

The distractors below look right under time pressure — learn the tell.

  1. The trap

    Fix an 8% unverified-refund rate by strengthening the system prompt.

    Correct answer

    Add a programmatic prerequisite gate that blocks process_refund until identity is verified.

    Why: Prompting is probabilistic - it trims failures toward 3-4% but never reaches the 0% high-stakes money flows require.

  2. The trap

    Add few-shot examples to guarantee compliance on financial operations.

    Correct answer

    Enforce the rule in code with a prerequisite gate.

    Why: Few-shot improves average behavior but stays probabilistic - it cannot provide a 100% guarantee.

  3. The trap

    Add a routing classifier to solve a per-agent compliance failure.

    Correct answer

    Enforce the workflow within the agent's execution, e.g. a PreToolUse gate.

    Why: Classifiers decide which agent runs, not what happens inside it - the failure is in the execution sequence.

  4. The trap

    Escalate to a human with a handoff summary missing the customer ID or recommended action.

    Correct answer

    Include all five fields: customer ID, conversation summary, root cause, refund amount, recommended action.

    Why: The human never sees the transcript, so any empty field forces the customer to repeat everything.

Key takeaways

  • Prompt-based control is probabilistic; programmatic enforcement is deterministic (100%).
  • Use programmatic enforcement whenever a single failure means financial loss, a security breach, or a compliance violation.
  • Prerequisite gates are code-based and cannot be bypassed by the model's reasoning.
  • SubagentStart is observational; SubagentStop can block completion; neither transforms output (use PostToolUse on the Agent tool for that).
  • Human handoffs must include all five fields - the human never sees the transcript.
  • For money/security/compliance scenarios, "stronger prompts," few-shot, and routing classifiers are distractor answers.

Frequently asked questions

When should I use programmatic enforcement instead of prompting a Claude agent?+

Whenever a single failure would cause financial loss, a security breach, or a compliance violation. Prompt-based guidance is probabilistic and cannot reach 100% reliability, so high-stakes operations need deterministic code-level checks such as prerequisite gates or PreToolUse hooks.

What is a prerequisite gate in a Claude agent?+

A code-based check that blocks a tool from running until required prior conditions are met - for example, blocking process_refund until get_customer has returned a verified customer ID. Because it is code, not a prompt instruction, the model cannot reason around it.

What must a human handoff summary include?+

Customer ID, a conversation summary, root cause analysis, the refund amount if applicable, and a recommended action. The human agent cannot see the conversation transcript, so any empty or placeholder field forces the customer to repeat themselves.

Practice makes pass

Ready to test what you just learned?

Reading gets you familiar — answering questions gets you certified. Jump into free practice or sit a full timed mock exam, scored 100–1000 just like the real thing.

No sign-up required · Explanation for every answer · Works offline