Skip to main content
Glama

Repair broken JSON text

repair_json_text
Read-onlyIdempotent

Repair broken or incomplete JSON text, including model output with missing quotes, trailing commas, or cut-off brackets, and return the corrected value or confirm it was already valid.

Instructions

Repair broken or incomplete JSON, including output from language models.

Use this when you have JSON in the conversation that may be missing quotes, have trailing commas, or be cut off. It is plain code, not an AI model: it can close missing brackets and fix common syntax issues, but it cannot invent the data you meant to write. Already-valid JSON is returned as-is, with wasValid true and repaired false. Do not use it for a file on disk (use repair_json_file for files).

json_lines: if true, each non-empty line is a separate document. If false (default), the whole text is tried as one JSON value first. If that cannot be repaired and there are several lines, each line is then tried on its own.

For one document, returns {"wasValid", "repaired", "value", "text"}. For several documents, returns {"count", "failed", "documents": [...]}.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "text": "<text>"
    },
    "name": "repair_json_text"
  }
}

Input Schema

NameRequiredDescriptionDefault
textYesThe JSON text to repair. May be one value, or several JSON Lines.
json_linesNoIf true, treat each non-empty line as its own JSON document.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.9/5.0
Behavior5/5

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

Beyond the annotations (readOnly, idempotent, non-destructive), it discloses the processing contract: deterministic code rather than a model, cannot invent missing data, valid input passes through as-is with wasValid=true and repaired=false, and the per-document failure reporting in json_lines mode. That sets expectations an agent could not derive from the annotation flags.

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?

It is front-loaded (purpose, then usage, then exclusion, then parameter behavior, then return shapes) and every block carries information. The json_lines paragraph is slightly long-winded, but since there is no output schema the return-shape sentences are not waste.

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?

For a two-parameter, non-destructive utility with no output schema, the description covers purpose, routing, limitations, parameter edge behavior, and both return shapes. An agent has everything it needs to call it correctly and interpret results.

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

Parameters5/5

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

Schema coverage is 100%, so the baseline would be 3, but the description adds non-obvious semantics for json_lines: default false means whole-text-first with per-line fallback, while true means each non-empty line is its own document. That fallback behavior is meaningfully beyond the one-line schema text.

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

Purpose5/5

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

It names a specific verb and resource ('repair broken or incomplete JSON') and scopes it to a concrete input class (text in the conversation, including LLM output). It explicitly distinguishes itself from the sibling repair_json_file, so an agent can route without opening either schema.

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

Usage Guidelines5/5

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

It gives an explicit when-to-use condition ('when you have JSON in the conversation that may be missing quotes, have trailing commas, or be cut off') and an explicit when-not plus the named alternative ('Do not use it for a file on disk (use repair_json_file for files)').

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