Skip to content

FIX Reject an example_count that is not a positive integer in ManyShotJailbreakAttack - #3395

Open
Shivam Sharma (ShivamSharma43) wants to merge 1 commit into
microsoft:mainfrom
ShivamSharma43:fix/many-shot-example-count-validation
Open

Shivam Sharma (ShivamSharma43) wants to merge 1 commit into
microsoft:mainfrom
ShivamSharma43:fix/many-shot-example-count-validation

Conversation

@ShivamSharma43

Copy link
Copy Markdown
Contributor

Description

Fixes #3393.

ManyShotJailbreakAttack uses example_count as a slice bound (examples[:example_count]), but only 0 was rejected. A negative count was accepted and dropped examples from the end of the list instead of selecting from the start: example_count=-1 sent 399 of the 400 bundled examples, and with five custom examples -4 kept one. True was taken as 1, and other types failed with an unrelated error (2.5 raised a slice TypeError). Because the check runs in validate_constructor_parameters, the REST technique API also accepted {"example_count": -1}.

Changes:

  • validate_constructor_parameters now raises ValueError("example_count must be a positive integer, got ...") for anything that is not an int of at least 1, including bools. The constructor and the deferred-construction path (REST TechniqueService) share this check.
  • An empty many_shot_examples list still raises Many shot examples must be provided.; that check no longer depends on the count.
  • The example_count docstring says it must be a positive integer.

example_count=0 was already rejected; it now gets the example_count message instead of Many shot examples must be provided. Valid counts behave as before, including counts larger than the number of examples.

Tests and Documentation

  • New tests in tests/unit/executor/attack/single_turn/test_many_shot_jailbreak.py: the constructor rejects 0, -1, -3, True, 2.5, "5" and None, and validate_constructor_parameters rejects 0, -1, True and "5" without constructing the attack.
  • tests/unit/backend/test_technique_service.py: added ("ManyShotJailbreakAttack", {"example_count": -1}) to the REST constraint cases.
  • On main all 11 new attack test cases fail and the new REST case fails (the technique is created). With this change they pass.
  • pytest tests/unit/backend/test_technique_service.py tests/unit/executor/attack -n 4: 1317 passed.
  • ruff check and ruff format pass on the changed files, and ty check reports nothing new compared to main beyond the environment-only dynamic-function-decorator-return entries for the new parametrized tests. git diff --check is clean.
  • No documentation changes beyond the docstring.

🤖 Generated with Claude Code

…tJailbreakAttack

example_count is used as a slice bound, so a negative value dropped examples
from the end of the list instead of selecting from the start, and bools,
floats and strings were accepted or failed with an unrelated error. The check
lives in validate_constructor_parameters, so the REST technique API rejects
the same values without constructing the attack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 20, 2026 12:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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.

BUG: ManyShotJailbreakAttack accepts a negative example_count and drops examples from the end

2 participants