Skip to content

fix(lib): treat null message content as empty in parse_response - #3851

Open
chenlichao wants to merge 1 commit into
openai:mainfrom
chenlichao:fix/parse-response-null-message-content
Open

fix(lib): treat null message content as empty in parse_response#3851
chenlichao wants to merge 1 commit into
openai:mainfrom
chenlichao:fix/parse-response-null-message-content

Conversation

@chenlichao

Copy link
Copy Markdown

Changes being requested

  • I understand that this repository is auto-generated and my pull request may not be merged

Fixes #3840

parse_response() in src/openai/lib/_parsing/_responses.py iterates output.content without a null guard, so a message output item with content: null raises TypeError: 'NoneType' object is not iterable instead of parsing:

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

Null reaches the parser because stream events are built without validation, and the same payload also passes the non-streaming path (reproduced with a mocked transport, both sync and async). This is the same class of bug as null output, fixed in #3345.

The fix applies the same or [] idiom used at line 61 for null output (one line). The change is in src/openai/lib/, which per CONTRIBUTING.md is handwritten and never modified by the generator, so no custom-code budget impact.

Additional context & links

Responses parsing raised `TypeError: 'NoneType' object is not iterable`
when a message output item had `content: null` - the same class of bug
as null `output` fixed in openai#3345. Null reaches the parser because stream
events are built without validation, and the same payload also passes
the non-streaming path.

Treat null content as empty with the same `or []` idiom used for null
output, and add a regression test alongside the null-output tests.

Fixes openai#3840
@chenlichao
chenlichao requested a review from a team as a code owner September 11, 2026 17:04
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-11T17:06:43.149789Z 617a3d8 PR opened
🔒 Security Review Completed 2026-09-11T17:08:10.377074Z 617a3d8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

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

1 participant