[TICK 3-001] Fix Trust Gate JSON parsing for markdown-fenced LLM responses#6
Merged
timeleft-- merged 3 commits intomainfrom Feb 25, 2026
Merged
Conversation
Trust gate _parse_verdict() fails when Gemini Flash wraps JSON in markdown code fences. Amend spec 3 and plan 3 with TICK-001 adding _extract_json_from_llm_response() utility and test coverage. Fixes #5 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add _extract_json_from_llm_response() sanitization utility to trust_gate.py that strips markdown code fences (```json or ```), leading/trailing whitespace, and extracts the first JSON object from preamble-wrapped responses before passing to json.loads(). Wire into _parse_verdict() to fix the bug where Gemini 2.5 Flash fence-wrapped responses caused validation_status: "error" instead of properly applying the reviewer's verdict. Add 8 new tests covering all sanitization paths. All 176 tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace npm run build / npm test (codev monorepo checks) with uv run pytest commands appropriate for this Python project. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
timeleft--
added a commit
that referenced
this pull request
Feb 27, 2026
…ate-json-parsing-fa [TICK 3-001] Fix Trust Gate JSON parsing for markdown-fenced LLM responses
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
_extract_json_from_llm_response()totrust_gate.pythat strips markdown code fences (```json/``` ``), leading/trailing whitespace, and extracts the first JSON object from preamble-wrapped responses before callingjson.loads()`_parse_verdict()(replacing barejson.loads(content)at line 223)review_thought()Root Cause
trust_gate.py:223calledjson.loads(content)directly on the raw LLM response. Gemini 2.5 Flash occasionally wraps its structured JSON output in markdown fences even whenresponse_format: json_objectis set, causing aJSONDecodeErrorat char 1. After the retry, the thought ended up withvalidation_status: "error"instead of the reviewer's actual verdict.Test plan
test_extract_json_fenced_with_lang_tag—```json ... ```test_extract_json_fenced_no_lang_tag—``` ... ```test_extract_json_leading_trailing_whitespacetest_extract_json_with_preamble_text— "Here is my response: {...}"test_extract_json_clean_no_fences— clean JSON passes unchangedtest_extract_json_genuinely_invalid— no JSON →json.loads()error preserved (fail-closed intact)test_extract_json_nested_braces— nested{}handled (first{to last})test_review_thought_fenced_json_response— end-to-end: fenced response → correct verdictFixes: Issue #5
🤖 Generated with Claude Code