Skip to content

[codex] Skip parsing incomplete response text#3427

Open
fengjikui wants to merge 1 commit into
openai:mainfrom
fengjikui:codex/skip-incomplete-response-parse
Open

[codex] Skip parsing incomplete response text#3427
fengjikui wants to merge 1 commit into
openai:mainfrom
fengjikui:codex/skip-incomplete-response-parse

Conversation

@fengjikui

Copy link
Copy Markdown

Summary

  • avoid structured-output parsing for response message text unless the message is completed
  • preserve incomplete output text while leaving parsed as None
  • add a regression test for incomplete JSON output in parse_response

Fixes #2486.

Root cause

parse_response attempted to parse every message.output_text item with the requested structured output type. For incomplete responses, that text can contain partial JSON, so Pydantic raises a validation error instead of returning the incomplete response payload.

Validation

  • uv run --with pytest --with pytest-asyncio --with respx --with inline-snapshot pytest tests/lib/responses/test_responses.py::test_parse_incomplete_output_text -q -o addopts=""
  • env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy uv run --with pytest --with pytest-asyncio --with respx --with inline-snapshot pytest tests/lib/responses/test_responses.py -q -o addopts=""
  • uv run --with ruff ruff format --check src/openai/lib/_parsing/_responses.py tests/lib/responses/test_responses.py
  • uv run --with ruff ruff check src/openai/lib/_parsing/_responses.py tests/lib/responses/test_responses.py
  • uv run --with pyright --with pytest --with pytest-asyncio --with respx --with inline-snapshot pyright src/openai/lib/_parsing/_responses.py tests/lib/responses/test_responses.py

@fengjikui fengjikui marked this pull request as ready for review June 23, 2026 16:00
@fengjikui fengjikui requested a review from a team as a code owner June 23, 2026 16:00
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.

Incomplete responses are not handled by parse_response when using Structured Output

1 participant