Tolerate trailing data in LLM JSON responses - #34
Merged
Conversation
Pass 4 (and any call) failed with "Extra data: line N column 1" when a model
returned a complete JSON value followed by extra content — a second object, a
trailing note, or a stray fence — which json.loads rejects. Gemini's judge
calls request responseMimeType=application/json, so the response had no fences
and went straight to json.loads with no recovery path. At temperature 0 the
bad output is deterministic, so all retries reproduced it and the article was
dropped.
Add a shared _parse_json_response() used by both the Gemini and
OpenAI-compatible callers: strip code fences, skip leading prose to the first
'{'/'[', and use json.JSONDecoder().raw_decode() so bytes after the first
complete value are ignored. Genuinely malformed output still raises
JSONDecodeError so the existing retry loop is unaffected.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01669jmknuhhZY3vBqwpDWvF
Pass 0 paragraph triage decided category relevance from only the first 120 chars of each paragraph, so bias signal past the opening sentence was invisible and triage systematically under-selected. Double the preview window to 240 chars to give the triage model more of each paragraph to judge against. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01669jmknuhhZY3vBqwpDWvF
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.
Pass 4 (and any call) failed with "Extra data: line N column 1" when a model returned a complete JSON value followed by extra content — a second object, a trailing note, or a stray fence — which json.loads rejects. Gemini's judge calls request responseMimeType=application/json, so the response had no fences and went straight to json.loads with no recovery path. At temperature 0 the bad output is deterministic, so all retries reproduced it and the article was dropped.
Add a shared _parse_json_response() used by both the Gemini and OpenAI-compatible callers: strip code fences, skip leading prose to the first '{'/'[', and use json.JSONDecoder().raw_decode() so bytes after the first complete value are ignored. Genuinely malformed output still raises JSONDecodeError so the existing retry loop is unaffected.
Claude-Session: https://claude.ai/code/session_01669jmknuhhZY3vBqwpDWvF