Skip to content

MAINT: Consolidating Target Metadata#2185

Merged
rlundeen2 merged 6 commits into
microsoft:mainfrom
rlundeen2:rlundeen2-prompt-metadata-patterns
Jul 15, 2026
Merged

MAINT: Consolidating Target Metadata#2185
rlundeen2 merged 6 commits into
microsoft:mainfrom
rlundeen2:rlundeen2-prompt-metadata-patterns

Conversation

@rlundeen2

@rlundeen2 rlundeen2 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Description

Consolidates the value objects that describe a target interaction and own their MessagePiece.prompt_metadata (de)serialization. This was first done with PromptUsage, but this PR moves target metadata to the same pattern.

1. Group target-metadata models under pyrit.models.target. Moves token_usage, target_capabilities, json_schema_definition, and the promoted json_response_config into a new pyrit/models/target/ sub-package. Everything is still re-exported from pyrit.models, so callers keep importing from pyrit.models import ....

2. Refactor JsonResponseConfig. It now owns PyRIT's canonical JSON-response metadata keys via a symmetric from_metadata / to_metadata pair.

3. Couple response format + schema on ResponseHandler. Replaces the two independent response_format / response_schema properties with a single json_response_config, so the nonsensical "schema set but format unset" state is no longer representable and llm_scoring no longer re-derives a config from a loose pair.

rlundeen2 and others added 4 commits July 14, 2026 09:25
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
Comment thread pyrit/models/target/json_response_config.py Outdated
rlundeen2 and others added 2 commits July 15, 2026 11:55
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
@rlundeen2 rlundeen2 enabled auto-merge July 15, 2026 21:02
@rlundeen2 rlundeen2 added this pull request to the merge queue Jul 15, 2026
Merged via the queue into microsoft:main with commit 9a954d4 Jul 15, 2026
47 checks passed
@rlundeen2 rlundeen2 deleted the rlundeen2-prompt-metadata-patterns branch July 15, 2026 21:24
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.

3 participants