Jido.AI.Output (Jido AI v2.2.0)

Copy Markdown View Source

Structured final-output contracts for Jido.AI runtimes.

This module validates an agent's final response against an object-shaped schema. It is intentionally independent from any DSL layer: callers provide a Zoi object/map schema or an object-shaped JSON Schema map.

Summary

Functions

Adds output instructions to a ReqLLM message list.

Returns prompt instructions that require the final response to match the schema.

Converts the contract to JSON Schema.

Builds a structured output contract from options.

Builds a structured output contract or raises ArgumentError.

Parses and validates raw model output.

Repairs a raw assistant answer into the configured object shape.

Validates a parsed map against the configured schema.

Types

schema_kind()

@type schema_kind() :: :zoi | :json_schema

t()

@type t() :: %Jido.AI.Output{
  on_validation_error: validation_mode(),
  retries: non_neg_integer(),
  schema: Zoi.schema() | map(),
  schema_kind: schema_kind()
}

validation_mode()

@type validation_mode() :: :repair | :error

Functions

apply_instructions(messages, output)

@spec apply_instructions([map()], t() | nil) :: [map()]

Adds output instructions to a ReqLLM message list.

instructions(output)

@spec instructions(t() | nil) :: String.t() | nil

Returns prompt instructions that require the final response to match the schema.

json_schema(output)

@spec json_schema(t()) :: map()

Converts the contract to JSON Schema.

new(output)

@spec new(keyword() | map() | t() | nil) :: {:ok, t() | nil} | {:error, term()}

Builds a structured output contract from options.

new!(attrs)

@spec new!(keyword() | map() | t() | nil) :: t() | nil

Builds a structured output contract or raises ArgumentError.

parse(output, response)

@spec parse(t(), term()) :: {:ok, map()} | {:error, term()}

Parses and validates raw model output.

repair(output, raw, reason, context, opts \\ [])

@spec repair(t(), term(), term(), map(), keyword()) :: {:ok, map()} | {:error, term()}

Repairs a raw assistant answer into the configured object shape.

validate(output, value)

@spec validate(t(), term()) :: {:ok, map()} | {:error, term()}

Validates a parsed map against the configured schema.