Inference.ResponseFormat (inference v0.3.0)

Copy Markdown View Source

Provider-neutral response format.

The union is closed. A request either leaves the format unspecified (nil) or declares exactly one of:

  • :text — plain assistant text.
  • {:json, :object} — schemaless JSON object mode.
  • {:json_schema, %{name: name, schema: schema, strict: strict?}} — a named schema the provider must conform to.

Every adapter either maps the declared format onto a real provider option or refuses it with Inference.Error.response_format_unsupported/2. Silently dropping a declared format is a contract violation, not a fallback.

Summary

Functions

Returns true when the format asks the provider for JSON output.

Normalizes a caller-supplied response format into the closed union.

Types

json_schema()

@type json_schema() :: %{
  name: String.t(),
  schema: map() | keyword(),
  strict: boolean()
}

t()

@type t() :: :text | {:json, :object} | {:json_schema, json_schema()}

Functions

json?(arg1)

@spec json?(t() | nil) :: boolean()

Returns true when the format asks the provider for JSON output.

normalize(other)

@spec normalize(term()) :: {:ok, t() | nil} | {:error, Inference.Error.t()}

Normalizes a caller-supplied response format into the closed union.

nil stays nil and means "unspecified". Anything outside the union is an :invalid error with reason :response_format.