Response Healing
Automatically fix malformed JSON responses
The Response Healing plugin automatically validates and repairs malformed JSON responses from AI models. When models return imperfect formatting – missing brackets, trailing commas, markdown wrappers, or mixed text – this plugin attempts to repair the response so you receive valid, parseable JSON.
Overview
Response Healing provides:
- Automatic JSON repair: Fixes missing brackets, commas, quotes, and other syntax errors
- Markdown extraction: Extracts JSON from markdown code blocks
How It Works
The plugin activates for non-streaming requests when you set text.format in a Responses API request (or response_format on Chat Completions) to either type: "json_schema" or type: "json_object", and include the response-healing plugin in your plugins array. See the Complete Example below for a full implementation.
What Gets Fixed
The Response Healing plugin handles common issues in LLM responses:
JSON Syntax Errors
Input: Missing closing bracket
{"name": "Alice", "age": 30Output: Fixed
{"name": "Alice", "age": 30}Markdown Code Blocks
Input: Wrapped in markdown
{"name": "Bob"}
Output: Extracted
{"name": "Bob"}Mixed Text and JSON
Input: Text before JSON
Here's the data you requested:
{"name": "Charlie", "age": 25}Output: Extracted
{"name": "Charlie", "age": 25}Trailing Commas
Input: Invalid trailing comma
{"name": "David", "age": 35,}Output: Fixed
{"name": "David", "age": 35}Unquoted Keys
Input: JavaScript-style
{name: "Eve", age: 40}Output: Fixed
{"name": "Eve", "age": 40}Complete Example
const response = await fetch('https://link-ora.net/api/v1/responses', {
method: 'POST',
headers: {
Authorization: 'Bearer <LINKORA_API_KEY>',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'google/gemini-2.5-flash',
input: 'Generate a product listing with name, price, and description',
text: {
format: {
type: 'json_schema',
name: 'Product',
schema: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'Product name'
},
price: {
type: 'number',
description: 'Price in USD'
},
description: {
type: 'string',
description: 'Product description'
}
},
required: ['name', 'price']
}
}
},
plugins: [
{ id: 'response-healing' }
]
}),
});
const data = await response.json();
const message = [...data.output].reverse().find((item: { type: string }) => item.type === 'message');
const text = message?.content.find((part: { type: string; text?: string }) => part.type === 'output_text')?.text;
if (text === undefined) {
throw new Error('No output_text in response');
}
// The plugin attempts to repair malformed JSON syntax
const product = JSON.parse(text);
console.log(product.name, product.price);Limitations
max_output_tokens, the plugin will not be able to repair it.