Repository navigation
FIX: warn when chat targets ignore extra choices from n > 1 - #4749
Closed
Denzil Nelson (Denzil10) wants to merge 4 commits into
Closed
Denzil Nelson (Denzil10) wants to merge 4 commits into
Denzil Nelson (Denzil10) wants to merge 4 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Responses with a content-filtered first choice return early and bypass the unused-choice warning, leaving extra choices, their finish reasons, and their costs unreported.
1 open issue
What changed in this PR
This PR addresses #4742 by making discarded chat-completion choices visible without changing the existing first-choice-only behavior.
Changes:
- Adds a shared warning reporting ignored choices, their finish reasons, and billing implications.
- Clarifies
nin the OpenAI and LiteLLM target documentation. - Adds mocked regression tests for multi-choice warnings and single-choice silence.
| File | Description |
|---|---|
tests/unit/prompt_target/target/test_openai_chat_target.py |
Tests warning behavior through the target’s send path. |
tests/unit/prompt_target/target/test_chat_completions_helpers.py |
Tests the shared warning and first-choice selection. |
pyrit/prompt_target/openai/openai_chat_target.py |
Documents how extra choices are handled. |
pyrit/prompt_target/litellm_chat_target.py |
Documents the same first-choice-only behavior. |
pyrit/prompt_target/common/chat_completions_response_parser.py |
Adds the warning helper and invokes it during response construction. |
Review effort: Balanced
| Returns: | ||
| list[MessagePiece]: All constructed response pieces (may be empty). | ||
| """ | ||
| warn_unused_choices(response=response) |
The content-filter early return in both chat targets bypasses build_response_pieces_async, so a response whose first choice was content-filtered dropped its extra choices silently - exactly the case where the ignored choices may hold usable completions. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
Issue author said they want to tackle this themselves. Closing this PR. Please read issue descriptions. |
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.

Description
Fixes #4742.
OpenAIChatTarget(n=3)(andLiteLLMChatTarget) sendn=3, are billed for three choices, and return onlychoices[0]with no indication that anything was dropped. This PR makes the drop visible instead of silent.build_response_pieces_async(shared by both chat targets) now logs one warning when a response has more than one choice. It reports the count and thefinish_reasonof each ignored choice, so a droppedcontent_filterchoice shows up, and says that the extra choices are still billed.ndocstrings onOpenAIChatTargetandLiteLLMChatTargetnow state that only the first choice is returned.ChatCompletionfrom the issue (3 choices, onecontent_filter), and a control showing a single-choice response does not warn. The end-to-end test fails on main (no warning) and passes here.Why a warning, not "return every choice" or "reject n > 1"
The issue lists three options and no maintainer picked one, so this is the least invasive. I checked the other two:
OpenAICompletionTargetdoes) breaks multi-turn use.build_text_chat_messagesraises unless each message has exactly one piece, and the multimodal builder would merge alternative replies into a single assistant turn on replay. Tool calls from non-first choices would also put calls from different branches into one history entry.n > 1would break behavior existing tests rely on, for exampletest_chat_tool_targets_accept_nested_settings_without_local_executionacceptsn=2when tools are not executed locally. The repo also moved toward warning over raising in similar cases (FIX: warn instead of raising on reasoning-model token truncation (Chat and Responses targets) #2166).If maintainers prefer one of those, I am happy to rework this PR.
Automatic tool execution requires n=1is unchanged.AI assistance: Claude Code helped trace the code paths and draft this change; I reviewed the diff and ran the tests.