fix(structured): report an output-limit stop instead of a JSON parse error - #94
Merged
Merged
Conversation
…error
A reasoning model can spend its entire output budget thinking and return no
content at all. The provider says so plainly through `finish_reason: "length"`,
but `extract_provider_schema` parsed the empty string regardless and surfaced
schema 'x': response text is not valid JSON: expected value at line 1 column 1
which points at a malformed response that was never sent. The reader goes
looking for bad JSON; the actual fix is to raise `max_tokens` or cap reasoning.
Observed with `moonshotai/kimi-k3` on a 49k-token prompt: `finish_reason` was
`length`, `completion_tokens` was the full 8000, reasoning was 17k characters,
and content was empty.
Empty content is now reported as what it is, naming the remedy when the stop
reason confirms truncation, and reporting the stop reason otherwise. Genuinely
malformed JSON still reports a parse error.
Co-authored-by: Medulla <medulla@tinyhumans.ai>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe structured-output extractor now detects empty model responses before JSON parsing. It reports output-limit truncation separately from missing content. Tests cover both diagnostics and preserve parse errors for malformed non-empty JSON. ChangesStructured output diagnostics
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
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
extract_provider_schemaparses the response text without first checking whether there is any. When a reasoning model spends its whole output budget thinking and returns empty content, the error is:That points at a malformed response which was never sent. The reader goes looking for bad JSON — the actual cause is truncation, and the fix is to raise
max_tokensor cap reasoning.How it was found
Reviewing a large pull request with
moonshotai/kimi-k3through OpenRouter. Calling the API directly with the same 49k-token prompt:The provider had already said exactly what happened.
ModelResponse::finish_reasoncarried it, and the extractor ignored it.Worth noting for anyone hitting the same thing: OpenRouter's
reasoning: {max_tokens: N}is ignored by this model — reasoning still grew past a 4096 cap.reasoning: {enabled: false}does work.The change
Empty content is now reported as empty content. When
finish_reasonislengththe message names the remedy; otherwise it reports the stop reason it did get. Genuinely malformed JSON still reports a parse error — there is a test pinning that, so the new branch cannot swallow the case it was not written for.Tests
Three added in
src/harness/structured/test.rs.cargo test --libis green at 1405 passed;cargo clippy --all-targets -- -D warningsis clean.Summary by CodeRabbit