Repository navigation
FIX Reject an example_count that is not a positive integer in ManyShotJailbreakAttack - #3395
Open
Shivam Sharma (ShivamSharma43) wants to merge 1 commit into
Conversation
…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>
This branch has not been deployed
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 #3393.
ManyShotJailbreakAttackusesexample_countas a slice bound (examples[:example_count]), but only0was rejected. A negative count was accepted and dropped examples from the end of the list instead of selecting from the start:example_count=-1sent 399 of the 400 bundled examples, and with five custom examples-4kept one.Truewas taken as1, and other types failed with an unrelated error (2.5raised a sliceTypeError). Because the check runs invalidate_constructor_parameters, the REST technique API also accepted{"example_count": -1}.Changes:
validate_constructor_parametersnow raisesValueError("example_count must be a positive integer, got ...")for anything that is not anintof at least 1, including bools. The constructor and the deferred-construction path (RESTTechniqueService) share this check.many_shot_exampleslist still raisesMany shot examples must be provided.; that check no longer depends on the count.example_countdocstring says it must be a positive integer.example_count=0was already rejected; it now gets theexample_countmessage instead ofMany shot examples must be provided.Valid counts behave as before, including counts larger than the number of examples.Tests and Documentation
tests/unit/executor/attack/single_turn/test_many_shot_jailbreak.py: the constructor rejects0,-1,-3,True,2.5,"5"andNone, andvalidate_constructor_parametersrejects0,-1,Trueand"5"without constructing the attack.tests/unit/backend/test_technique_service.py: added("ManyShotJailbreakAttack", {"example_count": -1})to the REST constraint cases.mainall 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 checkandruff formatpass on the changed files, andty checkreports nothing new compared tomainbeyond the environment-onlydynamic-function-decorator-returnentries for the new parametrized tests.git diff --checkis clean.🤖 Generated with Claude Code