Repository navigation
FIX GCG: drop unchanged suffixes with a separator space and survive all-rejected batches - #4769
Merged
Roman Lutz (romanlutz) merged 5 commits intoDec 1, 2026
Conversation
…ll-rejected batches
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The review reports no active issues with the GCG candidate-filtering and current-suffix fallback changes.
No open issues 🎉
What changed in this PR
Fixes PyRIT’s GCG candidate filtering for unchanged suffixes with a leading separator space and batches where every candidate is rejected, addressing #4545 and #4546.
Changes:
- Aligns both filter implementations’ no-op comparisons with prompt rendering while preserving meaningful whitespace.
- Falls back to the current suffix when all candidates are rejected, passing its unstripped decode from the GCG attack.
- Updates the filter contract and regression tests to cover these behaviors and maintain legacy parity.
| File | Description |
|---|---|
tests/unit/executor/promptgen/gcg/test_gcg_proposal.py |
Updates callback expectations for the decoded current control. |
tests/unit/executor/promptgen/gcg/test_gcg_core.py |
Verifies custom filters receive the unstripped control decode. |
tests/unit/executor/promptgen/gcg/test_default_implementations.py |
Adds separator-space and all-rejected regression tests for both filters. |
pyrit/executor/promptgen/gcg/extension_protocols.py |
Documents the current-control fallback exception. |
pyrit/executor/promptgen/gcg/default_implementations.py |
Fixes no-op comparisons and adds the all-rejected fallback. |
pyrit/executor/promptgen/gcg/attack/gcg/gcg_attack.py |
Passes the unstripped current-token decode to the filter. |
pyrit/executor/promptgen/gcg/attack/base/attack_manager.py |
Applies equivalent legacy filtering fixes and rejects fallback without a current control. |
Review effort: Balanced
…oser step() passed the stripped control_str as propose_candidates' current_control_str, so a direct GCGCandidateProposer user relying on the proposer's own candidate_filter would get a stripped all-rejected fallback that can re-tokenize to different ids than the current control. Decode via a shared helper in both filter paths. Co-Authored-By: Claude Fable 5 <[email protected]>
Roman Lutz (romanlutz)
approved these changes
Dec 1, 2026
… type main now sets unsound-assignment to error for tests/unit (microsoft#4759), and the alias off pytest.importorskip's module object is Any, which made the annotated legacy_out assignment fail ty. Import the class after the importorskip guard like test_gcg_core.py does. Co-Authored-By: Claude Fable 5 <[email protected]>
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 #4545 and fixes #4546, both in the GCG candidate filter.
LengthPreservingFilter.filter_candidatesand the legacyMultiPromptAttack.get_filtered_candsget the same change, so the parity tests still hold.AttackPrompt._update_idsdoes. An unchanged suffix that decodes with its separator space is dropped again. I usedremoveprefix(" ")instead ofstrip()because stripping also hides trailing space tokens: on GPT-2 and Qwen2.5," a "and" a"are different suffixes of the same length that both re-tokenize cleanly, but they strip to the same string.IndexError._filter_control_candidatesnow passes the unstripped decode of the current control tokens, so that fallback re-tokenizes to the current ids. The legacy method raises aValueErrorif this happens without acurr_control.CandidateFilterdocstring, since the all-rejected fallback is a case where the current suffix is returned.Per the discussion on #4545, this supersedes #4637.