LLM to JSON Cleaner repairs malformed JSON returned by language models. It strips markdown code fences, trailing commas, and comments, then validates against an optional JSON Schema. Aggressive mode infers missing closing brackets in truncated outputs. Returns a 0-1 repair confidence score so agents can decide whether to auto-accept the result or escalate to a human reviewer.
LLM to JSON Cleaner
Repair malformed JSON from LLM responses with confidence scoring
Strips markdown fences, // and /* */ comments, and trailing commas.
How to use
- Paste raw LLM output — Drop in the unparsed string with markdown fences, comments, or trailing commas.
- Choose repair strategy — Conservative strips fences and commas. Aggressive also infers missing closing brackets.
- Add a target schema (optional) — Provide a JSON Schema object for one-call validation alongside repair.
- Check repair confidence — A score of 1.0 means only whitespace was changed. Below 0.5 means structural repairs occurred.
- Inspect transformations — Each repair is logged with type, description, and position so you can audit the changes.
MCP / API
Call llm_to_json_cleaner directly from any MCP-compatible agent:
// MCP TypeScript SDK
const result = await client.callTool({
name: "llm_to_json_cleaner",
arguments: {
"raw": "..."
}
});
// curl
curl -X POST https://obfus.link/mcp \
-H "Authorization: Bearer <SPT>" \
-H "Content-Type: application/json" \
-d '{"method":"tools/call","params":{"name":"llm_to_json_cleaner","arguments":{"raw":"..."}}}'Related tools
FAQ
What is the repairConfidence score?
A 0-1 float that indicates how much the cleaner deviated from the original input. 1.0 means only whitespace or fences were stripped. Below 0.5 means structural repairs (bracket closing, value inference) were applied — the result should be human-reviewed before being trusted in a pipeline.
When should I use aggressive vs conservative repair?
Conservative is the default and only handles cosmetic issues (markdown fences, trailing commas, comments). Aggressive additionally infers missing closing brackets — useful for truncated LLM output but riskier because it guesses structure. Default to conservative; escalate to aggressive only when conservative fails.
How does targetSchema validation work?
Provide a JSON Schema (or Zod-compatible schema) and the cleaner runs validation after repair. Schema errors are returned alongside the cleaned JSON, giving you both the parsed value and a list of fields that violated the contract — without a second tool call.
Can I use this tool via the MCP API?
Yes. The tool is registered on the obfus.link MCP server at https://obfus.link/mcp. Call it from any MCP-compatible agent with a Shared Payment Token. The MCP tool name matches the snake_case slug shown in the integration snippet.