Reference: Structured Outputs

Structured outputs let you constrain the assistant to JSON that matches a schema.

In Lectic, set interlocutor.output_schema to a JSON Schema object. You can also load the schema from file: or exec:; loaded text is parsed as YAML (so JSON files work) and then validated.

Lectic validates that schema before sending it to the provider.

If you are new to JSON Schema, start here: https://json-schema.org/learn

Minimal example

interlocutor:
  name: Assistant
  provider: openai
  model: gpt-5.2
  prompt: Return JSON only.
  output_schema:
    type: object
    properties:
      answer:
        type: string
    required: [answer]
    additionalProperties: false

Supported schema subset in Lectic

Lectic intentionally supports a focused subset. Unknown keys are rejected during validation.

Common keys

You can use these on any schema node:

  • description
  • default

type: string

Supported keys:

  • type
  • enum (string array)
  • pattern
  • format (date-time, time, date, duration, email, hostname, ipv4, ipv6, uuid)
  • contentMediaType
  • description
  • default

type: number and type: integer

Supported keys:

  • type
  • enum (number array)
  • minimum
  • maximum
  • description
  • default

type: boolean

Supported keys:

  • type
  • enum (boolean array)
  • description
  • default

type: null

Supported keys:

  • type
  • enum (null array)
  • description
  • default

type: array

Supported keys:

  • type
  • items (required)
  • description
  • default

type: object

Supported keys:

  • type
  • properties (required)
  • required
  • additionalProperties
  • description
  • default

anyOf

Supported keys:

  • anyOf (array of schemas)
  • description
  • default

Not currently supported

Examples of common JSON Schema keywords that Lectic currently rejects:

  • oneOf, allOf, not
  • const
  • string constraints like minLength, maxLength
  • array constraints like minItems, maxItems, uniqueItems
  • object constraints like patternProperties, dependencies

If you need these, encode constraints in prompt instructions or post-validate with a hook/tool script.

Provider behavior notes

Lectic validates your output_schema against Lectic’s supported subset first, then forwards it to the provider.

Provider docs for schema support and limitations:

OpenAI providers (openai, openai/chat)

OpenAI strict mode has extra constraints. Lectic adapts your schema automatically for compatibility:

  • removes default
  • sets additionalProperties: false on all objects
  • marks all object properties as required
  • rewrites optional fields as nullable (anyOf: [X, { type: null }])

Because of that rewrite, optional fields may come back as explicit null instead of being omitted.

Anthropic provider (anthropic, anthropic/bedrock)

Anthropic supports a provider-specific subset for structured outputs. Lectic transforms the schema before sending it so it conforms to Anthropic’s subset as closely as possible.

This helps keep one output_schema usable across providers, but final compatibility still depends on the target model. If a provider rejects a schema, simplify it to the intersection supported by your models.

Practical advice

  • Start with small object schemas and expand gradually.
  • Use enum for classifier-like outputs.
  • Prefer explicit required lists.
  • Add additionalProperties: false when you need stable shapes.
  • For “exactly N items”, enforce N in prompt text for now.