Repository navigation
FEAT: Add JsonFieldConverter - #4385
Open
Dev3 ^~^ (shashank03-dev) wants to merge 2 commits into
Open
Dev3 ^~^ (shashank03-dev) wants to merge 2 commits into
Dev3 ^~^ (shashank03-dev) wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The wrapper applies random context inconsistently across conversion entry points, so the same configured seed can yield different results in direct conversion and an attack pipeline.
1 open issue
What changed in this PR
Adds JsonFieldConverter to apply an existing text converter to one JSON string selected by JSON Pointer, preserving the rest of the request byte for byte. This provides the field-only conversion needed for decision-model testing in #3246 without a decision-specific wrapper.
Changes:
- Implements JSON Pointer resolution, field-local token conversion, and public lazy export.
- Adds validation, registry, backend preview, and LiteLLM request-shape tests.
- Documents whole-field and marked-region conversion.
| File | Description |
|---|---|
tests/unit/registry/converter_identifier_samples.py |
Adds JSON Pointer identifier samples. |
tests/unit/converter/test_json_field_converter.py |
Tests field conversion, validation, composition, and request preservation. |
tests/unit/backend/test_converter_service.py |
Tests API construction and conversion previews. |
pyrit/converter/json_field_converter.py |
Implements pointer-selected string conversion. |
pyrit/converter/__init__.py |
Exposes the converter through lazy imports. |
doc/code/converters/6_selectively_converting.py |
Adds field-conversion examples. |
doc/code/converters/6_selectively_converting.ipynb |
Adds matching notebook examples and outputs. |
doc/code/converters/0_converters.ipynb |
Lists the converter in the modality table. |
Review effort: Balanced
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.

Related to #3246, split from #3250.
Adds a converter that applies another text converter to one string in a JSON request, selected with a JSON Pointer. The rest of the request stays byte for byte, so a decision model's
statecan be converted without touching its questions. This replaces the decision-specific state wrapper from #3250.Tests: pointer resolution, malformed input, duplicate keys, lone surrogates, token selection, stacked converters, the backend API path, and the LiteLLM request shape. 39,835 unit tests pass locally on Python 3.14, the new tests pass on 3.11, and diff coverage is 100%. A randomized check against Python's
jsonover about 24,000 conversions found no wrong splices.Not tested: other operating systems, or a live provider through this PR alone.