Repository navigation
FEAT: Add DiffChainConverter and DiffChainDecodeConverter - #4297
Open
Absarahmedofficial wants to merge 5 commits into
Open
Absarahmedofficial wants to merge 5 commits into
Absarahmedofficial wants to merge 5 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unescaped chunk markers break decoding, and valid custom templates using dataset paths with deferred conditions fail validation because the template environment lacks the required filter.
2 open issues
What changed in this PR
Adds diff-chain encoding and decoding to PyRIT’s converter library, allowing text prompts to be represented as a placeholder file followed by sequential unified diff patches.
Changes:
- Introduces configurable encoding, seeded patch ordering, and a companion decoder.
- Adds lazy public exports and a default reconstruction template.
- Adds round-trip, validation, registry, and determinism tests, plus usage examples.
| File | Description |
|---|---|
tests/unit/converter/test_seeded_converter_determinism.py |
Adds the encoder to shared determinism checks. |
tests/unit/converter/test_diff_chain_converter.py |
Tests round trips, templates, validation, and registry integration. |
pyrit/datasets/converters/diff_chain.yaml |
Defines the default reconstruction instructions. |
pyrit/converter/diff_chain_converter.py |
Implements encoding, decoding, and diff validation. |
pyrit/converter/__init__.py |
Exposes both converters through lazy imports. |
doc/code/converters/1_text_to_text_converters.py |
Adds an encoding and decoding example. |
doc/code/converters/1_text_to_text_converters.ipynb |
Adds the matching notebook example and output. |
doc/code/converters/0_converters.ipynb |
Lists both converters in the modality table. |
Review effort: Balanced
Co-Authored-By: Claude Sonnet <noreply@anthropic.com>
DiffChainConverter now does one transformation: it always emits the
initial PARTS file and the diff changesets. The include_instructions and
template options are removed; diff_chain.yaml is now a {{ prompt }}
wrapper to stack with PromptTemplateConverter. Tests drop the asyncio
marks, parametrize the validation and corruption cases, and cover the
stacked template. The filename docstring example now matches the
single-segment rule, and a findall result gets the cast the newer ty
from main requires.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The adversarial round-trip input again spells U+2028 and U+2029 as escape sequences instead of raw characters, so editors cannot strip them and silently drop that coverage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hannahwestra25
approved these changes
Dec 4, 2026
hannahwestra25
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for contributing! I merged main, made DiffChainConverter encoding-only with diff_chain.yaml stacked via PromptTemplateConverter, and parametrized its tests.
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
DiffChainConverter(text -> text) andDiffChainDecodeConverter(text -> text) to encode a prompt as an initialPARTSplaceholder file followed by sequential unified diff changesets (v0->vN) in PyRIT converter pipelines.DiffChainConverter: Splits a UTF-8 text prompt intostepssingle-line JSON string slots on a virtual file (v0/spec.pyby default) and emits unified diff hunks (context_lines=0by default), patching slots in a seeded non-sequential order whenshuffle_order=True. It only encodes; to add reconstruction instructions, stackPromptTemplateConverterwith the{{ prompt }}template inpyrit/datasets/converters/diff_chain.yaml.DiffChainDecodeConverter: Companiontext -> textconverter (plusDiffChainConverter.decode()helper) that extracts and applies the unified diff hunks in sequence back into UTF-8 text for pipeline chaining and round-trip verification._LAZY_EXPORTSinpyrit/converter/__init__.py.cc Roman Lutz (@romanlutz) Richard Lundeen (@richlundeen)