Skip to main content
Low-level building blocks exposed from @withboundary/contract. All are pure, synchronous, and side-effect free.
Usage guide: Engine primitives.

clean

Normalize raw LLM output into a parsed JSON value.

verify

Validate data against schema and, if provided, every rule. Returns the same ContractResult<T> shape contract.accept returns. No LLM involved.
  • result.ok === true → data passed schema and all rules. result.data is typed T.
  • result.ok === falseresult.error.attempts[0] has the failure category ("VALIDATION_ERROR" or "RULE_ERROR") and the list of issues.

classify

Categorize a failed response. Returns one of:
Based on the combination of raw string and parsed result:

repair

Generate repair messages for a failed attempt. Returns:
  • Message[] — messages to feed back to the model.
  • false — the category is disabled (via overrides[category] = false), caller should not retry.

overrides shape

  • false — skip retry for this category.
  • (detail) => Message[] — build custom repair messages for this category.

instructions

Generate prompt text from a Zod schema. Includes field types, enums, ranges, and .describe() annotations.
Called automatically inside contract.accept and available on attempt.instructions. The primitive does not take an options object. If you want to append stable text to the generated instructions used by contract.accept, configure the contract instead:

createConsoleLogger

Built-in human-readable logger. Implements the full ContractLogger surface and prints formatted traces to console.log.

ConsoleLoggerOptions

The debug: true option on defineContract / enforce is equivalent to logger: createConsoleLogger().

See also

Engine primitives guide

Recipes and custom pipelines

Testing contracts

Use verify() for unit tests