Repository navigation
MAINT: Deprecate n on chat and completion targets - #4793
Akshay Hitesh Shah (AkshayShah03) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the change warning users about first-choice-only responses.
No open issues 🎉
What changed in this PR
Addresses #4742 by warning when PyRIT chat targets request multiple choices but return only the first, without changing response behavior.
Changes:
- Adds a construction-time warning using shared choice-count lookup, including passthrough overrides.
- Clarifies first-choice-only behavior in both targets’ documentation.
- Adds warning coverage for OpenAI and LiteLLM targets.
| File | Description |
|---|---|
| tests/unit/prompt_target/target/test_openai_chat_target.py | Tests warnings for defaults, multiple choices, and overrides. |
| tests/unit/prompt_target/target/test_litellm_chat_target.py | Tests warning behavior for single and multiple choices. |
| pyrit/prompt_target/openai/openai_chat_target.py | Documents that only the first choice is returned. |
| pyrit/prompt_target/litellm_chat_target.py | Documents first-choice-only behavior and the warning. |
| pyrit/prompt_target/common/chat_completions_tool_loop.py | Adds the shared warning and extracts choice-count lookup. |
Review effort: Balanced
|
Thanks Akshay Hitesh Shah (@AkshayShah03)! After some research we're going to deprecate
|
6b2900e to
a53ba07
Compare
|
Thanks Richard Lundeen (@richlundeen), done in a53ba07 (rebased onto main). |
Description
Fixes #4742. Following the discussion there, this deprecates the
nargument on the chat and completion targets for removal in 1.4.0, instead of only warning about it. Every API that offersnalso takes the full conversation history, so sending once per sample, each in its own conversation, gets the same samples, and each one goes through PyRIT's normal converters, scoring, retries and content-filter handling.OpenAIChatTarget,LiteLLMChatTargetandOpenAICompletionTargetemit aDeprecationWarningthroughprint_deprecation_message(..., removed_in="1.4.0")whenevernis passed, includingn=1, naming one send per sample, each in its own conversation, as the replacement. The warning points at the caller's line.nabove 1 that arrives throughextra_body_parameters(top level or nestedextra_body). It is skipped when thenargument was passed, so the caller never gets both.ndocstrings on all three targets say it is deprecated.OpenAICompletionTarget's says to send once per sample instead, since it does return every choice today.pytest.warns(DeprecationWarning)forn=1andn=3onOpenAIChatTargetandOpenAICompletionTarget, and forLiteLLMChatTarget; no warning of either kind whennis unset; the logged warning forextra_body_parameters={"n": 2}and nested{"extra_body": {"n": 3}}, and not forn=1or a nested override to 1; no logged warning when thenargument already warned. 9 of the 20 new cases fail on main; the rest check that nothing warns.Rebased onto current main. The prompt_target, output, backend and scenario unit suites pass locally (11,325 tests).
Disclosure: this change and its tests were written with the help of an AI coding assistant (Claude).