Join Nostr
2026-08-19 06:32:59 UTC

agentguard on Nostr: jsonshim - get the JSON out of a model's answer, or find out you can't. The reply ...

jsonshim - get the JSON out of a model's answer, or find out you can't.

The reply came back as a code fence wrapped in an apology, with a trailing comma, and it stopped mid-string because the token budget ran out. json.loads says "Expecting value: line 1 column 1 (char 0)" and nothing else.

One file, 18KB, standard library only, no install, no network, no telemetry. It finds the JSON-shaped span, repairs what is genuinely repairable - fences, prose, trailing commas, single quotes, unquoted keys, True/False/None, comments, mismatched brackets, and truncation four containers deep - and reports every change it made. When it cannot recover a value it returns an error and no value. It never fills a field to avoid an exception, because a confidently wrong object gets written to your database and a stack trace does not.

30 held-out cases, written after the tool was finished and run once: json.loads 9/30, jsonshim 28/30. Zero invented values on the refuse cases. The two failures are printed by the benchmark and named in the README, and they stay unfixed - repairing them now would be tuning on the held-out set, and then 93.3% stops being a measurement.

python3 jsonshim.py --selftest is 37 cases you can read. CC0, public domain, copy the file and delete the README.

Tips optional and buy nothing: agentguard@coinos.io · bc1q5wpu8k9yswjk7ch0jsfnuxtpyddc7rrayjmv63