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

@fengjikui fengjikui commented Jun 23, 2026

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

  • PYTHONPATH=src uv run --frozen --python 3.9 --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="" (1 passed)
  • env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy PYTHONPATH=src uv run --frozen --python 3.9 --with pytest --with pytest-asyncio --with respx --with inline-snapshot pytest tests/lib/responses/test_responses.py -q -o addopts="" (8 passed)
  • uv run --frozen --python 3.9 --with ruff ruff format --check src/openai/lib/_parsing/_responses.py tests/lib/responses/test_responses.py
  • uv run --frozen --python 3.9 --with ruff ruff check src/openai/lib/_parsing/_responses.py tests/lib/responses/test_responses.py
  • uv run --frozen --python 3.9 --with pyright==1.1.399 --with pytest --with pytest-asyncio --with respx --with inline-snapshot pyright src/openai/lib/_parsing/_responses.py tests/lib/responses/test_responses.py (0 errors)

@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
@fengjikui fengjikui force-pushed the codex/skip-incomplete-response-parse branch from 21b3fca to 387108b Compare July 10, 2026 19:16
@fengjikui

Copy link
Copy Markdown
Author

Rebased this fix onto current main (f16fbbd) and resolved the test insertion conflict while preserving the upstream program-item coverage. The refreshed head is 387108b.

Validation on Python 3.9: focused regression 1 passed, full tests/lib/responses/test_responses.py 8 passed, Ruff format/check clean, Pyright 0 errors, and the incomplete-JSON reproduction now returns the response with parsed=None.

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