Skip to main content
Glama

Repair broken JSON (LLM output) and list the fixes

repair_json
Read-onlyIdempotent

Turn broken or messy JSON text into valid JSON. Strips Markdown code fences and prose before/after the JSON, removes comments and trailing commas, converts single/curly quotes, quotes unquoted keys, maps Python None/True/False, inserts missing commas, closes truncated strings/arrays/objects, and wraps NDJSON / several concatenated objects into one array. Returns the parsed value (json), the repaired text, and the list of fixes applied; valid input passes through unchanged with no fixes. Optional schema (+ coerce) also validates the result. Fails with isError (code unrepairable / no_json_found) when nothing JSON-like can be recovered. Pure computation: read-only, no network access, inputs not stored. Same engine and limits as POST /api/v1/repair.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
draftNoJSON Schema draft. Default: from the schema's $schema, else 2020-12.
inputYesThe raw (possibly broken) JSON text, e.g. an LLM reply with code fences and prose around the JSON. Max 102,400 bytes (UTF-8).
coerceNoConvert values toward the schema's declared types before validating: "42" → 42, "true" → true, "null" → null, 5 → "5", x → [x]. Each change is listed in coercions.
formatNoLayout of the returned text: compact (default), pretty (2-space indent), or preserve (jsonrepair's output, keeps original spacing and long-number digits).compact
schemaNoA JSON Schema (draft 2020-12 by default; 2019-09, 7 and 4 also supported). Only local $refs (#/...) resolve; remote $refs are an error. Max 32 KB.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
okYes
jsonYesThe repaired JSON value (coerced if coerce was used)
planNo
fixesYes
formatNo
schemaNo
valuesNoNumber of top-level JSON values found (more than 1 = wrapped in an array)
changedYesfalse when the input was already valid JSON
versionNo
warningsNo
inputBytesNo
outputBytesNo
inputWasValidYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.1/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Goes well beyond the annotations: discloses the exact failure codes (unrepairable / no_json_found) via isError, the return payload contents, the no-network/no-storage guarantee, and the shared engine and limits with POST /api/v1/repair. That is the kind of mutation-free, idempotent behavioral contract an agent needs.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Information-dense rather than padded: the repair list is front-loaded, then returns, then error behavior, then the purity/limits note. The long enumeration of repairs is justified by the breadth of the tool, though it makes the paragraph dense enough to be borderline.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With an output schema present, the description does not need to explain return values in detail, yet it still names them. Combined with error semantics, idempotency, input limits and the purity guarantee, an agent has everything needed to call this correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents input, schema, coerce, draft and format with examples. The description adds only a light interaction note ('optional schema (+ coerce) also validates the result') and no syntax or format guidance beyond the schema, so the baseline 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource (repair broken JSON text) and enumerates the concrete repair classes it performs, so the agent knows exactly what transformation happens. It does not explicitly name or contrast with the sibling validate_json, though the line about optional schema validation hints at the overlap.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives clear context for when to reach for it (broken or messy JSON, e.g. an LLM reply with fences and prose) and states that valid input passes through unchanged, which tells the agent it is safe to call speculatively. It never explicitly routes the agent to validate_json for pure validation, so no exclusion is given.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources