BUILD · 5 MIN READ

Design tools an agent can use well

Give each tool a precise purpose, a small input schema, and a trustworthy result.

Download example files Code + setup + checks in a ZIP
Jump to a section 10 sections

EXAMPLE USE CASE

Expose a safe order-status lookup to an agent

A model may request the wrong order, add an untrusted tenant field or pass malformed arguments.

Input
The authenticated tenant from the application plus exactly one order_id argument.
Expected output
A structured ok/status response, not_found, or a validation error before the business operation.
  • Success check: A104 returns packed for its tenant; another tenant cannot read the same record.
  • Try a failure: Pass an extra tenant argument or ../../orders. Validation must reject it before lookup.

Example scope: A local Python tool boundary. Authentication is supplied by the application; a model-proposed identity is never trusted.

Pydantic exampleFastMCP exampleOpen Policy Agent example
SEE HOW THE SYSTEM FITS TOGETHERSELECT A COMPONENT
inputprocessresultcheckoutputUser requestAuthenticated sessionTool schemaSmall typed argumentsPolicy + validationReject invalid callsBusiness serviceAuthoritative operationStructured resultSuccess or explicit errorAgent continuationUse the observation
  1. The server resolves identity; the model does not choose the effective tenant.

  2. Expose only the operation and arguments needed for the task.

  3. Reject unknown fields and verify permission for the specific resource.

  4. Perform the lookup or approved write with a timeout and an operation identifier.

  5. Return compact evidence with distinct not-found, denied, and unavailable outcomes.

  6. The next model turn reasons from this result without treating returned text as instructions.

    Result or stopping point
Tool schema

Expose only the operation and arguments needed for the task.

Follow the arrows, then select a component to inspect its responsibility. On mobile, downward arrows connect the next step; bent arrows identify branches and return paths. Select a destination to jump to that component.

Describe the operation

  • A useful tool name describes one action.
  • A lookup tool should identify required fields, the scope of the data, and what an empty result means.
  • Keep inputs structured so the application can validate them before execution.

Make the boundary real

  • Resolve the authenticated user in application code.
  • Apply authorization to every resource access.
  • A user identifier proposed by a model does not establish permission to read that user’s data.

Design the result and the failure

  • Return stable fields such as status, record, and error code.
  • Distinguish a missing record from a network failure.
  • Use idempotency keys for actions that could otherwise be repeated during a retry.
  • Test malformed arguments, partial results, slow tools, and a result containing misleading instructions.
  • Retrieved content is data; it cannot change the application’s policy.

Set up the lab

  • Use a new working directory for this example.
Shell
python3 -m venv .venv
source .venv/bin/activate

Implement the example

Save as tool_boundary.py

Python · tool_boundary.py
import re

records = {("tenant-a", "A104"): "packed"}
def lookup_order(authenticated_tenant, arguments):
    if set(arguments) != {"order_id"}:
        raise ValueError("Unexpected or missing arguments")
    order_id = arguments["order_id"]
    if not isinstance(order_id, str) or not re.fullmatch(r"A[0-9]{3}", order_id):
        raise ValueError("Invalid order identifier")
    value = records.get((authenticated_tenant, order_id))
    return {"status": "ok", "order_status": value} if value else {"status": "not_found"}

print(lookup_order("tenant-a", {"order_id": "A104"}))
assert lookup_order("tenant-b", {"order_id": "A104"}) == {"status": "not_found"}
try:
    lookup_order("tenant-a", {"order_id": "A104", "tenant": "tenant-b"})
except ValueError:
    print("untrusted tenant argument rejected")

Run and verify

Shell
python tool_boundary.py
  • The same order identifier in another tenant returns not_found.
  • Unexpected fields fail before any business operation.

Troubleshooting and failure tests

  • Never accept a model-supplied tenant as proof of identity.
  • Distinguish not-found, invalid-input, denied, timeout, and unavailable outcomes in your real service.

Before production

  • Derive identity from verified authentication middleware; enforce permissions at the resource service.
  • Set a timeout, cap result sizes, and use operation identifiers for retryable writes.

Keep exploring

A governed tool layer with MCPA human approval boundary for agent actionsBuild an agent with LangChain