Skip to content

fix(llm): make JSON extraction string-aware so braces in text cannot drop findings#151

Merged
Liohtml merged 1 commit into
mainfrom
claude/dependabot-prs-q6u94z
Jul 10, 2026
Merged

fix(llm): make JSON extraction string-aware so braces in text cannot drop findings#151
Liohtml merged 1 commit into
mainfrom
claude/dependabot-prs-q6u94z

Conversation

@Liohtml

@Liohtml Liohtml commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Summary

parse_llm_json counted braces without tracking string context, so any } inside a JSON string value — entirely plausible in an LLM's free-text overall_impression/findings — truncated the object mid-string. The resulting decode error was swallowed by parse_llm_response, which fell back to treating the whole response as plain text: all structured findings silently discarded.

Fixes #136

Changes

  • src/medcheck/llm/base.py: parse_llm_json now uses json.JSONDecoder().raw_decode (string/escape-aware), trying candidate { positions in order until one decodes to an object — this also recovers when a stray { appears in prose before the real JSON, which the old scanner could not
  • tests/unit/test_llm/test_base.py: 3 new tests — braces inside string values, stray { before the object, markdown-fenced JSON

Testing

  • Existing tests pass (uv run pytest) — 175 passed (all existing parser tests unchanged and green)
  • New tests added for new functionality — 3 new parser tests
  • Coverage does not decrease (uv run pytest --cov-fail-under=85) — 87.23%
  • Linting passes (uv run ruff check .)
  • Type checking passes (uv run mypy src/medcheck --strict)
  • Pre-commit hooks pass — ruff hooks pass locally; full pre-commit not run

Additional Notes

Error behavior is unchanged for genuinely JSON-free responses: parse_llm_json still raises ValueError and parse_llm_response still falls back to raw text.

🤖 Generated with Claude Code

https://claude.ai/code/session_01W4svt5QTs4WUMSy4HwiVt9


Generated by Claude Code

…drop findings

parse_llm_json counted braces without tracking string context, so any
'}' inside a JSON string value truncated the object mid-string; the
resulting decode error was swallowed upstream and the whole structured
result (all findings) was silently discarded, leaving only raw text.
Use json.JSONDecoder().raw_decode, trying candidate '{' positions in
order — string/escape aware, and also recovers when a stray '{'
precedes the real object.

Fixes #136

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W4svt5QTs4WUMSy4HwiVt9
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Liohtml, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 39 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5807a6d6-ea3c-4cf8-ae16-0acd45f753b5

📥 Commits

Reviewing files that changed from the base of the PR and between 63a57ac and a76c6af.

📒 Files selected for processing (2)
  • src/medcheck/llm/base.py
  • tests/unit/test_llm/test_base.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/dependabot-prs-q6u94z

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Liohtml Liohtml merged commit 9592f2e into main Jul 10, 2026
13 checks passed
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

[repo-health] Medium: parse_llm_json brace scanner is not string-aware — a "}" inside a JSON string silently discards all structured findings

2 participants