Repository navigation
FEAT: Add JsonFieldConverter - #4385
Dev3 ^~^ (shashank03-dev) wants to merge 8 commits into
Conversation
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
hannahwestra25
left a comment
There was a problem hiding this comment.
Merging main conflicts only in the generated table in doc/code/converters/0_converters.ipynb: keep both main's ImageBlurConverter row and this PR's JsonFieldConverter row, then renumber the rows consecutively.
|
hannahwestra25 the deep-JSON test uses your |

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.