Make Module 24 lab scripts tolerate code-fence-wrapped JSON #23

Closed
opened 2026-06-22 14:23:48 -04:00 by claude · 0 comments
Contributor

Problem

Both reviewer.py and triage.py call json.loads() directly on the saved AI response. Chat assistants very commonly wrap JSON in a ```json fence even when told to "return only the JSON." The canned samples are clean so the loop appears to work, but at the actual point of the lab (save the AI's JSON and apply it) the most likely real output fails with a controlled error ("could not read a JSON … Expecting value: line 1 column 1 (char 0)") and exit 1 — for a persona whose entire prior workflow is copy-pasting from a browser chat.

Evidence

modules/24-assistive-agents/lab/reviewer.py (~line 43): review = json.loads(Path(args.response).read_text()); modules/24-assistive-agents/lab/triage.py same (~line 52). README "do it for real" steps tell the persona to save the AI's JSON and apply it.
Reproduced: fenced JSON → error message + exit 1.

Why it matters

The module's central "do it for real" step is most likely to fail on the realistic output, while the clean canned samples hide it. The fix is vendor-agnostic robustness.

Proposed change

Before json.loads in both scripts, strip a leading/trailing ```json fence (or extract the first {...} block). triage.py already imports re; use stdlib only (no new deps). At minimum, also note in the README save step to delete fence lines first — but the in-script tolerant parse is the kinder fix since the persona hits this live.

Acceptance criteria

  • reviewer.py and triage.py parse both clean JSON and ```json-fenced JSON.
  • No new third-party dependency is added.

Affected files

  • modules/24-assistive-agents/lab/reviewer.py, modules/24-assistive-agents/lab/triage.py, modules/24-assistive-agents/README.md

References

Source finding F37 (realVotes 3/3).


Filed from an adversarial multi-agent course review (217 raw findings → 54 adversarially-verified survivors). Scoped for manual review; intentionally not auto-assigned to an agent.

## Problem Both `reviewer.py` and `triage.py` call `json.loads()` directly on the saved AI response. Chat assistants very commonly wrap JSON in a ```json fence even when told to "return only the JSON." The canned samples are clean so the loop appears to work, but at the actual point of the lab (save the AI's JSON and apply it) the most likely real output fails with a controlled error ("could not read a JSON … Expecting value: line 1 column 1 (char 0)") and exit 1 — for a persona whose entire prior workflow is copy-pasting from a browser chat. ## Evidence `modules/24-assistive-agents/lab/reviewer.py` (~line 43): `review = json.loads(Path(args.response).read_text())`; `modules/24-assistive-agents/lab/triage.py` same (~line 52). README "do it for real" steps tell the persona to save the AI's JSON and apply it. Reproduced: fenced JSON → error message + exit 1. ## Why it matters The module's central "do it for real" step is most likely to fail on the realistic output, while the clean canned samples hide it. The fix is vendor-agnostic robustness. ## Proposed change Before `json.loads` in both scripts, strip a leading/trailing ```json fence (or extract the first `{...}` block). `triage.py` already imports `re`; use stdlib only (no new deps). At minimum, also note in the README save step to delete fence lines first — but the in-script tolerant parse is the kinder fix since the persona hits this live. ## Acceptance criteria - [ ] `reviewer.py` and `triage.py` parse both clean JSON and ```json-fenced JSON. - [ ] No new third-party dependency is added. ## Affected files - `modules/24-assistive-agents/lab/reviewer.py`, `modules/24-assistive-agents/lab/triage.py`, `modules/24-assistive-agents/README.md` ## References Source finding F37 (realVotes 3/3). --- *Filed from an adversarial multi-agent course review (217 raw findings → 54 adversarially-verified survivors). Scoped for manual review; intentionally not auto-assigned to an agent.*
claude added the ai-readybugP1 labels 2026-06-22 14:23:48 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: justin/ai-workflow-course#23