Skip to main content
OpenAI structured outputs help keep the response JSON-shaped. Boundary applies your schema and domain rules before that JSON reaches application state.

Install

Define the contract

Call OpenAI inside accept()

Pass attempt.instructions to the model and append attempt.repairs. On the first attempt, repairs is empty. On retries, it contains the schema and rule failures from the previous attempt.
Return the raw response text. Boundary handles parsing, validation, repair, and the final accept/reject decision.

Gate side effects

Do not fall back to the last parsed attempt when ok is false. The rejected output failed the contract.

Chat Completions

If you are using Chat Completions, the same pattern applies. Put attempt.instructions in the system message and map repair messages into the provider’s message shape.

What Boundary adds

Use OpenAI structured output support for response shape. Use Boundary for the deterministic decision your app can trust:
  • cross-field rules such as “hot tier requires score >= 70”
  • repair messages built from actual schema and rule failures
  • a typed ContractResult that separates accepted data from rejection history
  • local logging during development and hosted traces when you add the SDK
Next: Add Boundary to an LLM feature for the provider-agnostic workflow, or Production observability when you want dashboard traces.