From 2b3b6e8dfdb292555d1b53c426fd0246a35414b3 Mon Sep 17 00:00:00 2001 From: type-two Date: Sat, 18 Jul 2026 21:31:04 +1000 Subject: [PATCH] distill: salvage well-formed strings from malformed writer arrays Co-Authored-By: Claude Fable 5 --- distill.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/distill.py b/distill.py index 8b521e7..570f444 100755 --- a/distill.py +++ b/distill.py @@ -96,7 +96,15 @@ def ask_writer(persona, topic, refs): start = txt.find("[") if start < 0: raise ValueError(f"no JSON array in writer output: {txt[:200]}") - arr, _ = json.JSONDecoder().raw_decode(txt[start:]) + try: + arr, _ = json.JSONDecoder().raw_decode(txt[start:]) + except json.JSONDecodeError: + # salvage: models sometimes break an array element mid-list; + # harvest the well-formed quoted strings instead of losing all 12 + arr = [json.loads(f'"{m}"') for m in + re.findall(r'"((?:[^"\\]|\\.){8,300})"', txt[start:])] + if not arr: + raise except (ValueError, json.JSONDecodeError) as e: last_err = e continue