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:
- Try
serde_json::from_strdirectly — the fast path for valid JSON. - On failure, run
llm_json::loads, which repairs the string (markdown fences, trailing commas, unquoted keys, missing brackets) and parses it to aValuein a single pass. - Return an error only when
llm_jsonitself fails (an I/O or UTF-8 fault).llm_jsoncoerces aggressively — arbitrary text becomes a JSON string, empty input becomes{}, and a lone delimiter becomesnull— so callers MUST validate the returnedValue’s shape rather than relying onErrfor semantically-wrong-but-parseable input.