Skip to content

MAINT: Strongly Typed Identifiers#2007

Open
rlundeen2 wants to merge 5 commits into
microsoft:mainfrom
rlundeen2:rlundeen2/refactor-component-descriptors
Open

MAINT: Strongly Typed Identifiers#2007
rlundeen2 wants to merge 5 commits into
microsoft:mainfrom
rlundeen2:rlundeen2/refactor-component-descriptors

Conversation

@rlundeen2

Copy link
Copy Markdown
Contributor

A ComponentIdentifier already carries everything that identifies a target / converter / scorer / attack: class_name, class_module, behavioral params, and child identifiers. But every consumer read that data by poking identifier.params["temperature"] by string key, and the backend re-derived the same shapes by hand into loosely-typed per-kind dicts inside mappers. These are really strongly-typed identifiers and now live in pyrit.models.identifiers as such, so any consumer can read (and construct) them with types.

Phase 19 of pyrit.models refactor: https://gist.github.com/rlundeen2/3e8daa8e12a11b4b6e52587b3c9b1dca

rlundeen2 and others added 3 commits June 14, 2026 11:29
Introduce typed identifiers as subclasses of ComponentIdentifier in
pyrit/models/identifiers/ (TargetIdentifier, ScorerIdentifier,
ConverterIdentifier, AttackIdentifier, AttackTechniqueIdentifier,
SeedIdentifier, AtomicAttackIdentifier). Each promotes its identity-defining
params/children into typed fields while mirroring them back so hashes stay
stable with plain ComponentIdentifiers.

Key changes:
- ComponentIdentifier: tighten params to JSON-scalar/list/dict values and
  children to ComponentIdentifier instances, validated/coerced via a
  model_validator(mode="before") plus the .of(...) factory; rename
  .promote() to .from_component_identifier().
- Identifiable._create_identifier subclasses build the correct typed
  identifier with strongly-typed named params (targets, scorers, converters,
  attacks, attack techniques).
- Move TargetCapabilities to a pydantic model in pyrit/models; capabilities
  are no longer part of target identity.
- Fold free builders into classmethods: build_seed_identifier ->
  SeedIdentifier.from_seed and build_atomic_attack_identifier ->
  AtomicAttackIdentifier.build; remove the free functions, their exports, and
  the stale pyrit/identifiers/atomic_attack_identifier.py shim.
- Narrow ComponentIdentifier usages to specific typed identifiers where
  appropriate; promote score_aggregator and seed data_type into identity.
- Documentation and docstrings converted to MyST double-backtick style.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread doc/code/targets/0_prompt_targets.md Outdated
Comment thread pyrit/backend/mappers/converter_mappers.py Outdated
Comment thread pyrit/models/identifiers/__init__.py
- Export get_known_capabilities from pyrit.prompt_target; update target docs to use it

- Use pyrit.backend.models / pyrit.models roots in converter and target mappers

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rlundeen2 rlundeen2 enabled auto-merge June 15, 2026 22: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.

2 participants