Repository navigation
fix(utils): find JSON after placeholder braces in model output - #4332
Conversation
Structured extraction returned nothing when the model wrote a placeholder
like "{field}" before its JSON, because only the first "{" was ever tried.
The parser now resumes after an invalid span, but never inside one, so a
malformed or truncated object still yields None rather than a fragment.
Adds table tests for extract_json_from_text (fenced code, arrays of
objects, brackets inside strings, trailing text, truncation) and pins the
SD prompt text to LemonadeClient.SD_MODEL_DEFAULTS so the size/steps/cfg
the model is told to use can't drift from the real defaults.
Part of amd#4257
|
Verdict: Approve with suggestions The fix works — the parser now skips past a The PR promises that broken model output returns nothing rather than a misleading fragment, but that promise only holds when the broken part and the fragment are the same kind of bracket. If a truncated object contains a list, the parser still hands back that inner list as if it were the whole answer — exactly the "looks like a complete answer" failure the PR set out to prevent. The new tests don't catch it because every "must return nothing" case uses only curly braces. This is pre-existing behaviour on Nothing else blocking. No security concerns. Real-world evidenceN/A — no user-facing surface here (a parsing helper plus two new unit-test files), and no 🔍 Technical detailsIssues🟡 Fragment leak survives across bracket types ( When a balanced span parses invalidly, only that bracket type's cursor is advanced past The last two are the array-flavoured twins of Advancing every cursor that sits inside the failed span closes it. Keep the Termination still holds: the selected Worth adding to pytest.param('{"a": [1, 2], oops}', id="malformed-outer-object-around-array"),
pytest.param('{"a": [1, 2], "b": ', id="truncated-outer-object-around-array"),🟢 Private registry access in the SD test (
Strengths
|
Document and image extraction failed whenever the model wrote a placeholder such as
{field}before its JSON answer: the parser only tried the first{, gave up, and the extraction raised "did not parse". It now moves past an invalid span and finds the real JSON. It still never looks inside a broken object, so truncated or malformed output returns nothing instead of a misleading fragment. Also adds table tests for the JSON parser behind every VLM extraction path, and tests that pin the Stable Diffusion prompt text to the real per-model defaults so the size, steps, and CFG the model is told to use can't drift from them.Covers the parser and SD-prompt parts of #4257. Chunking and cache-clearing are in #4262 and #4260.
deltas_cli,code_bench_fixtures, and the TUI flag wiring already had tests.talk/app.pyis left out because it needs a design decision (see the issue).Test plan
python -m pytest tests/unit/test_parsing.py: 2 placeholder cases fail onmain, 13/13 pass with the fixpython -m pytest tests/unit/test_parsing.py tests/unit/test_sd_prompts.py tests/unit/test_file_watcher.py tests/unit/test_structured_vlm_extraction.py tests/unit/test_vlm_extraction_failures.py tests/unit/test_sd_mixin.py tests/unit/test_sd_error_messages.py hub/agents/gaia/python/tests/test_sd_tools_do_not_rewrite_the_prompt.py: 176 passed, 3 skippedpython util/check_test_lane_coverage.pydoes not flag either new file (thepytest tests/unit/lane runs them)Part of #4257