openai / openai/openai-python

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

Open
#3,063 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
31.6k
Forks
5.7k
Avg merge
1d 6h
Merged PRs (30d)
96

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Response.model_validate(data) reproduction, Response.output_text, and responses.parse(...), then inspect the response output-text model and parsing path. Add regression coverage for the provided null-text payload and verify that validation succeeds, null entries are ignored, and non-null text is still parsed.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.