fix(models): surface content-filter refusals in non-streaming Chat Completions - #4159
Closed
LeSingh1 wants to merge 1 commit into
Closed
fix(models): surface content-filter refusals in non-streaming Chat Completions#4159LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
seratch
requested changes
Aug 4, 2026
seratch
left a comment
Member
There was a problem hiding this comment.
Thanks for the contribution. The behavior and fix are valid, but the impact description is slightly too broad: an empty content-filtered response does not always drive the agent loop into retries. For plain-text agents, the current runner completes successfully with an empty string; structured-output agents retry until the turn limit.
Please update the source comment, test docstring, and PR description to state that the lost refusal signal produces an empty final output for plain-text runs and repeated retries for structured-output runs. No runtime implementation change is needed.
Member
|
#4188 includes your contribution; thanks again for your efforts here. |
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
OpenAIChatCompletionsModel.get_responsenever inspectedfinish_reason. Some providers — Azure OpenAI content filtering, Bedrock-backed Chat Completions proxies — signal a safety block only viafinish_reason == "content_filter"with an empty message and norefusalfield.Converter.message_to_output_itemsthen produces zero output items, so the caller sees an indistinguishable "empty turn" and agent loops retry fruitlessly against a block that will never clear.Both sibling paths already handle this. The streamed handler synthesizes a
ResponseOutputRefusal(chatcmpl_stream_handler.py), and so doesLitellmModel.get_response(#3769). This brings the non-streaming OpenAI Chat Completions path into agreement with them by settingmessage.refusalbefore conversion, and only when the turn is genuinely empty — no content, no provider-supplied refusal, and no tool calls — so no existing successful shape changes.Test plan
New
tests/models/test_openai_chatcompletions_content_filter.py, mirroring the existingtest_litellm_content_filter.py:finish_reason="stop"is unaffected in both the text and empty casesFails on
main(AssertionError: expected a refusal item, got: []), passes with the fix. Fulltests/models/suite: 646 passed..agents/skills/code-change-verification/scripts/run.shpassed.Issue number
N/A — found while auditing provider parity between the streaming and non-streaming Chat Completions paths.
Checks
.agents/skills/code-change-verification/scripts/run.sh/reviewbefore submitting this PR