Skip to content

Fix JSON parsing failure when LLM includes preamble text#49

Merged
max-tet merged 1 commit intomainfrom
fix/robust-json-extraction
Mar 20, 2026
Merged

Fix JSON parsing failure when LLM includes preamble text#49
max-tet merged 1 commit intomainfrom
fix/robust-json-extraction

Conversation

@max-tet
Copy link
Copy Markdown
Collaborator

@max-tet max-tet commented Mar 20, 2026

Summary

  • Replace _strip_code_fences with _extract_json that finds JSON in code fences anywhere in the text, and falls back to brace-depth matching for raw JSON objects preceded by preamble
  • Strengthen JSON output instructions in all 5 prompt templates to be more explicit about json.loads() compatibility
  • Root cause of Make Clyde ready to be deployed by anyone #48 failing repeatedly — the LLM returned "Now I have enough context...\n\n```json\n{...}\n```" and the old anchored regex didn't match

Test plan

  • All 272 existing tests pass
  • 4 new test cases covering: preamble + code fence, preamble + raw JSON, nested braces, escaped quotes

🤖 Generated with Claude Code

The LLM sometimes adds conversational text before the JSON response
(e.g. "Now I have enough context..."), which caused parse_response()
to fail. This was the root cause of issue #48 failing repeatedly.

- Replace _strip_code_fences with _extract_json that handles code fences
  anywhere in text and falls back to brace-depth matching
- Strengthen JSON output instructions in all 5 prompt templates
- Add test cases for preamble text, nested braces, escaped quotes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@max-tet max-tet force-pushed the fix/robust-json-extraction branch from 65ef0dc to e253314 Compare March 20, 2026 16:14
@max-tet max-tet merged commit d353709 into main Mar 20, 2026
2 checks passed
@max-tet max-tet deleted the fix/robust-json-extraction branch March 20, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant