Skip to content

parse_response crashes with TypeError when a message item has content:null #3840

Closed

Description

@soroush5

Follow-up to #3325 (fixed for output: null in #3345).

Same crash one level deeper: when the API returns a message output item with content: null, parse_response (src/openai/lib/_parsing/_responses.py) raises a raw TypeError: 'NoneType' object is not iterable instead of parsing.

Repro (both paths hit it, sync and async):

client.responses.parse(model="...", input="...")
# API returns output: [{"id": ..., "type": "message", "role": "assistant",
#   "status": "completed", "content": null}]
# -> TypeError: 'NoneType' object is not iterable

This also breaks streaming when response.completed carries explicit output with a null-content message, since explicit completion output is passed straight through to parse_response.

Null reaches the parser because stream events are built without validation, and the same payload passes the non-streaming path too (verified with a mocked transport). Treating null content as empty — the same or [] idiom #3345 used for output — fixes it. PR follows.

Activity

  1. marcuswood-oai commented on Sep 18, 2026

    @marcuswood-oai
    Contributor

    Thanks for the clear repro! We confirmed the crash with a mocked response, and #3851 safely treats null message content as empty. We haven’t found a production path that emits this payload, so we’re treating this as defensive hardening.

  2. soroush5 commented on Sep 18, 2026

    @soroush5
    Author

    Thanks for confirming and for the fix in #3851.

  3. added a commit that references this issue on Sep 18, 2026
    fab5283
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions