Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/openai/lib/_parsing/_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def parse_response(
) -> ParsedResponse[TextFormatT]:
output_list: List[ParsedResponseOutputItem[TextFormatT]] = []

for output in response.output:
for output in response.output or []:
if output.type == "message":
content_list: List[ParsedContent[TextFormatT]] = []
for item in output.content:
Expand Down
26 changes: 25 additions & 1 deletion tests/lib/responses/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from inline_snapshot import snapshot

from openai import OpenAI, AsyncOpenAI
from openai._types import omit
from openai._types import omit, NOT_GIVEN
from openai._utils import assert_signatures_in_sync
from openai._models import construct_type_unchecked
from openai.types.responses import Response
Expand Down Expand Up @@ -92,3 +92,27 @@ def test_parse_method_definition_in_sync(sync: bool, client: OpenAI, async_clien
checking_client.responses.parse,
exclude_params={"tools"},
)


def test_parse_response_handles_null_output() -> None:
response = Response.model_construct(
id="resp_123",
object="response",
created_at=0,
status="completed",
error=None,
incomplete_details=None,
instructions=None,
max_output_tokens=None,
model="gpt-4o-mini",
output=None,
parallel_tool_calls=True,
temperature=1.0,
tool_choice="auto",
tools=[],
top_p=1.0,
)

parsed = parse_response(text_format=NOT_GIVEN, input_tools=None, response=response)

assert parsed.output == []