fix(types): make ResponseOutputText.text Optional to accept null from API - #3632
fix(types): make ResponseOutputText.text Optional to accept null from API#3632Xsidz wants to merge 2 commits into
Conversation
… 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.
There was a problem hiding this comment.
💡 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
Fixes #3063 (layer 1).
Some models (
gpt-oss-safeguard-120band others) returnoutput_textcontent items withtext: null. The stricttext: strannotation caused pydantic to reject the entire response payload at parse time.Changed
text: strtotext: Optional[str] = NoneinResponseOutputText. This is consistent with howaction: Optional[Action]is already handled onResponseFunctionWebSearch.Note: layer 2 of this issue (the
Response.output_textproperty crashing when text is null) is covered by a companion PR fixing thecontent.text is not Noneguard — see PR #3628.Test plan
tests/test_models.py+tests/lib/responses/: 65 passed, 0 failures.