Repository navigation
Conversation
The parsed-output property checked the parsed value for truthiness, so 0, False, an empty string, list, or dict were returned as None and looked like an unparsed block. None is the not-parsed sentinel; return every other value in both ParsedMessage and ParsedBetaMessage.
This branch has not been deployed
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.
ParsedMessage.parsed_outputandParsedBetaMessage.parsed_outputreturnNonefor valid falsy structured outputs. A response whose parsed value is0,False,"",[], or{}is indistinguishable from a response that was not parsed at all, for both non-streamingmessages.parse()and streamingstream.get_final_message().The parser stores the value correctly on the text block, but the property tests
content.parsed_outputfor truthiness before returning it.Noneis the "not parsed" sentinel; every other value is a parsed output.The fix checks
content.parsed_output is not Nonein bothParsedMessageandParsedBetaMessage. Tests cover all five falsy values for both message types and both sync and async streaming.Test: the new tests fail on
202db72c(assert None == 0,None == False,None == "",None == [],None == {}) and pass on this branch (12 passed). The broadertests/lib/streaming,tests/lib/_parse, andtests/lib/threadssuites are 715 passed; the Pydantic v1 targeted run is 15 passed../scripts/lintis clean (ruff, dependency caps, pyright, import smoke).Details
A legitimate JSON
nulloutput remains indistinguishable from "not parsed" becauseparsed_outputisOptional[ResponseFormatT]; that pre-existing type ambiguity is not changed here. No live API calls are made; streaming tests replay fixtures throughrespx.