Skip to content

fix(types): make ResponseOutputText.text Optional to accept null from API - #3632

Open
Xsidz wants to merge 2 commits into
openai:mainfrom
Xsidz:fix/response-output-text-nullable
Open

fix(types): make ResponseOutputText.text Optional to accept null from API#3632
Xsidz wants to merge 2 commits into
openai:mainfrom
Xsidz:fix/response-output-text-nullable

Conversation

@Xsidz

@Xsidz Xsidz commented Aug 16, 2026

Copy link
Copy Markdown

Summary

Fixes #3063 (layer 1).

Some models (gpt-oss-safeguard-120b and others) return output_text content items with text: null. The strict text: str annotation caused pydantic to reject the entire response payload at parse time.

Changed text: str to text: Optional[str] = None in ResponseOutputText. This is consistent with how action: Optional[Action] is already handled on ResponseFunctionWebSearch.

Note: layer 2 of this issue (the Response.output_text property crashing when text is null) is covered by a companion PR fixing the content.text is not None guard — see PR #3628.

Test plan

  • tests/test_models.py + tests/lib/responses/: 65 passed, 0 failures.
  • Ruff lint: all checks passed.

… API

Fixes openai#3063: some models (gpt-oss-safeguard-120b) return output_text
content items with text: null. The strict str annotation caused pydantic
to reject the payload. Changed to Optional[str] = None.
@Xsidz
Xsidz requested a review from a team as a code owner August 16, 2026 18:22
Copilot AI lite review requested due to automatic review settings August 16, 2026 18:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ec08c15c2f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

"""The annotations of the text output."""

text: str
text: Optional[str] = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Guard null values when aggregating output text

When the API returns the exact text: null payload this change is intended to accept, deserialization now succeeds, but accessing the common Response.output_text convenience property still appends that None value and passes it to "".join(...), raising TypeError. Update the aggregator to skip or normalize null text in the same change so callers can safely consume these responses.

Useful? React with 👍 / 👎.

"""The annotations of the text output."""

text: str
text: Optional[str] = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid parsing null as structured JSON

For client.responses.parse(..., text_format=...), a response containing this newly accepted null value is passed unconditionally from parse_response to parse_text, which then gives None to Pydantic's JSON parser and fails before returning the response. Guard the null case and leave parsed as None; otherwise the structured-response API still rejects the payload this change is meant to support.

Useful? React with 👍 / 👎.

"""The annotations of the text output."""

text: str
text: Optional[str] = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Initialize null streaming text before applying deltas

If a streaming response initializes an output_text content part with the newly valid null value and then emits a response.output_text.delta, the response accumulator executes content.text += event.delta, so None + str raises TypeError and terminates the stream. Normalize a null initial value to an empty string before accumulating deltas.

Useful? React with 👍 / 👎.

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.

Response.output_text and responses.parse fail when an output_text item has text: null

2 participants