output_schema_violation
The message text is shown in the example below.
⚠️
Preview — this feature is being built; the design below is the spec. Not in the public error catalog: planned for preview endpoints.
| HTTP status | 422 |
type | invalid_request_error |
| Retry? | No, not unchanged |
| Status | Preview |
| Extra fields | none |
When it happens
Structured output could not be made to match the supplied JSON schema within the retry budget.
Example
{
"error": {
"type": "invalid_request_error",
"code": "output_schema_violation",
"message": "The output could not be made to match the schema.",
"param": null,
"request_id": "req_6f1c2a9e0b7d4c3a8e5f1b2d"
}
}How to fix it
- Simplify the schema: fewer optional fields, no deep
anyOf. - Raise
max_tokensso the object is not cut off. - See Structured outputs.
Detect it in code
err = resp.json().get("error", {})
if resp.status_code == 422 and err.get("code") == "output_schema_violation":
log.warning("%s (%s)", err["message"], err["request_id"]) # fix the request; do not retry unchangedRelated
Was this page helpful?