Signature
ContractConfig<T>
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
schema | ZodType<T> | Yes | — | Zod schema defining the expected output structure |
rules | Rule<T>[] | No | [] | Domain correctness rules. Each rule is (data: T) => true | string |
retry | RetryOptions | No | { maxAttempts: 3 } | Retry behavior on failure |
repairs | RepairOverrides | No | — | Custom repair strategies per failure category |
instructions | { suffix?: string } | No | — | Append text to auto-generated schema prompt |
onAttempt | AttemptHook | No | — | Called after each attempt |
logger | ContractLogger<T> | No | — | Hook into execution lifecycle events |
debug | boolean | No | false | Shorthand for enabling createConsoleLogger() |
DefinedContract<T>
The returned contract object has one method:.accept(run, overrides?)
ContractResult<T>.
The optional overrides let you override any config option at call time. Definition-time options are the defaults; runtime options take precedence.
RetryOptions
| Strategy | Delay pattern |
|---|---|
"none" | No delay between retries |
"linear" | baseMs * attemptNumber |
"exponential" | baseMs * 2^attemptNumber |
RepairOverrides
Override or disable repair for specific failure categories:false to skip retrying for that category. Provide a function to generate custom repair messages.