openai-python
openai-python copied to clipboard
fix: guard against null output in parse_response and output_text property
Fixes #3325 and #3063.
Problem
Two crashes in the Responses API when the server returns unexpected null values:
- Some backends send
output: nullin the finalresponse.completedevent even when output items were already streamed.parse_responseandResponse.output_textboth iterateresponse.outputdirectly →TypeError: 'NoneType' object is not iterable. - When an output_text content item has
text: null,parse_responsepassesNoneto the structured parser andoutput_textconcatenatesNoneinto the string.
Fix
_parsing/_responses.py— iterateresponse.output or []; skip structured parsing whenitem.text is Nonetypes/responses/response.py— sameor []guard in theoutput_textproperty; skip content items wheretext is Nonelib/streaming/responses/_responses.py— whenresponse.completedarrives withoutput: null, fall back to the accumulated snapshot output instead of parsing an empty list
Test
All existing tests in tests/lib/responses/ pass.