Repository navigation
FEAT: Add OutputFormatConverter and CharSplitOutputConverter - #3381
Open
Absarahmedofficial wants to merge 1 commit into
Open
Absarahmedofficial wants to merge 1 commit into
Absarahmedofficial wants to merge 1 commit into
Conversation
| from pyrit.models import ComponentIdentifier, PromptDataType | ||
|
|
||
|
|
||
| class OutputFormatConverter(Converter): |
Contributor
There was a problem hiding this comment.
Absarahmedofficial Could we compose the existing converters here instead of adding a new public base class?
PromptTemplateConverter or SuffixAppendConverter can append the formatting instructions, and SearchReplaceConverter can decode the response using the same regex. AttackConverterConfig already lets us configure these separately as request and response converters.
Could we package that configuration as a reusable attack technique instead? That would keep the character-splitting behavior without adding another converter hierarchy to maintain. Is there a use case this composition cannot support that I'm missing?
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
Adds
OutputFormatConverterandCharSplitOutputConverter(text -> text) for output-format steering and response normalization in PyRIT converter pipelines.OutputFormatConverter: Abstract base class for converters that append output-formatting instructions to a prompt (action="encode") and normalize the formatted target response back into plain text (action="decode") before scoring. Follows the sameaction="encode" | "decode"pattern and publicself.actioninterface asSmugglerConverter(pyrit/converter/token_smuggling/base.py).CharSplitOutputConverter: Instructs the target to insert a single non-whitespace delimiter (.by default) between adjacent characters within each word while preserving spaces, hyphens, and punctuation, and strips intra-word delimiters (unescaping doubled literal delimiters) onaction="decode".TYPE_CHECKINGand_LAZY_EXPORTSinpyrit/converter/__init__.py.cc Roman Lutz (@romanlutz)
Tests and Documentation
tests/unit/converter/test_output_format_converter.pycovering abstract instantiation checks,actionand modality validation, valid/invalid delimiter checks (empty, multi-char, whitespace, non-string, NUL byte), printable and non-printable format instructions, intra-word delimiter stripping, doubled-delimiter unescaping, andComponentIdentifierparams. Verified withpytest tests/unit/converter/test_output_format_converter.py,pytest tests/unit/docs/test_converter_documentation.py,pytest tests/unit/common/test_lazy_package_imports.py,ruff check,ruff format --check, andty check.CharSplitOutputConverterencode/decode example todoc/code/converters/1_text_to_text_converters.py, synced the paireddoc/code/converters/1_text_to_text_converters.ipynbwithjupytext --sync, and executed the new cell so the notebook carries the actual output while leaving existing cell outputs untouched.