Skip to main content

Module json_repair

Module json_repair 

Source
Expand description

v1.0.97: repairs malformed JSON from OpenRouter chat models (markdown code fences, trailing commas, unquoted keys) before parsing into a serde_json::Value. JSON repair for malformed LLM responses (v1.0.97).

OpenRouter chat models — notably deepseek/deepseek-v4-flash:nitro, which does not reliably honour json_schema strict mode — frequently wrap their output in markdown code fences, leave trailing commas, or omit quotes around keys. This module parses such payloads defensively: a strict serde_json pass runs first so well-formed responses pay zero repair cost, and only on failure does the llm_json repair pass (a Rust port of the Python json_repair library) run before a second parse attempt.

Functions§

repair_to_value
Parse input into a serde_json::Value, repairing common LLM JSON defects when a strict parse fails.