Skip to content

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

@texasich

Description

@texasich

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

Response.output_text can fail when a Responses API payload includes an output_text content item whose text field is null.

There are two affected layers:

  • strict response parsing rejects ResponseOutputText.text = null
  • parsed responses can still attempt structured parsing on an output_text item whose text is null

Expected behavior:

  • the SDK should accept nullable output_text.text values from the API
  • Response.output_text should ignore null entries instead of failing
  • responses.parse(...) should skip structured parsing for null output_text items

Related PR: #3062

To Reproduce

Create or receive a Responses API payload where a message contains an output_text item with text: null, for example alongside another normal output_text item.

Code snippets

from openai.types.responses.response import Response

data = {
    "id": "resp_null_output_text",
    "object": "response",
    "created_at": 0,
    "status": "completed",
    "background": False,
    "error": None,
    "incomplete_details": None,
    "instructions": None,
    "max_output_tokens": None,
    "max_tool_calls": None,
    "model": "gpt-4o-mini",
    "output": [
        {
            "id": "msg_null_output_text",
            "type": "message",
            "status": "completed",
            "role": "assistant",
            "content": [
                {
                    "type": "output_text",
                    "annotations": [],
                    "logprobs": [],
                    "text": None,
                },
                {
                    "type": "output_text",
                    "annotations": [],
                    "logprobs": [],
                    "text": '{"message":"hello"}',
                },
            ],
        }
    ],
    "parallel_tool_calls": True,
    "previous_response_id": None,
    "prompt_cache_key": None,
    "reasoning": {"effort": None, "summary": None},
    "safety_identifier": None,
    "service_tier": "default",
    "store": True,
    "temperature": 1.0,
    "text": {"format": {"type": "text"}, "verbosity": "medium"},
    "tool_choice": "auto",
    "tools": [],
    "top_logprobs": 0,
    "top_p": 1.0,
    "truncation": "disabled",
    "usage": {
        "input_tokens": 1,
        "input_tokens_details": {"cached_tokens": 0},
        "output_tokens": 1,
        "output_tokens_details": {"reasoning_tokens": 0},
        "total_tokens": 2,
    },
    "user": None,
    "metadata": {},
}

Response.model_validate(data)

OS

Windows 11

Python version

Python 3.13.12

Library version

openai v2.30.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions