Skip to main content

repair_to_value

Function repair_to_value 

Source
pub fn repair_to_value(input: &str) -> Result<Value>
Expand description

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

Strategy:

  1. Try serde_json::from_str directly — the fast path for valid JSON.
  2. On failure, run llm_json::loads, which repairs the string (markdown fences, trailing commas, unquoted keys, missing brackets) and parses it to a Value in a single pass.
  3. Return an error only when llm_json itself fails (an I/O or UTF-8 fault). llm_json coerces aggressively — arbitrary text becomes a JSON string, empty input becomes {}, and a lone delimiter becomes null — so callers MUST validate the returned Value’s shape rather than relying on Err for semantically-wrong-but-parseable input.