Contract library types
All exported from@withboundary/contract.
ContractResult<T>
The return type of every contract call. Discriminated union onok.
ContractAttempt
Passed to yourRunFn on each attempt.
ContractError
AttemptDetail
FailureCategory
Rule<T>
check returns true when the data is correct. It returns false or a string when the rule fails. A string return becomes the failure message for that specific attempt; otherwise Boundary uses message when provided.
Use stable name values for dashboards, metrics, and ruleIssues. Use description as the human label. Use fields when a rule maps cleanly to one or more output fields.
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. Every context object includescontractName and runHandle so one logger can serve multiple contracts and correlate hooks from the same run.
ConsoleLoggerOptions
createConsoleLogger.
Engine primitives
Lower-level functions for advanced use cases. All pure and side-effect-free.| Function | Signature | Description |
|---|---|---|
clean | (raw: string | null | undefined) => unknown | Extract and normalize JSON from raw LLM output |
verify | <T>(data: unknown, schema: ContractSchema<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: ContractSchema<unknown>) => string | Generate prompt text from a Zod schema |
createConsoleLogger | (options?) => ContractLogger<T> | Create a logger that prints to console |
SDK types
All exported from@withboundary/sdk.
@withboundary/contract also exports a BoundaryLogEvent type for contract-level logger integrations. The SDK’s BoundaryLogEvent below is the hosted ingest event used by createBoundaryLogger, beforeSend, and custom write sinks.
BoundaryLogger<T>
The object returned bycreateBoundaryLogger. Implements every ContractLogger<T> hook and adds drain controls.
BoundaryLoggerOptions
Full options shape forcreateBoundaryLogger. See createBoundaryLogger for a per-field table with defaults.
BoundaryLogEvent
The wire format shipped to the ingest endpoint. A tagged union onok — AcceptedEvent (always terminal) or FailedEvent (one per non-terminal attempt plus the terminal one). See BoundaryLogEvent for examples and lifecycle.
CapturePolicy
category, issues, ruleFailures) and run metadata are always sent on the wire — they are not gated by a capture flag.
RedactionOptions
BoundaryEnvironment
BoundaryLogEvent.environment) is string so the server accepts future names without an SDK bump; the SDK’s input type is the narrow union to prevent typos like "prod" or "stg" that would fragment dashboards.
Transport
Low-level extension point. Typical users don’t implement this — they passwrite instead.