Repository navigation
FEAT: Add context_wrap attack technique in extra.py - #3549
Open
Absarahmedofficial wants to merge 1 commit into
Open
Absarahmedofficial wants to merge 1 commit into
Absarahmedofficial wants to merge 1 commit into
Conversation
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
Registers the
context_wrapattack technique inpyrit/setup/initializers/techniques/extra.pyby composingPromptTemplateConverterandSearchReplaceConverteronPromptSendingAttackviaAttackConverterConfig(restricted toprompt_data_types_to_apply=["text"]on both sides):PromptTemplateConverter): Appends output-formatting instructions asking the target to wrap each sentence in<seg>and</seg>tags interleaved with single-line compiler diagnostic status lines starting with[DIAG-.SearchReplaceConverter): Normalizes the response before scoring with a single-pass regex (pattern=r"</seg>\s*\[DIAG-[^\r\n ]*( )[^\r\n]*\s*<seg>|\s*\[DIAG-[^\r\n]*\s*|</?seg>",replace=r"\1") that joins adjacent tagged sentences across diagnostic lines with a single space and strips outer<seg>tags and diagnostic lines.Follows the same converter composition pattern established in #3381.
cc Roman Lutz (@romanlutz)
Tests and Documentation
EXTRA_TECHNIQUE_NAMESandtest_default_registers_only_coreintests/unit/setup/test_technique_initializer.py.TestContextWrapTechniqueintests/unit/setup/techniques/test_extra_techniques.pycovering factory wiring, request prompt formatting, multi-sentence round-trip decoding, scorer evaluation on decoded output (SubStringScorer), and multimodal text/image preservation on both requests and responses.