@boundary/contract.
Core types
ContractResult<T>
The return type of every contract call. Discriminated union onok.
ContractAttempt
Passed to yourRunFn on each attempt.
ContractError
AttemptDetail
FailureCategory
Rule<T>
true if the data is correct. Return a string describing the violation if it’s wrong.
RunFn
null if the model returned nothing.
Message
attempt.repairs and repair functions.
Configuration types
ContractConfig<T>
RetryOptions
RepairOverrides
ContractLogger<T>
Hook into the execution lifecycle. All hooks are optional.Engine primitives
Lower-level functions for advanced use cases. All are pure and side-effect-free.| Function | Signature | Description |
|---|---|---|
clean | (raw: string | null) => unknown | Extract and normalize JSON from raw LLM output |
verify | (data: unknown, schema: ZodType<T>, rules?: Rule<T>[]) => ContractResult<T> | Validate data against schema and rules. No LLM involved. |
classify | (raw: string, cleaned: unknown) => FailureCategory | Categorize a failed response |
repair | (detail: AttemptDetail, overrides?) => Message[] | false | Generate repair messages for a failed attempt |
instructions | (schema: ZodType) => string | Generate prompt text from a Zod schema |
createConsoleLogger | (options?) => ContractLogger<T> | Create a logger that prints to console |