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.
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.
The server resolves identity; the model does not choose the effective tenant.
inputTo 02 · Tool schemaExpose only the operation and arguments needed for the task.
processTo 03 · Policy + validationReject unknown fields and verify permission for the specific resource.
resultTo 04 · Business servicePerform the lookup or approved write with a timeout and an operation identifier.
Return compact evidence with distinct not-found, denied, and unavailable outcomes.
The next model turn reasons from this result without treating returned text as instructions.
Result or stopping point
Expose only the operation and arguments needed for the task.
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.
python3 -m venv .venv
source .venv/bin/activateImplement the example
Save as 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
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.