MAINT: Consolidating Target Metadata#2185
Merged
rlundeen2 merged 6 commits intoJul 15, 2026
Merged
Conversation
Create a pyrit.models.target sub-package grouping the prompt-metadata value
objects (token_usage, target_capabilities, json_schema_definition) alongside a
promoted, public JsonResponseConfig.
- Promote private _JsonResponseConfig -> public JsonResponseConfig with a new
to_metadata() method mirroring from_metadata (canonical PyRIT metadata keys).
- Move token_usage, target_capabilities, json_schema_definition, and
json_response_config into pyrit/models/target/ and repoint all importers.
- Dedup the hand-built {"response_format": "json", ...} producers across the
decomposition converter, adversarial conversation manager, fuzzer converters,
and llm scoring to use JsonResponseConfig(...).to_metadata().
- Keep provider translation (build_response_format/_build_text_format)
target-side; only the canonical vocabulary moves to models.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0b94f7cd-2be3-45c2-9f71-6188edf85e90
ResponseHandler previously exposed response_format and response_schema as two independent properties, making the nonsensical "schema set but format unset" state representable and forcing llm_scoring to re-derive a JsonResponseConfig from the loose pair. Collapse them into a single json_response_config property (the canonical value object), so format and schema are always one coherent unit: - Base handler returns a disabled config; JsonSchemaResponseHandler returns an enabled config carrying the optional schema. The wrapper handlers delegate. - llm_scoring now calls response_handler.json_response_config.to_metadata() directly instead of reconstructing the config from two properties. - Scorer identity dicts read json_response_config.json_schema (same value, so scorer identity is unchanged). - Tests updated to the single-property API. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0b94f7cd-2be3-45c2-9f71-6188edf85e90
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0b94f7cd-2be3-45c2-9f71-6188edf85e90
The adversarial metadata now routes through JsonResponseConfig, which copies the schema dict, so assert identity (is) no longer holds; assert value equality. Add coverage for schema-without-response_format (dropped), empty-string schema, and ignoring unrelated metadata keys. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0b94f7cd-2be3-45c2-9f71-6188edf85e90
ValbuenaVC
approved these changes
Jul 15, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0b94f7cd-2be3-45c2-9f71-6188edf85e90
A schema is meaningless without JSON output, so a model validator now coerces enabled=True whenever json_schema is set, removing the contradictory enabled=False-with-schema state. enabled is still needed on its own for JSON-object mode (schema-mode handlers may carry no schema). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0b94f7cd-2be3-45c2-9f71-6188edf85e90
romanlutz
approved these changes
Jul 15, 2026
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
Consolidates the value objects that describe a target interaction and own their
MessagePiece.prompt_metadata(de)serialization. This was first done withPromptUsage, but this PR moves target metadata to the same pattern.1. Group target-metadata models under
pyrit.models.target. Movestoken_usage,target_capabilities,json_schema_definition, and the promotedjson_response_configinto a newpyrit/models/target/sub-package. Everything is still re-exported frompyrit.models, so callers keep importingfrom pyrit.models import ....2. Refactor
JsonResponseConfig. It now owns PyRIT's canonical JSON-response metadata keys via a symmetricfrom_metadata/to_metadatapair.3. Couple response format + schema on
ResponseHandler. Replaces the two independentresponse_format/response_schemaproperties with a singlejson_response_config, so the nonsensical "schema set but format unset" state is no longer representable andllm_scoringno longer re-derives a config from a loose pair.