Skip to content

MAINT: Convert leaf model types to Pydanticv2#1769

Merged
rlundeen2 merged 3 commits into
microsoft:mainfrom
rlundeen2:rlundeen2/models-pydantic-phase-1
May 27, 2026
Merged

MAINT: Convert leaf model types to Pydanticv2#1769
rlundeen2 merged 3 commits into
microsoft:mainfrom
rlundeen2:rlundeen2/models-pydantic-phase-1

Conversation

@rlundeen2
Copy link
Copy Markdown
Contributor

@rlundeen2 rlundeen2 commented May 21, 2026

Converts the leaf modules in pyrit/models/ to pydantic.BaseModel in place, with no file moves and no public API breaks.

Contributors: see pyrit.shared design for more context [phase 1]

Convert leaf modules in pyrit.models to Pydantic v2 BaseModel in place:

- retry_event.RetryEvent

- conversation_reference.ConversationReference (frozen, hash by conversation_id)

- conversation_stats.ConversationStats (frozen, PREVIEW_MAX_LEN ClassVar)

- harm_definition.HarmDefinition / ScaleDescription

- json_response_config._JsonResponseConfig

RetryEvent and ConversationReference keep deprecated to_dict / from_dict thin wrappers that emit a DeprecationWarning via pyrit.common.deprecation (removed_in=0.16.0). All in-repo callers migrated to model_dump(mode=\"json\") / model_validate (pyrit.models.attack_result, pyrit.memory.memory_models). Verified via repo-wide grep that no internal call sites remain outside the explicit deprecation-coverage tests.

No public API breaks: existing import paths and kwarg-only construction preserved.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rlundeen2 rlundeen2 marked this pull request as draft May 21, 2026 03:29
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rlundeen2 rlundeen2 marked this pull request as ready for review May 21, 2026 16:25
@rlundeen2 rlundeen2 changed the title refactor(models): convert leaf types to Pydantic v2 BaseModel (Phase 1) MAINT: Convert leaf model types to Pydanticv2 May 21, 2026
Copy link
Copy Markdown
Contributor

@adrian-gavrila adrian-gavrila left a comment

Choose a reason for hiding this comment

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

LGTM, left one small comment but it is certainly not blocking.

Comment thread pyrit/models/json_response_config.py
…chema clash

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rlundeen2 rlundeen2 enabled auto-merge May 27, 2026 19:09
@rlundeen2 rlundeen2 added this pull request to the merge queue May 27, 2026
Merged via the queue into microsoft:main with commit ed8f6cf May 27, 2026
48 checks passed
@rlundeen2 rlundeen2 deleted the rlundeen2/models-pydantic-phase-1 branch May 27, 2026 19:43
romanlutz added a commit to romanlutz/PyRIT that referenced this pull request May 28, 2026
…icks

The `check-no-rest-roles` pre-commit hook added in microsoft#1823
flags four `:meth:model_dump` / `:meth:model_validate` references in
`pyrit/models/conversation_reference.py` and `pyrit/models/retry_event.py`
that landed via PR microsoft#1769 before the hook existed. Replace them with plain
double-backticks so the hook passes cleanly on this stacked branch and the
deprecation notices render as readable code spans under MyST instead of
literal `:meth:
ame` text.

`model_dump` / `model_validate` are Pydantic methods, not PyRIT API, so
the auto-linker leaves them as plain code spans (correct: there is nothing
in our docs to link them to).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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