response_format, some providers occasionally return slightly broken JSON — Response Healing silently repairs it before returning the response to your application.
When It Activates
Response Healing only activates when both conditions are met:response_formatis set tojson_schemaorjson_object- The response body is valid UTF-8 but contains fixable JSON syntax errors
What Gets Fixed
| Problem | Example | Fixed |
|---|---|---|
| Markdown code blocks | ```json\n{"key": "value"}\n``` | {"key": "value"} |
| Trailing commas | {"a": 1, "b": 2,} | {"a": 1, "b": 2} |
| Unquoted keys | {key: "value"} | {"key": "value"} |
| Mixed text + JSON | Sure! Here's the data: {"id": 1} | {"id": 1} |
| Single-quoted strings | {'key': 'value'} | {"key": "value"} |
What Cannot Be Fixed
| Problem | Reason |
|---|---|
| Truncated JSON (incomplete) | Missing data — cannot reconstruct safely |
| Semantically wrong structure | Output doesn’t match your schema — model error |
| Binary/non-UTF-8 data | Not JSON at all |
Enabling Response Healing
Response Healing is enabled by default when using structured output formats. You can also enable it explicitly via theplugins array:
Detecting Healed Responses
When a response was repaired, the response includes a flag in the metadata:Limitations
- Non-streaming only — Response Healing requires the full response body to be available before repair can be attempted. It is not applied to streaming responses.
- Will not repair all JSON — Truncated output (e.g. from hitting
max_tokens) cannot be completed. - Schema validation — Healing fixes syntax errors, not semantic errors. A healed response still needs to pass your own schema validation.
Related
- Structured Outputs — Using
json_schemafor guaranteed schema compliance - Plugins Overview — All available plugins