> ## Documentation Index
> Fetch the complete documentation index at: https://docs.arouter.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Response Healing

> ARouter automatically repairs malformed JSON responses when using json_schema or json_object response formats. No changes needed in your application.

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

| 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 the `plugins` array:

```json theme={null}
{
  "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:

```json theme={null}
{
  "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.

## Related

* [Structured Outputs](/en/guides/features/structured-outputs) — Using `json_schema` for guaranteed schema compliance
* [Plugins Overview](/en/guides/features/plugins-overview) — All available plugins
