Skip to content

FEAT: Add JsonFieldConverter - #4385

Open
Dev3 ^~^ (shashank03-dev) wants to merge 2 commits into
microsoft:mainfrom
shashank03-dev:feat/json-field-converter
Open

Dev3 ^~^ (shashank03-dev) wants to merge 2 commits into
microsoft:mainfrom
shashank03-dev:feat/json-field-converter

Conversation

@shashank03-dev

Copy link
Copy Markdown
Contributor

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 state can 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 json over about 24,000 conversions found no wrong splices.

Not tested: other operating systems, or a live provider through this PR alone.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread pyrit/converter/json_field_converter.py Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants