Skip to content

fix: handle null response output text - #3400

Closed
he-yufeng wants to merge 2 commits into
openai:mainfrom
he-yufeng:fix/nullable-response-output-text
Closed

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

Conversation

@he-yufeng

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

Changes being requested

  • Allow ResponseOutputText.text to be None when the API returns a nullable output_text.text item.
  • Make Response.output_text skip null text items instead of failing or appending a non-string value.
  • Make responses.parse(...) leave null output_text items unparsed while still parsing later non-null output text items.
  • Add regression coverage for both Response.output_text and the structured parse path.

Additional context & links

Fixes #3063.

I know the repository is generated; this PR is intended to pin down the runtime behavior and regression tests for the nullable API payload shape.

Verification:

  • PYTHONPATH=src python -m pytest tests\lib\responses\test_responses.py -q
  • python -m ruff check src\openai\types\responses\response_output_text.py src\openai\types\responses\response.py src\openai\lib\_parsing\_responses.py tests\lib\responses\test_responses.py
  • python -m pyright src\openai\types\responses\response_output_text.py src\openai\types\responses\response.py src\openai\lib\_parsing\_responses.py tests\lib\responses\test_responses.py
  • python -m ruff format --check src\openai\types\responses\response_output_text.py src\openai\types\responses\response.py src\openai\lib\_parsing\_responses.py tests\lib\responses\test_responses.py
  • git diff --check

@he-yufeng
he-yufeng requested a review from a team as a code owner June 13, 2026 22:14

@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: 897ce0a518

ℹ️ 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".



def _response_with_output_text_items(items: list[dict[str, Any]]) -> Response:
return Response.model_validate(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use v1-compatible validation in test helper

In the test-pydantic-v1 nox session, noxfile.py installs pydantic<2 and runs the whole pytest suite, but this helper now calls Response.model_validate(...) unconditionally. The SDK's BaseModel does not shim model_validate for pydantic v1, so that CI path will fail with AttributeError before these regressions run. Use the repo's compatibility helper or Response.parse_obj(...) here instead.

Useful? React with 👍 / 👎.

…se-output-text

# Conflicts:
#	tests/lib/responses/test_responses.py
@he-yufeng

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main — the only conflict was in the test file (both sides added tests near the same spot), resolved by keeping both my null-output-text cases and the new program_items parametrize test. The source change is unchanged: output_text / parse_response now skip output_text items whose text is null instead of tripping over them. Ready for review whenever someone has a moment.

@he-yufeng

Copy link
Copy Markdown
Contributor Author

A note on why this keeps showing conflicts: the edits under src/openai/types/responses/ land in Stainless-generated files, so every spec regeneration collides with them. The durable part of this fix is the lib/_parsing side (skip null text items while parsing later ones). I can rebase this down to just the lib change plus tests and leave the nullable output_text.text type to the spec side, if that's the preferred split. Holding off on further rebases until then since each one conflicts again on the generated files.

@he-yufeng

Copy link
Copy Markdown
Contributor Author

Re-verified against current main: ResponseOutputText.text is still a required str, so a Responses payload item that arrives with text: null still fails parsing instead of being tolerated. The null-tolerant handling and its test still apply. (Sibling #3401 landed recently; this one is the same error class on the output side.)

Copy link
Copy Markdown
Contributor

Thanks for working on this! We’re closing this for now because we haven’t established a case where Responses structured-output parsing should accept null or empty text. If you’re hitting this in practice, please open an issue with a minimal reproduction and the API/provider you’re using—we’re happy to revisit.

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