Skip to content

MAINT: Making Score a Pydantic model#1891

Merged
rlundeen2 merged 7 commits into
microsoft:mainfrom
rlundeen2:rlundeen2/probable-potato
Jun 2, 2026
Merged

MAINT: Making Score a Pydantic model#1891
rlundeen2 merged 7 commits into
microsoft:mainfrom
rlundeen2:rlundeen2/probable-potato

Conversation

@rlundeen2
Copy link
Copy Markdown
Contributor

This converts Score to a Pydantic BaseModel. It is phase 5 of the pyrit.models refactor: https://gist.github.com/rlundeen2/3e8daa8e12a11b4b6e52587b3c9b1dca

rlundeen2 and others added 5 commits June 1, 2026 15:20
Convert Score from a hand-written class to a Pydantic v2 BaseModel, mirroring the MessagePiece refactor (PR microsoft#1871). UnvalidatedScore stays a dataclass. Move the ComponentIdentifierField alias into score.py and have message_piece.py consume it plus the native Score type. Switch internal serialization paths (attack_result, sqlite_memory) to model_dump/model_validate so the deprecated to_dict/from_dict shims don't fire. Make score_value_description/score_rationale/score_metadata accept None to preserve the old permissive behavior, and update tests that relied on the unvalidated class.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…time

All Score timestamp inputs are already tz-aware (memory wraps with _ensure_utc, scorers pass MessagePiece.timestamp, UnvalidatedScore.to_score falls back to now(utc)), so the before-validator was redundant. Naive datetimes now raise via AwareDatetime instead of being silently coerced.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reintroduces Score.validate() as a deprecated no-op-style method that re-runs construction-time validation on the current instance. Args are ignored; it no longer needs to be called explicitly since validation happens at construction.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tato

# Conflicts:
#	pyrit/models/message_piece.py
#	pyrit/models/score.py
Comment thread pyrit/models/score.py Outdated
rlundeen2 and others added 2 commits June 2, 2026 14:21
Replace Optional[X]/Union[...] with X | None and PEP 604 unions per the PyRIT style guide (str | None, dict[str, str | int | float] | None, etc.) across Score and UnvalidatedScore.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tato

# Conflicts:
#	pyrit/models/message_piece.py
@rlundeen2 rlundeen2 enabled auto-merge June 2, 2026 21:38
@rlundeen2 rlundeen2 added this pull request to the merge queue Jun 2, 2026
Merged via the queue into microsoft:main with commit b3b018f Jun 2, 2026
52 checks passed
@rlundeen2 rlundeen2 deleted the rlundeen2/probable-potato branch June 2, 2026 22:11
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