Fix JSON parsing failure when LLM includes preamble text#49
Merged
Conversation
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>
65ef0dc to
e253314
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_strip_code_fenceswith_extract_jsonthat finds JSON in code fences anywhere in the text, and falls back to brace-depth matching for raw JSON objects preceded by preamblejson.loads()compatibility"Now I have enough context...\n\n```json\n{...}\n```"and the old anchored regex didn't matchTest plan
🤖 Generated with Claude Code