Skip to content

fix(responses): handle null text values in output_text property#3017

Open
dagangtj wants to merge 1 commit intoopenai:mainfrom
dagangtj:fix-output-text-null-handling
Open

fix(responses): handle null text values in output_text property#3017
dagangtj wants to merge 1 commit intoopenai:mainfrom
dagangtj:fix-output-text-null-handling

Conversation

@dagangtj
Copy link
Copy Markdown

Summary

Fixes #3011

When using the OpenAI Responses API with certain models like openai/gpt-oss-safeguard-120b, the response can contain output_text content items where the text field is null instead of a string. This causes the output_text property to raise a TypeError when accessed, as it attempts to concatenate None values.

Changes

Added a null check before appending content.text to the texts list:

# Before
if content.type == "output_text":
    texts.append(content.text)

# After  
if content.type == "output_text" and content.text:
    texts.append(content.text)

Testing

The fix ensures that when text is null, it is simply skipped rather than causing a TypeError during string concatenation.

Checklist

  • Bug fix (non-breaking change which fixes an issue)
  • Code follows the project's style guidelines

When the API returns output_text content items with text: null,
the output_text property would raise a TypeError because it
attempted to concatenate None values.

Add null check before appending to texts list.

Fixes openai#3011
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 fails to handle null text values in content items

1 participant