74 / 90

Day 74: Tool Schemas, Validation, and Protocol Boundaries

Define tools as JSON-Schema contracts, classify validation failures into layers, and place MCP host/client/server roles - without claiming protocol compliance from a toy harness.

Agents 480 active minutes (8 hours)
01 120 min

Tool Schemas as Contracts: tool_use, tool_calls, and JSON Schema

Agent-Assisted Engineering Check

Prerequisites

Day 73 control loop; basic JSON and function signatures from the Python block.

Learning Objective

Describe how production model APIs declare tools (name, description, JSON Schema parameters), how tool_use / tool_calls blocks carry name plus arguments, and how MCP generalizes the same contract into host/client/server roles - while scoping what the bounded fixture does not implement.

Instructions

1. A tool schema is a contract: a unique name, a natural-language description, and a JSON Schema parameters object listing properties, types, required fields, and additionalProperties policy. The model can only propose calls it has been shown schemas for.
2. Anthropic-style: the model returns a tool_use content block {id, name, input}; the client executes and replies with a tool_result block. OpenAI-style: the model returns tool_calls[{id, function:{name, arguments(JSON string)}}]; the client replies with role:"tool" messages. Both separate the model's request from the tool's execution - the same seam our harness draws between next_action and _tool_call.
3. MCP in one paragraph: a host process embeds clients; each client keeps one connection to a server exposing tools, resources, and prompts over JSON-RPC 2.0, with capability negotiation at initialize time; transports are stdio or streamable HTTP.
4. Compliance boundary: projects.agent_learning hard-codes three tools with hand-rolled argument checks. It demonstrates dispatch and validation shape only - it has no JSON-RPC framing, no initialize handshake, no tool discovery, and no schema negotiation. Study it as the loop's shape, not as a protocol implementation.
5. Why schemas matter: they are the surface a validator enforces; a malformed call fails at the schema layer before the tool runs.

Practice & Prediction Log

Express the three project tools (list_notes, read_note, write_report) as Anthropic-style tool definitions with name, description, and an input_schema JSON Schema each.

Independent Mastery Criterion

Produce valid tool definitions for all three tools and state at least two protocol features the toy harness lacks (JSON-RPC framing, capability negotiation, discovery, streaming).

Authoritative Source Resources & Provenance

linking Anthropic PBC copyright (no open license stated) / linked reference Linking only; no documentation text is copied

Anthropic Tool Use (Function Calling) Implementation Guide

Author: Anthropic PBC | Original Source Link ↗

Relevant Section / Range: Tool Use Overview, Schema Definitions, and Stop Reasons

Verified Version & Date: Claude API Specification (Verified: 2026-10-30)

Selection Rationale:

Detailed production reference for client-side tool definitions, tool_use content blocks, stop reason tool_use, and tool_result response formatting.

Source Prerequisites:

REST API concepts, JSON schema specification, and basic Python client programming.

Safe Fallback (Offline Resilience):

Offline mock request/response cycles and tool payload schemas are provided in the repo.

Compared Candidate Sources & Selection Analysis (2)
Google Gemini Function Calling Documentation ↗ compared_alternative [Creative Commons Attribution 4.0]

Protobuf and REST function declaration schema; Anthropic documentation provides explicit structured message block mechanics (tool_use / tool_result).

Cohere Tool Use and Multi-Step Agents Guide ↗ compared_alternative [Open Documentation]

Multi-step tool calling parameter definitions; Anthropic specification demonstrates clear separated content blocks essential for inspectable event traces.

linking OpenAI copyright (no open license stated) / linked reference Linking only; no documentation text is copied

OpenAI Function Calling and Structured Outputs Guide

Author: OpenAI | Original Source Link ↗

Relevant Section / Range: Function Calling Architecture and Strict Outputs

Verified Version & Date: OpenAI API Reference (Verified: 2026-10-30)

Selection Rationale:

Widely adopted specification establishing tool choice parameters, JSON schema function descriptions, tool_calls arrays, and role: "tool" responses.

Source Prerequisites:

JSON data structures, chat completion roles, and schema validation.

Safe Fallback (Offline Resilience):

Standard schema dictionaries and simulated tool call responses are bundled in the repository.

Compared Candidate Sources & Selection Analysis (2)
Mistral AI Function Calling Guide ↗ compared_alternative [Open Documentation]

Follows OpenAI-compatible schema convention; OpenAI documentation serves as the primary originating reference for tools and tool_calls schemas.

Ollama Tools and Function Calling Documentation ↗ compared_alternative [MIT / Open Documentation]

Local model runtime implementation of function calling; OpenAI docs document the standard schema contract and strict output validation.

02 120 min

Author and Apply a JSON Schema for read_note Arguments

Independent Mastery Check (no AI assistance).

Prerequisites

Day 74 Activity 1: tool schema anatomy and the contract idea.

Learning Objective

Independently write a JSON Schema (draft 2020-12) object schema for read_note arguments and use it to classify four candidate argument payloads, including the case where schema validation alone is insufficient.

Instructions

1. Write the schema: type object; properties.filename a string; required [filename]; additionalProperties false; optionally a pattern restricting path separators.
2. Classify four payloads against your schema AND against the harness rule Path(filename).name == filename:
a) {"filename": "alpha.txt"} - schema valid, harness accepts.
b) {"filename": "../outside.txt"} - a plain string passes a loose schema, yet the harness rejects it as invalid_arguments because the basename check blocks traversal. Lesson: schema validation is necessary but not sufficient; policy checks live one layer deeper.
c) {"file": "alpha.txt"} - fails required (missing filename) and hits additionalProperties - invalid_arguments.
d) {"filename": 42} - fails type - invalid_arguments.
3. Record each verdict in a table with columns: payload, schema verdict, harness verdict, error code.
4. This is why the adapter's first fault path emits ../outside.txt: the repair depends on an honest error observation, not on the schema silently coercing input.

Practice & Prediction Log

Write read_note.schema.json plus a four-row verdict table (schema verdict / harness verdict / error code) for payloads a-d.

Independent Mastery Criterion

Independent: schema written with required and additionalProperties; all four verdicts correct including the schema-passes-but-harness-rejects traversal case.

Authoritative Source Resources & Provenance

linking IETF Trust License / Open Standard

JSON Schema: A Media Type for Describing JSON Documents (Draft 2020-12)

Author: Austin Wright, Henry Andrews, Ben Hutton, Greg Dennis | Original Source Link ↗

Relevant Section / Range: Section 4 & 5 (Schema Objects and Keywords)

Verified Version & Date: IETF Internet-Draft 2020-12 (Verified: 2026-10-30)

Selection Rationale:

The normative standard governing parameter schemas, type validation, required constraints, additionalProperties restrictions, and descriptive metadata in tool definitions.

Source Prerequisites:

JSON data interchange formats, data typing, and structural validation concepts.

Safe Fallback (Offline Resilience):

Compact schema validator examples and standard validation rules are embedded in local project code.

Compared Candidate Sources & Selection Analysis (2)
OpenAPI Specification 3.1.0 (OAI) ↗ compared_alternative [Apache-2.0]

Comprehensive REST API specification format; JSON Schema Draft 2020-12 is the exact underlying core used by modern agent tool definition protocols.

JSON Schema Draft-07 Specification ↗ compared_alternative [IETF Open Standard]

Legacy JSON schema dialect; modern tool protocols standardise on 2020-12 with strict keyword support.

linking IETF Trust License / Open Standard

RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format

Author: Tim Bray (Ed.) | Original Source Link ↗

Relevant Section / Range: Section 1-4 (JSON Syntax and Grammar)

Verified Version & Date: IETF Standards Track RFC 8259 (Verified: 2026-10-30)

Selection Rationale:

Foundational Internet standard defining strict JSON grammar, token parsing, and whitespace rules underpinning model tool calling serialization.

Source Prerequisites:

Text encoding, UTF-8 parsing, and serialized data exchange.

Safe Fallback (Offline Resilience):

JSON grammar parsing rules and error recovery guidelines are documented in curriculum notes.

Compared Candidate Sources & Selection Analysis (2)
RFC 7049: Concise Binary Object Representation (CBOR) ↗ compared_alternative [IETF Open Standard]

Binary serialization standard; text-based LLMs operate primarily on human-readable UTF-8 JSON interchange formats.

YAML 1.2 Specification (OASIS / yaml.org) ↗ compared_alternative [Open Standard]

Indentation-sensitive text format; JSON has universally standardized parsing across language runtimes and tool schemas.

03 120 min

Failure Vocabulary: unknown_tool, invalid_arguments, not_found, size_limit

Agent-Assisted Engineering Check

Prerequisites

Day 74 Activity 2: schema validation vs harness policy checks.

Learning Objective

Map every structured error the harness emits to the validation layer producing it - existence, argument shape, resource state, payload size - and relate the flat {ok:false,error} shape to protocol-level error surfaces.

Instructions

1. Read _tool_call in projects/agent_learning/agent.py and tabulate:
- name not in ALLOWED_TOOLS -> unknown_tool (dispatch layer).
- arguments not a Mapping, or extra/missing keys -> invalid_arguments (schema layer).
- read_note filename fails the basename rule -> invalid_arguments (policy layer inside schema layer).
- note file absent on disk -> not_found (tool runtime layer).
- write_report content over 4096 bytes -> size_limit (resource limit layer).
2. Trigger each error in a Python REPL inside a tempfile workspace (create_fixture first), and record the observation objects.
3. Malformed results: in real protocols a tool must return a serializable result; if a tool produced non-JSON output the protocol layer itself raises an error (JSON-RPC error object with code and message). Our flat error string is a teaching simplification of that surface.
4. Why structured errors matter: the adapter's repair step re-plans from the observation; a vague failure would leave the loop guessing.

Practice & Prediction Log

In a REPL, call _tool_call with {"name": "delete_all", "arguments": {}} and with write_report content of 5000 characters; record both observations and add them to your error-layer table.

Independent Mastery Criterion

Reproduce all four error codes with correct layer attribution and explain the malformed-result risk in protocol terms (one paragraph).

Authoritative Source Resources & Provenance

linking Apache-2.0 (specification; unrelicensed legacy contributions remain MIT) / Open Specification

Model Context Protocol (MCP) Specification

Author: Anthropic PBC & Open Source Contributors | Original Source Link ↗

Relevant Section / Range: Architecture Overview, Transports, Tools, and Resources

Verified Version & Date: MCP Specification 2024-11-05 (Verified: 2026-10-30)

Selection Rationale:

Normative open architecture specification defining Host, Client, and Server separation, resource subscriptions, tool listing/invoking primitives, and JSON-RPC 2.0 message framing.

Source Prerequisites:

Client-server architecture, JSON-RPC 2.0 protocol, and standard IO communication.

Safe Fallback (Offline Resilience):

Architectural comparison tables, loop invariants, and message frame examples are self-contained in curriculum materials.

Compared Candidate Sources & Selection Analysis (2)

Precursor JSON-RPC architecture for code intelligence in IDEs; MCP adapts similar client-server decoupling specifically for LLM context, tools, and prompts.

OpenAI Responses API Built-in Tools ↗ compared_alternative [Proprietary Documentation]

Hosted, vendor-managed built-in tool execution (successor to the Assistants API tools); MCP provides an open, decoupled local/remote client-server standard.

linking Anthropic PBC copyright (no open license stated) / linked reference Linking only; no documentation text is copied

Anthropic Tool Use (Function Calling) Implementation Guide

Author: Anthropic PBC | Original Source Link ↗

Relevant Section / Range: Tool Use Overview, Schema Definitions, and Stop Reasons

Verified Version & Date: Claude API Specification (Verified: 2026-10-30)

Selection Rationale:

Detailed production reference for client-side tool definitions, tool_use content blocks, stop reason tool_use, and tool_result response formatting.

Source Prerequisites:

REST API concepts, JSON schema specification, and basic Python client programming.

Safe Fallback (Offline Resilience):

Offline mock request/response cycles and tool payload schemas are provided in the repo.

Compared Candidate Sources & Selection Analysis (2)
Google Gemini Function Calling Documentation ↗ compared_alternative [Creative Commons Attribution 4.0]

Protobuf and REST function declaration schema; Anthropic documentation provides explicit structured message block mechanics (tool_use / tool_result).

Cohere Tool Use and Multi-Step Agents Guide ↗ compared_alternative [Open Documentation]

Multi-step tool calling parameter definitions; Anthropic specification demonstrates clear separated content blocks essential for inspectable event traces.

04 120 min

Assessment: Validation Layers and Protocol Compliance Boundaries

Independent Mastery Check (no AI assistance).

Prerequisites

Day 74 Activities 1-3 completed.

Learning Objective

Independently classify eight validation scenarios by layer and write the compliance-boundary statement the rubric requires.

Instructions

1. Classify each scenario into exactly one layer - serialization, schema, dispatch, tool runtime, or resource limits - and name the observable error: (a) arguments text is not valid JSON; (b) arguments missing a required key; (c) tool name not in the registry; (d) requested note absent from disk; (e) report content over 4096 bytes; (f) filename contains ../; (g) arguments is a list not an object; (h) tool result cannot be serialized to JSON in a real protocol.
2. Write a three-sentence compliance boundary statement: the harness teaches loop plus validation shape; it is not an MCP client; it proves no protocol compliance. Name at least two missing protocol features.
3. Independent rubric: at least 7 of 8 classifications correct, boundary statement complete, unaided.
4. Assisted rubric: an agent may draft the table but you must verify every row against _tool_call source.

Practice & Prediction Log

Complete the eight-row classification table and the three-sentence boundary statement without opening agent.py; verify afterward against the source.

Independent Mastery Criterion

Independent Mastery Check: at least 7 of 8 rows correct and a boundary statement naming two missing protocol features, unaided.

Authoritative Source Resources & Provenance

linking Apache-2.0 (specification; unrelicensed legacy contributions remain MIT) / Open Specification

Model Context Protocol (MCP) Specification

Author: Anthropic PBC & Open Source Contributors | Original Source Link ↗

Relevant Section / Range: Architecture Overview, Transports, Tools, and Resources

Verified Version & Date: MCP Specification 2024-11-05 (Verified: 2026-10-30)

Selection Rationale:

Normative open architecture specification defining Host, Client, and Server separation, resource subscriptions, tool listing/invoking primitives, and JSON-RPC 2.0 message framing.

Source Prerequisites:

Client-server architecture, JSON-RPC 2.0 protocol, and standard IO communication.

Safe Fallback (Offline Resilience):

Architectural comparison tables, loop invariants, and message frame examples are self-contained in curriculum materials.

Compared Candidate Sources & Selection Analysis (2)

Precursor JSON-RPC architecture for code intelligence in IDEs; MCP adapts similar client-server decoupling specifically for LLM context, tools, and prompts.

OpenAI Responses API Built-in Tools ↗ compared_alternative [Proprietary Documentation]

Hosted, vendor-managed built-in tool execution (successor to the Assistants API tools); MCP provides an open, decoupled local/remote client-server standard.

linking IETF Trust License / Open Standard

JSON Schema: A Media Type for Describing JSON Documents (Draft 2020-12)

Author: Austin Wright, Henry Andrews, Ben Hutton, Greg Dennis | Original Source Link ↗

Relevant Section / Range: Section 4 & 5 (Schema Objects and Keywords)

Verified Version & Date: IETF Internet-Draft 2020-12 (Verified: 2026-10-30)

Selection Rationale:

The normative standard governing parameter schemas, type validation, required constraints, additionalProperties restrictions, and descriptive metadata in tool definitions.

Source Prerequisites:

JSON data interchange formats, data typing, and structural validation concepts.

Safe Fallback (Offline Resilience):

Compact schema validator examples and standard validation rules are embedded in local project code.

Compared Candidate Sources & Selection Analysis (2)
OpenAPI Specification 3.1.0 (OAI) ↗ compared_alternative [Apache-2.0]

Comprehensive REST API specification format; JSON Schema Draft 2020-12 is the exact underlying core used by modern agent tool definition protocols.

JSON Schema Draft-07 Specification ↗ compared_alternative [IETF Open Standard]

Legacy JSON schema dialect; modern tool protocols standardise on 2020-12 with strict keyword support.