Agent Tool Contracts

Structured Outputs and Tool Contracts for Safe Agents

Original OPNFTR content about AI, technology, and practice.

Original content by OPNFTR
agentsJSON Schematool callingaudit

Model output is untrusted input

Treat every model response as untrusted. Constrain fields with JSON Schema, then validate enums, ranges, resource ownership, and current state on the server. A valid schema does not make an action legal; business rules remain separate.

At minimum, a tool contract should record:

name, version, input schema, output schema, permission scope, timeout, idempotency key, error types

Bind the tool version to the task record. When fields change, keep a backward-compatible parser so an old task cannot retry against an incompatible interface.

Isolate side effects behind policy

An agent may propose a refund, but a policy layer must verify amount, order state, and operator permission. High-risk actions go to human approval. Store the evidence and rejection reason in an audit log. A timed-out external API should return a retryable state rather than repeat a side effect blindly.

Test normal and hostile paths

Give each tool samples for invalid types, unauthorized resources, expired state, duplicate idempotency keys, and timeouts. Contract tests lock input and output shapes; replay tests prove that a failure cannot send a message, write a row, or charge twice.

Sources

See OpenAI Structured Outputs, JSON Schema, and the OWASP Agentic AI threat guidance.

Browse all articles
AI AgentsAI Agents: From Core Concepts to Productionagents · tool calling · workflow
Product Hub Demo · V0.3