Skip to main content
Boundary is easiest to add when you treat it as the last step before your application trusts model output. You do not need to move provider code into Boundary. Keep your model call where it is. Wrap the call with contract.accept(), return the provider’s raw text, and only continue with result.data when the contract accepts.

Install the Boundary skill before asking an AI coding agent to add this pattern.

Open in Cursor

Before Boundary

A typical structured-output flow looks like this:
That code checks whether the model returned JSON. It does not check whether the values are safe for the workflow.

Add a contract near the workflow

Keep the contract close to the feature it protects:
Write rules for the parts that would cause bad behavior if they were wrong: routing, money, permissions, state transitions, risk labels, or customer-facing decisions.

Wrap the provider call

Inside accept(), call your provider the same way you already do. Include attempt.instructions and spread attempt.repairs into later attempts.
The important rule: return a string, not a parsed object. Boundary owns parsing, validation, and repair.

Gate the side effect on result.ok

Only accepted data should reach the system Boundary is protecting.
Do not write result.error.attempts.at(-1)?.cleaned to your database as a fallback. The whole point of the boundary is that rejected data does not enter the application path.

Write repair-friendly rule messages

A good rule failure tells the model what was wrong and what would satisfy the rule.
The useful version includes the field, actual value, expected condition, and a valid repair direction.

Start with local logging

Use debug: true or createConsoleLogger while you are integrating:
Once the contract is stable, remove noisy console logging and add either a lightweight ContractLogger for your own metrics or the hosted SDK for dashboard traces.

Common integration mistakes

Next steps

Local development

Debug the contract before production

OpenAI integration

Provider-specific OpenAI example

Anthropic integration

Provider-specific Claude example

Production observability

Send accepted and rejected runs to the dashboard