openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

fix: guard against null output in parse_response and output_text property

Open adhavan18 opened this issue 5 months ago • 0 comments

Fixes #3325 and #3063.

Problem

Two crashes in the Responses API when the server returns unexpected null values:

  1. Some backends send output: null in the final response.completed event even when output items were already streamed. parse_response and Response.output_text both iterate response.output directly → TypeError: 'NoneType' object is not iterable.
  2. When an output_text content item has text: null, parse_response passes None to the structured parser and output_text concatenates None into the string.

Fix

  • _parsing/_responses.py — iterate response.output or []; skip structured parsing when item.text is None
  • types/responses/response.py — same or [] guard in the output_text property; skip content items where text is None
  • lib/streaming/responses/_responses.py — when response.completed arrives with output: null, fall back to the accumulated snapshot output instead of parsing an empty list

Test

All existing tests in tests/lib/responses/ pass.

adhavan18 avatar Jun 15 '26 07:06 adhavan18