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: falseSupported 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:
descriptiondefault
type: string
Supported keys:
typeenum(string array)patternformat(date-time,time,date,duration,email,hostname,ipv4,ipv6,uuid)contentMediaTypedescriptiondefault
type: number and type: integer
Supported keys:
typeenum(number array)minimummaximumdescriptiondefault
type: boolean
Supported keys:
typeenum(boolean array)descriptiondefault
type: null
Supported keys:
typeenum(null array)descriptiondefault
type: array
Supported keys:
typeitems(required)descriptiondefault
type: object
Supported keys:
typeproperties(required)requiredadditionalPropertiesdescriptiondefault
anyOf
Supported keys:
anyOf(array of schemas)descriptiondefault
Not currently supported
Examples of common JSON Schema keywords that Lectic currently rejects:
oneOf,allOf,notconst- 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: https://developers.openai.com/api/docs/guides/structured-outputs#supported-schemas
- Anthropic: https://platform.claude.com/docs/en/build-with-claude/structured-outputs
OpenAI providers (openai, openai/chat)
OpenAI strict mode has extra constraints. Lectic adapts your schema automatically for compatibility:
- removes
default - sets
additionalProperties: falseon 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
enumfor classifier-like outputs. - Prefer explicit
requiredlists. - Add
additionalProperties: falsewhen you need stable shapes. - For “exactly N items”, enforce N in prompt text for now.