Structured Output
JSON schema validation and retry on parse failure.
Structured output ensures model responses conform to a JSON schema before returning to your application. Eridian validates output at the gateway so downstream systems receive typed, parse-safe payloads without custom post-processing in every service.
Configuration
Add structured_output to any inference request:
{
"model": "auto",
"project_id": "prj_legal_001",
"messages": [
{ "role": "user", "content": "Extract risks from this contract clause." }
],
"structured_output": {
"schema": {
"type": "object",
"properties": {
"risks": {
"type": "array",
"items": { "type": "string" }
},
"severity": { "type": "string", "enum": ["low", "medium", "high"] }
},
"required": ["risks", "severity"],
"additionalProperties": false
},
"retry_on_failure": true,
"max_retries": 2
}
}
Fields
| Field | Type | Default | Description |
|---|---|---|---|
schema | object | - | JSON Schema draft-07 subset enforced on model output |
retry_on_failure | boolean | false | Re-invoke model with parse error feedback on validation failure |
max_retries | integer | 2 | Maximum retry attempts after parse failure |
strict | boolean | true | Reject responses with properties not in schema when additionalProperties: false |
Retry on Parse Failure
When retry_on_failure is enabled, Eridian re-invokes the model with parse error feedback if the response fails schema validation. Each retry is logged as a separate span in OpenTelemetry traces. Responses include:
eridian.structured_output_valid-truewhen final payload passed validationeridian.structured_output_retries- count of retry attempts
Response Shape
Validated structured output appears in choices[0].message.content as a JSON string and in choices[0].message.parsed as a native object when using official SDKs:
{
"choices": [{
"message": {
"role": "assistant",
"content": "{\"risks\":[\"Indemnification cap missing\"],\"severity\":\"high\"}",
"parsed": {
"risks": ["Indemnification cap missing"],
"severity": "high"
}
}
}],
"eridian": {
"structured_output_valid": true,
"structured_output_retries": 0
}
}
Custom Parsers
Enterprise customers can register custom parsers for domain-specific output formats (FIX messages, SWIFT MT fields, internal JSON dialects). Custom parsers run after default JSON schema validation:
POST /v1/parsers
Authorization: Bearer eridian_sk_...
Parser registration requires governance:manage scope. Parser IDs attach to templates for repeatable workflows.
Caching Interaction
Structured output requests are excluded from semantic cache by default because near-identical prompts may require different schema shapes. Opt in with cache_config.allow_structured_output: true only when schemas are stable and false-positive cache hits are acceptable.
Error Codes
| HTTP | Code | Meaning |
|---|---|---|
| 400 | invalid_schema | Schema not supported or malformed |
| 422 | structured_output_failed | Validation failed after all retries |
| 503 | model_unavailable | No model in pool supports structured output for schema |
See Inference for the core request envelope and Semantic Caching for cache exclusion rules.
Production API credentials are issued with an institution workspace. Contact sales if you need access.