Skip to main content
Glama

Repair malformed JSON from a model

fix_json

Repair malformed JSON from LLMs by removing code fences, prose, trailing commas, smart quotes, single quotes, and unquoted keys. Returns clean parsed JSON with repairs or closest error.

Instructions

Best-effort repair of broken JSON (code fences, trailing commas, smart quotes, unquoted keys, single quotes, prose around the object, bare words). Returns the parsed value as clean JSON plus a list of the repairs applied — or, if unrepairable, the error and the closest candidate. Call this before re-asking the model.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesthe raw broken JSON text

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A4.3/5.0
Behavior4/5

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

With no annotations, the description carries the full burden and does so well: it discloses the best-effort (non-guaranteeing) nature, the exact failure modes tolerated, and both success and failure return behavior including the 'closest candidate' fallback. Missing only explicit side-effect/purity or size-limit notes, which keeps it from a 5.

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

Conciseness5/5

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

Two dense sentences with zero filler; the core purpose and the threshold detail (failure list) are front-loaded, and the workflow instruction closes it compactly.

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 one-parameter, annotation-free transform with no output schema, the description covers what the tool does, what it tolerates, what it returns on success, and what it returns on failure. An agent has everything needed to call it and interpret the result.

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 coverage is 100% and the single param is documented as "the raw broken JSON text", so the schema does the heavy lifting. The description adds no syntax or format detail beyond that, making the baseline 3 appropriate.

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?

States a specific verb (repair) and resource (broken JSON), and enumerates the concrete failure classes it handles (code fences, trailing commas, smart quotes, unquoted keys, single quotes, prose, bare words). An agent can tell at a glance this is a text-repair transform, distinct from the sibling check_keys.

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?

"Call this before re-asking the model" gives clear, actionable placement in the workflow. It does not name a when-not condition or explicitly contrast with check_keys, but no competing tool overlaps the repair function, so guidance is effectively complete.

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

Deploy Server

Other Tools