The Tool Contract: Narrow Schemas, Clear Boundaries, and Idempotent Writes That Keep Production Agents Predictable

Design tools as strict contracts with narrow scopes, typed schemas, meaningful errors, and idempotency so agents call the right action and recover cleanly from retries.

Mapki

Mapki

Nov 24, 2026•6 min read
Share:
Mapki
Custom Agents

Why tool design decides production reliability

Most production agent failures are not model failures. They are tool failures. A model that can reason well still calls the wrong tool, supplies malformed arguments, or triggers a side effect twice when a timeout forces a retry. The fix is not a longer system prompt. It is a tool contract: a narrow, typed, side-effect-aware definition that the model can understand and that the surrounding code can enforce.

A tool is the interface between a non-deterministic planner and a deterministic system. Anthropic’s engineering work on writing effective tools for agents makes the same point: the description, name, and schema are themselves prompt text. When those texts are ambiguous or overlapping, selection accuracy drops and the agent invents workarounds. When they are precise, the model stays on the intended path and the rest of the harness (validation, approval, observability) can do its job.

The five fields every production tool must declare

Treat every tool as a small contract. At minimum it contains:

  • Name and namespace: A verb-noun pair that matches the user’s mental model (get_invoice_summary, create_refund_request). Avoid synonyms that compete (search_orders and find_orders).
  • Description that teaches: What the tool does, when to use it, when not to use it, and what it returns. Include a short example of correct arguments and one common edge case.
  • Strict input schema: JSON Schema (or equivalent) with required fields, enums for closed sets, format constraints, and min/max bounds. Validate again on the server; schema-constrained generation reduces but does not eliminate malformed calls.
  • Side-effect class: Read, reversible write, or irreversible write. This single field drives permissions, approval gates, and retry policy.
  • Idempotency and error contract: Whether an idempotency key is required, the exact shape of success and error responses, and whether the error is retryable.

A short description is better than a long one that tries to cover every API endpoint. Group related actions only when they share the same risk class. One well-designed get_customer_context tool is more reliable than four overlapping read tools.

Separate reads from writes

Read tools are safe to call, retry, and parallelize. Write tools are not. Keep them distinct so policy can be applied at the tool boundary rather than inside a boolean flag.

  • Read tools (get_, search_, list_): No external side effects. Return only the fields the next decision needs. Truncate or summarize large payloads so the model is not forced to re-process irrelevant data.
  • Reversible writes (draft_, add_note, create_draft_invoice): Allowed under normal authorization. Still log the call and support undo or overwrite where possible.
  • Irreversible writes (send_, charge_, delete_, merge_): Separate tool, narrower schema, mandatory idempotency key, and an approval or hard limit gate before execution.

This separation also simplifies least-privilege. You can grant the read tool to an agent while withholding the corresponding write tool, or place the write tool behind a human checkpoint without changing the model’s available catalog mid-run.

Errors are instructions

A tool that returns only “404” or a stack trace forces the model to guess. A useful error is an instruction:

{
"ok": false,
"error_code": "invoice_not_found",
"message": "No invoice matched id INV-8841. Try searching by customer email or order number.",
"retryable": false,
"suggested_next": ["search_invoices"]
}

Include a stable error code, a human-readable message that points to a recovery path, and an explicit retryable flag. Token-efficient responses matter: return only the fields required for the next decision, not the entire upstream payload.

Idempotency for every mutating call

Agents and orchestrators retry. Timeouts, rate limits, and process restarts are normal. Without an idempotency key, a second attempt can create a second refund, a second ticket, or a second email.

Practical pattern:

  1. Generate a stable key once per logical action (run id + step name, or a UUID minted when the step begins). Never let the model invent a new key on retry.

2. Pass the key as a required argument and as an HTTP header to the backend.

  1. Store the first completed response under that key for a TTL that covers your retry window (often 24 hours for financial actions).
  2. On a second arrival with the same key and the same parameters, return the stored response. On the same key with different parameters, reject.
  3. After an uncertain outcome (timeout, 5xx), call a matching status/read tool before deciding to retry.

The Model Context Protocol includes annotations such as readOnlyHint and idempotentHint. Treat them as documentation, not enforcement. The real guarantee lives in the server-side store and the validation layer that sits between the model and the external system.

A minimal tool review checklist

Before a tool ships, confirm:

1. One clear job, named after a workflow step the agent is likely to express.

  1. Description states what, when, when not, and what is returned, with at least one example.
  2. Input schema uses enums, formats, and required fields; server validates again.

4. Read and write actions are separate tools.

  1. Irreversible writes require an idempotency key and sit behind an approval or hard limit.
  2. Error responses contain a stable code, a recovery hint, and a retryable flag.

7. Output is truncated to the fields needed for the next decision.

  1. Tool selection and argument correctness are measured in an evaluation set, not assumed.

Putting the contract into the harness

The tool contract is only half the system. Pair it with the surrounding controls that keep the agent inside the contract:

  • Validate arguments and check authorization before execution.
  • Attach a correlation id so every tool call appears in the same trace.
  • Enforce step, token, and cost budgets before the call is issued.
  • Require human approval for irreversible actions and re-validate parameters after the approval is granted.
  • Score tool selection and argument quality offline and on a sample of production traces.

Google Cloud’s recent discussion of the four-layer production harness (Learn, Guard, Review, Score) places tool quality inside the Guard and Score layers. A clean tool contract makes both layers cheaper and more precise.

References & Community Insights

A precise tool contract turns an unpredictable planner into a system whose actions can be validated, retried, and audited. The model still decides the next step. The contract decides which steps are allowed and how they survive the real world.

Want to implement this in your business?

Mapki designs bespoke AI agents, custom workflow automations, and tool-agnostic integrations tailored specifically to your existing ERP, CRM, and databases.

Tags:AI AgentsTool DesignIdempotencyProduction AgentsSchema ContractsAgent Reliability