fix(items): guard None refusal in ItemHelpers.extract_last_content#3750
Closed
jawwad-ali wants to merge 1 commit into
Closed
fix(items): guard None refusal in ItemHelpers.extract_last_content#3750jawwad-ali wants to merge 1 commit into
jawwad-ali wants to merge 1 commit into
Conversation
extract_last_content is typed -> str, and its ResponseOutputText branch already coerces a possibly-None text to "" (openai#3394). The sibling ResponseOutputRefusal branch returned last_content.refusal unguarded -- the lone remaining path that can return None despite the -> str contract. Guard with `or ""` to match the text branch and the sibling helpers extract_text, extract_refusal, and text_message_output.
Member
|
We've been receiving this patch several times but we don't need the change. #3751 clarifies why we don't accept it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ItemHelpers.extract_last_contentis typed-> str, and itsResponseOutputTextbranch already coerces a possibly-Nonetextto""(added in #3394). The siblingResponseOutputRefusalbranch, however, returnedlast_content.refusalunguarded — the one remaining path in this helper that can returnNonedespite the-> strcontract.refusalis typedstrby the Responses API schema, but the same provider-gateway (e.g. LiteLLM) andmodel_constructstreaming paths that surface aNonetextcan surface aNonerefusal. This guards it withor "", matching the text branch directly above and the sibling helpersextract_text,extract_refusal, andtext_message_output, which all already useor "".Test plan
test_extract_last_content_tolerates_none_refusal_contentintests/test_items_helpers.py, mirroring the existingtest_extract_text_tolerates_none_text_content: it builds aResponseOutputRefusal.model_construct(refusal=None, ...)and assertsextract_last_contentreturns""(and notNone).uv run pytest tests/test_items_helpers.py— 35 passed.uv run ruff formatanduv run ruff checkare clean;uv run mypy src/agents/items.pypasses.Issue number
N/A — this completes the
None-guarding introduced in #3394 (same function,textbranch) and #3375 (text_message_output); the refusal branch is the lone remaining unguarded path in a helper typed-> str.Checks
make lintandmake format