Install
Define a contract
A contract is a schema + rules. The schema defines the shape. The rules define what “correct” means.score-lead.ts
(data) => true | string. Return true if the data is correct, or a string describing the violation.
Wrap your LLM call
Usecontract.accept() to wrap your existing provider call. Your LLM code stays the same — Boundary wraps the acceptance boundary around it.
Use the result
result.ok is a discriminated union. When true, result.data is typed and guaranteed correct. When false, result.error explains what failed.
What just happened
Next steps
Contracts
How contracts work in detail
Rules
Writing effective domain rules
OpenAI guide
Full integration with OpenAI
Anthropic guide
Full integration with Anthropic