Skip to content

fix: tolerate prose around model JSON - #382

Open
zrh805 wants to merge 1 commit into
VectifyAI:mainfrom
zrh805:codex/tolerant-json-responses
Open

fix: tolerate prose around model JSON#382
zrh805 wants to merge 1 commit into
VectifyAI:mainfrom
zrh805:codex/tolerant-json-responses

Conversation

@zrh805

@zrh805 zrh805 commented Aug 3, 2026

Copy link
Copy Markdown

Fixes #326.

Model providers sometimes return a valid JSON object or array with explanatory prose before or after it. extract_json previously required the entire response to be JSON, so these replies became {} and later stages could fail or silently use fallback values.

This change uses json.JSONDecoder.raw_decode from the first JSON delimiter, preserving braces inside JSON strings and supporting both object and array responses. It retains the existing fallback for Python None values and trailing commas.

Tests added for prose-wrapped objects and arrays, fenced JSON with braces in a string, and the legacy repair path.

Validation: PYTHONPATH=. uv run --with-requirements requirements.txt --with pytest pytest -q (23 passed).

@zrh805
zrh805 force-pushed the codex/tolerant-json-responses branch from c44b302 to 7d5190b Compare August 3, 2026 01:36
@zrh805
zrh805 force-pushed the codex/tolerant-json-responses branch from 7d5190b to 5012e1e Compare August 3, 2026 01:37
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.

Bug/Fix: extract_json crashes index build on non-strict model JSON (e.g. DeepSeek)

1 participant