Skip to content

MAINT: Minor pyrit.model module reorganization #1999

Open
rlundeen2 wants to merge 2 commits into
microsoft:mainfrom
rlundeen2:rlundeen2/models-relocate-result-message-types
Open

MAINT: Minor pyrit.model module reorganization #1999
rlundeen2 wants to merge 2 commits into
microsoft:mainfrom
rlundeen2:rlundeen2/models-relocate-result-message-types

Conversation

@rlundeen2

Copy link
Copy Markdown
Contributor

Moving some modules around to where they make sense. Deprecation seemed more confusing than helpful since everything is imported from the base.

Move ScenarioResult into pyrit.models.results and ConversationReference /
ChatMessage into pyrit.models.messages. These symbols are re-exported from
pyrit.models, so the canonical import stays `from pyrit.models import X` and
no deprecation shim is needed at the old submodule paths.

Switch all external consumers and tests to the short-form package-root import
per the style guide, keep same-package imports on the specific module to avoid
cycles, and clarify that ChatMessage is the OpenAI Chat Completions wire shape
(distinct from the domain Message/MessagePiece). Adds a dedicated Conversation
model test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rlundeen2 rlundeen2 changed the title MAINT: Minor module reorganization MAINT: Minor pyrit.model module reorganization Jun 12, 2026
@adrian-gavrila adrian-gavrila self-assigned this Jun 15, 2026
Comment thread pyrit/models/messages/__init__.py Outdated
SeedSimulatedConversation,
SeedType,
)
from pyrit.models.scenario_result import ScenarioRunState

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why don't we do something like

_MOVED_TO_MEMORY_STORAGE: dict[str, str] = {
?

if not, we should at least label the PR as breaking

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rich agrees with this comment but it is copilot generated: We went the other direction and removed the deep-path shims entirely instead of adding more. The rule we settled on: if a symbol only moves within pyrit.models and is still re-exported from the package root, there's no shim — from pyrit.models import ScenarioRunState (and every other symbol) keeps working, and that's the only import form we support/document. Warning shims are reserved for symbols that actually leave the package (e.g. the pyrit.memory.storage moves). For consistency I also deleted the older silent shims that were still lingering (attack_result, message, message_piece, strategy_result). The only thing that breaks is the uncanonical deep path from pyrit.models.scenario_result import ..., which was never the documented import.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(it got messy having so many deprecated shims, and I think when the import mostly stays the same it's likely okay to just move it)

@adrian-gavrila adrian-gavrila left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overll looks good, left a couple of small comments to consider

Comment thread pyrit/models/__init__.py
group_message_pieces_into_conversations,
sort_message_pieces,
)
from pyrit.models.messages.chat_message import (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we add a back-compat shim at every old path? message.py, message_piece.py, attack_result.py, strategy_result.py all still have them.

from pyrit.models import X still resolves for all three so nothing in-repo breaks, but from pyrit.models.scenario_result import ScenarioResult is now a hard ModuleNotFoundError for any downstream code on the old deep path. I think we should either add the 3 shims or add a note about the breaking change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rich agrees with this comment but it is copilot generated: Good catch on the inconsistency. Rather than add three more shims, we removed the deep-path shims altogether — including the four existing silent ones (message, message_piece, attack_result, strategy_result). Principle: internal pyrit.models reshuffles stay shim-free because everything is re-exported from pyrit.models (the canonical import); warning shims are only for symbols that move to a different package. So the only thing that breaks is from pyrit.models.scenario_result import X, which was never a supported path — from pyrit.models import X is unchanged.

Comment thread pyrit/models/messages/__init__.py
Address PR review: the deep-path back-compat shims for purely internal
pyrit.models relocations add confusion rather than value, since every symbol
stays re-exported from pyrit.models. Delete the lingering silent shims at
attack_result.py, message.py, message_piece.py, and strategy_result.py so the
single canonical import (from pyrit.models import X) is the only supported form.
Warning shims remain only where a symbol genuinely left the package (the
pyrit.memory.storage moves).

Export ToolCall from pyrit.models so it is reachable via the package root like
every other messages symbol, and fold the one-class conversation.py module into
conversations.py to remove the near-duplicate module name.

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.

3 participants