Skip to main content
Response Healing is an automatic post-processing step that fixes malformed JSON in model responses. When you request structured output via 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:
  1. response_format is set to json_schema or json_object
  2. The response body is valid UTF-8 but contains fixable JSON syntax errors
It does not activate for plain text responses, streaming responses, or responses that are correctly-formed JSON.

What Gets Fixed

ProblemExampleFixed
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 + JSONSure! Here's the data: {"id": 1}{"id": 1}
Single-quoted strings{'key': 'value'}{"key": "value"}

What Cannot Be Fixed

ProblemReason
Truncated JSON (incomplete)Missing data — cannot reconstruct safely
Semantically wrong structureOutput doesn’t match your schema — model error
Binary/non-UTF-8 dataNot JSON at all

Enabling Response Healing

Response Healing is enabled by default when using structured output formats. You can also enable it explicitly via the plugins array:
{
  "model": "openai/gpt-5.4",
  "messages": [{"role": "user", "content": "Extract the user info from: John Doe, age 30, NYC"}],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "user_info",
      "schema": {
        "type": "object",
        "properties": {
          "name": {"type": "string"},
          "age": {"type": "integer"},
          "city": {"type": "string"}
        },
        "required": ["name", "age", "city"]
      }
    }
  },
  "plugins": [{"id": "response-healing"}]
}

Detecting Healed Responses

When a response was repaired, the response includes a flag in the metadata:
{
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "{\"name\": \"John Doe\", \"age\": 30, \"city\": \"NYC\"}"
      },
      "finish_reason": "stop"
    }
  ],
  "x_arouter": {
    "response_healed": true
  }
}

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.