Constrain vision output with a JSON Schema so per-field confidences survive - #47
Merged
Merged
Conversation
…urvive
The vision call used format="json", which only guarantees valid JSON, not
our nested {value, confidence} shape. Smaller models (qwen2.5vl:3b) collapse
each field to a bare scalar, so _parse_field defaulted every confidence to
0.5 — silently destroying the signal that drives low-confidence review.
Build a JSON Schema from the canonical src/schema constants and pass it to
Ollama's format= so decoding is constrained to the object shape. Also detect
an all-flat-scalar page and warn instead of masking it. Document that
confidence quality is model-dependent (3b unreliable, 7b is the floor).
Verified: 7b output unchanged (no regression); 3b now emits the object shape.
Closes #45
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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
Fixes the all-
0.5confidences in vision-path output (#45).The vision call used
format="json", which only guarantees valid JSON — not our nested{value, confidence}shape. Smaller models (qwen2.5vl:3b) collapse each field to a bare scalar, so_parse_fielddefaulted every confidence to_DEFAULT_CONFIDENCE(0.5), silently destroying the signal that drives low-confidence review.src/schemaconstants (_build_json_schema) and pass it to Ollama'sformat=so decoding is constrained to the object shape. Schema is generated from the same field lists as the prompt skeleton, so it can't drift._response_is_flat) and log a warning instead of masking it — so this failure mode is visible if a model still ignores the schema.docs/models.md: confidence quality is model-dependent — 3B is unreliable (constant value), 7B is the practical floor for confidence-driven features.Investigation notes
format="json"; with the schema its output is unchanged ({1.0, 0.9, 0.6}spread,0.6landing on ambiguoussuccessfulcells) — no regression.format="json"returned flat scalars → all 0.5. With the schema it emits the object shape (though its confidences flatline — a model limitation the schema can't fix, hence the doc note).Test plan
pytest -q— 286 passed--no-cache) — no content/confidence regressionTestJsonSchema(schema built from canonical fields),TestFlatResponseWarning(flat detection + warning), updated format assertionCloses #45
🤖 Generated with Claude Code