Unit 3 of 12 · about 3 hours · implement

Tool argument normalization and result validation

Valid JSON is neither a valid command nor proof that a tool succeeded. Both the proposal and the returned observation cross an untrusted boundary.

You'll be able to

  • Normalize only documented representations before validating the exact executable arguments.
  • Validate result shape, bounds, operation identity and business postconditions before accepting completion.
  • Preserve an unknown effect outcome when the returned result is malformed.

Covers

Argument normalization plus result and output validation
1

Read

In this order, only the parts listed

0 of 3 done

  1. AI Agents in Depth: transparent normalization and verificationAI Agents in Depth - Tools and Asynchronous Interaction

    Live edition, Section 4.2.3 Fidelity of Parameter Passing; Section 4.6, Automated Validation and Feedback Loop and Truncation and Persistence of Long Outputs (page read 2026-10-18)

  2. MCP 2026-07-28: result validation and errorsModel Context Protocol Specification 2026-07-28

    Output Schema; Error Handling; Security Considerations

  3. Durable Tool-Using Workflow: independent outcomesDurable Tool-Using Workflow

    Architecture constraints; Milestone A - Correct baseline; Correctness requirements; Failure-injection requirements

2

Focus on

  • The Programming unit on typed interfaces and runtime validation supplies the validator. Here apply it after proposal parsing and again after tool execution, not just when generating a schema.
  • Canonical serialization can ignore object-key order without changing string values. Persist the canonical executable arguments and normalization version; approval must refer to those arguments.
  • A schema-valid receipt can still name another operation or resource. Check correlation and permitted state changes against the intent and the recipient ledger.
  • Bound output before context assembly. Preserve explicit truncation metadata and an authorized retrieval handle; do not present a partial list as exhaustive.
Common mistakes · 3
  • Coercing a malformed proposal into a different action after approval. A changed executable meaning needs new validation and approval.
  • Retrying a write because its result failed validation. The effect may already have committed.
  • Treating text inside a valid tool result as an instruction. Validation makes data well formed, not authoritative.
3

Try it yourself

Closed-book, before checking anything

Using Pydantic 2.14.1, rebuild the strict reservation boundary from memory. Reject absent fields, string quantity, extra tenant field and nonpositive quantity. Serialize validated arguments with sorted keys and compact separators: reordered object keys must serialize identically, but curly and straight quotes must remain distinct. Feed a valid receipt, a missing receipt ID and a receipt for another operation into your result boundary. Accept only the correlated valid receipt; leave the other effect outcomes unresolved until recipient evidence settles them.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.A tool returns success text but omits the required receipt. Is the workflow complete?Answer

    No. Reject the result as completion evidence. If dispatch occurred, query or reconcile the original operation rather than assuming no effect.

  2. 2.Why normalize before binding an approval?Answer

    Approval must cover what will execute. A later meaning-changing normalization would execute an effect the human did not approve.

  3. 3.A valid result includes another operation's receipt. What failed?Answer

    Semantic correlation, even if structural validation passed. The receipt does not establish this operation's outcome.

You're done when

Your boundary rejects malformed inputs before dispatch and cannot turn a missing or miscorrelated receipt into either success or a safe-to-repeat failure.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 11 more in the section
  • Durable Tool-Using WorkflowRoadmap-Final · primary

    Build the reduced core through typed tools, one approval, one simulated irreversible effect, one compensable effect, capability policy, idempotency, durable intent and outcome, bounded execution and replay. Run kill tests around every persistence and effect boundary before adding an agent loop.

  • AI Agents in Depth - Tools and Asynchronous InteractionBojie Li · required

    Read Chapter 4: 4.2 tool design and schema fidelity, 4.3 MCP, 4.5 versus 4.6 (read-only perception tools against execution tools), the "Idempotency and Cancellation Semantics" passage and the observability part of 4.6, and 4.7 human-in-the-loop timeouts. Add 5.1.5 Failure and Error Recovery and 6.2 asynchronous interaction. Translate the advice into explicit state and effect contracts.

  • Model Context Protocol Specification 2026-07-28Model Context Protocol · required

    Read the 2026-07-28 architecture and versioning pages: there is no initialize handshake, every request carries _meta protocol version, client info and capabilities, and server/discover lists versions and capabilities. Then the stdio and Streamable HTTP bindings, tools/list and tools/call (input and output schemas, isError versus JSON-RPC errors), resources and prompts, the tasks extension, and the roots and sampling deprecations. Build one small stdio server and client, record the wire messages, and keep application authorization outside the protocol.

Also in this section

  • Making Retries Safe with Idempotent APIsAmazon Builders' Library · required

    Read "Retrying and the potential for undesirable side effects", "Reducing client complexity with idempotent API design", "Semantic equivalence and support for default retry strategies", "Late arriving requests and the life span of unique client request identifiers" and the parameter-mismatch section. Record the key and the effect atomically, scope keys by caller, and reject a reused key with different parameters.

  • Idempotent RequestsStripe · required

    Read the page as one concrete recipient contract: an Idempotency-Key header, the first result saved and replayed, parameter mismatch rejected, keys pruned after at least 24 hours (API v1), and the different API v2 retry semantics. Encode these cases in your fake effect recipient; do not treat 24 hours as universal.

  • Timeouts, Retries, and Backoff with JitterAmazon Builders' Library · required

    Read "Timeouts", "Retries and backoff" and "Jitter": a timeout leaves the outcome unknown, side-effecting calls are unsafe to retry without idempotency, and retries belong at one layer with a token-bucket budget. Model the unknown outcome as its own workflow state.

  • How to Do Distributed Locking (fencing tokens)Martin Kleppmann · required

    Read "What are you using that lock for?", "Protecting a resource with a lock" and "Making the lock safe with fencing". The effect recipient must remember the highest token and reject older ones (34 accepted, delayed 33 rejected); a random lock value is not a fencing token. Fencing rejects stale authority, while idempotency rejects repeated operations.

  • SagasHector Garcia-Molina and Kenneth Salem · reference

    Read Section 1 (p. 250: compensation does not necessarily restore the earlier state) and Section 9 Designing Sagas, with Sections 4 and 5 on backward and forward recovery. Some actions cannot be compensated; model failed compensation and manual handling explicitly.

  • LangGraph Persistence and InterruptsLangChain · support

    Read persistence (checkpointer versus store; the in-memory saver does not survive a restart), interrupts (interrupt, Command(resume=...), the rules of interrupts, "side effects called before interrupt must be idempotent") and the Functional API determinism and idempotency sections. Resuming restarts the interrupted node from its beginning: reproduce the repeated pre-interrupt action with a SQLite checkpointer across two processes.

  • DBOS Transact Python: Workflows and StepsDBOS · support

    Read the workflow tutorial ("Workflow IDs and Idempotency", "Determinism"), the step tutorial ("Configurable Retries", "Step Timeouts") and the system-database page (SQLite by default). Kill a process mid-workflow and confirm that completed steps do not rerun while the interrupted step does. Choose this or LangGraph as the implementation companion, not both.

  • Temporal: Workflow Replay, Activity Retries and TestingTemporal · reference

    Read Event History and replay, the Python workflow logic requirements, "Make Activities idempotent", the default retry policy (unlimited attempts unless set) and Signals versus Updates. Activities may run more than once, so replay does not make an external effect exactly-once.

  • Writing Effective Tools for AI AgentsAnthropic · support

    Read "Running an evaluation" and "Principles for writing effective tools" through "Prompt-engineering your tool descriptions": a small task-shaped tool surface, unambiguous parameter names, bounded and paginated results, actionable errors. Compare with the OpenAI function-definition best practices and rewrite one tool contract.

  • AI Engineering Handbook - Agent EngineeringHandbook Academy · support

    Study the Part 7 chapters on tool design, MCP and security, human review and long-running agents. Use them to audit user-facing workflow behavior and failure paths after the durable core works.

  • The Hitchhiker's Guide to Agentic AI - Harness and MCPHaggai Roitman · support

    Use v3 sections 18.4 to 18.7 (tool integration, orchestration with the explicit state machine in 18.5.5, state management and checkpoints, error handling), then Chapter 23 for MCP vocabulary and 23.6 for its security model. Its transport lists predate the 2026-07-28 specification and 18.4.5 contradicts Chapter 23, so take protocol facts from the specification.