BrainBots
Back to journal
Engineering

Type-safe boundaries for tool-using agents

Why we wrap every agent tool in typed contracts — and how it prevents production disasters.

BrainBots TeamJanuary 5, 2026 9 min read
Type-safe boundaries for tool-using agents

The problem with untyped tools

When agents call external APIs through ad-hoc JSON, failures are silent. Wrong field names, missing validations, and partial updates corrupt production data before anyone notices.

We treat agent tools like public API endpoints: typed inputs, typed outputs, schema validation on both sides.

Our pattern

Each tool is a function with a Zod (or equivalent) schema. The agent receives a JSON schema derived from those types. Outputs are validated before side effects execute.

If validation fails, the agent gets a structured error and retries — it doesn't write bad data to your CRM.

Testing tools independently

Tools are unit-tested without the model. Agent evals test tool selection and sequencing. This separation makes debugging fast: was it the model or the integration?

Related reading

Want to apply this to your business?

Book a discovery call — we'll map your highest-impact opportunity in 30 minutes.