fix(inference): stop dumping raw JSON into description on parse failure#66
Merged
Conversation
When the VLM emitted a SCENE_SCHEMA-shaped JSON but trio-core's
json.loads failed (truncation, no closing brace, malformed), the
fallback `desc = clean[:300]` was leaking 300-char raw JSON slices
into observations.description, ending mid-token. The downstream
substring-match fallback then guessed activity_level from random
words inside the JSON dump (e.g. "moderate" appearing as a value).
- Recognize lowercase `summary` (SCENE_SCHEMA) in the entities
branch so schema-mode outputs produce a clean description instead
of the "0 people, N vehicles: parked, …" parts template.
- On JSON parse failure (or JSON-shaped text with no closing brace),
return empty desc rather than raw garbage and emit a warning that
includes text length plus head/tail bytes so the truncation-vs-
malformed root cause is observable.
- Plain prose (no leading `{`) keeps the existing 300-char slice
behavior unchanged.
Tests cover: SCENE_SCHEMA summary path, truncated JSON, malformed
JSON, and plain prose.
0911a42 to
3d1c063
Compare
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
When the VLM emits a SCENE_SCHEMA-shaped JSON but
json.loadsfails (truncation, no closing brace, or malformed),_crop_describe_innerwas leaking a 300-char raw JSON slice intodescription— observable as DB rows like:(ending mid-token at exactly 300 chars). The downstream substring-match fallback then guessed
activity_levelfrom random words inside the JSON dump, producing rows where the structured columns were inferred from JSON literals rather than the model's actual output.Changes
summary(the SCENE_SCHEMA contract) in the entities branch so schema-mode outputs produce a clean description instead of the"0 people, N vehicles: parked, …"parts template.summaryis read withoutpopso callers re-parsing entities still see it.json.loadsfails, or when text starts with{but has no closing}(truncation), returndesc = ""instead ofclean[:300].{) keeps the existing 300-char slice behavior unchanged.Test plan
test_inference_router.pypass unchanged.summarypopulates description, summary preserved in entities.desc="", warning logged withtruncation suspected.desc="", warning logged withJSON parse failed.crop_describe: JSON parse failed/truncation suspectedwarnings appear in/tmp/vlm.logand pin the root cause (likelymax_tokens=512default for SCENE_SCHEMA payloads with multi-vehicle arrays).Notes
This addresses the symptom only. The next step is using the new diagnostic logs to determine the failure mode and either bump
max_tokens(currentlyengine.config.max_tokens=512and not overridden in_crop_describe_inner) or fix the specific malformation. ~500 existing JSON-stringdescriptionrows in prod are not backfilled by this change.🤖 Generated with Claude Code