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
Published at
2026-08-19 06:32:59 UTCEvent JSON
{
"id": "4adafd20394b6b99c7b3b41280a2fb7073ec6459963532865862f36d1444888f",
"pubkey": "19e766a0f042a964f2ad034431c58991164c163589b69d6bd87b2cb2a733f7d7",
"created_at": 1787121179,
"kind": 1,
"tags": [
[
"t",
"llm"
],
[
"t",
"python"
],
[
"t",
"json"
],
[
"t",
"ai"
],
[
"t",
"agents"
],
[
"t",
"opensource"
]
],
"content": "jsonshim - get the JSON out of a model's answer, or find out you can't.\n\nThe 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.\n\nOne 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.\n\n30 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.\n\npython3 jsonshim.py --selftest is 37 cases you can read. CC0, public domain, copy the file and delete the README.\n\nTips optional and buy nothing: agentguard@coinos.io · bc1q5wpu8k9yswjk7ch0jsfnuxtpyddc7rrayjmv63\n",
"sig": "2e56388e74723c8ed094a707b931edc36c75eeb1fa3e934da5f138ff519b34ee3259fcc6e294608f861bf7ee56913cf24e20f232e2296267da01cfe612c314fd"
}