Skip to content

fix(lib): guard parse_response against response.output=None#3460

Open
nicha16 wants to merge 1 commit into
openai:mainfrom
nicha16:fix/parse-response-none-output
Open

fix(lib): guard parse_response against response.output=None#3460
nicha16 wants to merge 1 commit into
openai:mainfrom
nicha16:fix/parse-response-none-output

Conversation

@nicha16

@nicha16 nicha16 commented Jul 1, 2026

Copy link
Copy Markdown

Fixes #3459

Problem

parse_response in src/openai/lib/_parsing/_responses.py iterates response.output without guarding against None:

for output in response.output:   # TypeError if response.output is None

When a completed Response has output=None, this raises TypeError: 'NoneType' object is not iterable. Because parse_response is invoked from the streaming accumulator (lib/streaming/responses/_responses.py::accumulate_eventparse_response), the exception crashes the entire stream rather than surfacing as a handleable result — and it originates deep in the SDK, so it isn't catchable as a normal API error.

output can be None for incomplete / failed / reasoning-only responses, and via some proxy/aggregator backends.

Fix

Guard the iteration:

-    for output in response.output:
+    for output in (response.output or []):

A None/absent output now yields a ParsedResponse with an empty output list instead of crashing.

Test

Adds tests/lib/responses/test_parse_response_none_output.py, a focused regression test that calls parse_response with a Response whose output is None.

Validated in isolation:

  • Without the guard: the test fails with exactly TypeError: 'NoneType' object is not iterable at _parsing/_responses.py (reproduces the bug).
  • With the guard: the test passes.

The change is one line plus a test; happy to adjust naming/placement to match your conventions.

parse_response iterated response.output directly, raising
TypeError('NoneType' object is not iterable) when a completed Response
has output=None (incomplete/failed/reasoning-only responses, and some
proxy/aggregator backends). Because this fires inside the streaming
accumulator (accumulate_event -> parse_response), it crashes the whole
stream rather than surfacing as a handleable result.

Guard with (response.output or []). Adds a regression test that
reproduces the crash without the guard.

Fixes openai#3459
@nicha16 nicha16 requested a review from a team as a code owner July 1, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

responses.stream: parse_response crashes with TypeError when response.output is None

1 participant