Skip to content

MAINT Breaking: Creating Conversation class and moving fields off of messagePiece#1950

Open
rlundeen2 wants to merge 4 commits into
microsoft:mainfrom
rlundeen2:rlundeen2/conversation-model
Open

MAINT Breaking: Creating Conversation class and moving fields off of messagePiece#1950
rlundeen2 wants to merge 4 commits into
microsoft:mainfrom
rlundeen2:rlundeen2/conversation-model

Conversation

@rlundeen2
Copy link
Copy Markdown
Contributor

Description

MessagePiece is gigantic - due to deprecating fields via a rename and not having good models. We've moved some pieces to AttackResult, but one field (TargetIdentifier) was tricky to move off because it is tied to a conversation and not necessarily an AttackResult (e.g. an adversarial conversation can have a different TargetIdentifier).

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

Why remove deprecated fields?

This PR creates a conversation model, and moves these properties to the correct place. I opted to not deprecate for a couple reasons:

  • A shim would be silently wrong. The whole point is that the target is conversation-scoped, not piece-scoped. A back-compat property on MessagePiece would have to lazily query the Conversations table per piece, hiding N+1 reads and returning subtly stale/empty values for in-memory pieces that were never persisted. Silent-but-wrong is worse than a loud break.
  • The data already lives elsewhere. attack_identifier is fully covered by AttackResult.atomic_attack_identifier / get_attack_strategy_identifier(), so keeping it on the piece was pure duplication.
  • Real impact. Reduces conversation size 10x, and we're passing this around to/from the db, to/from REST API.
  • Old databases are handled by Alembic, not by a runtime shim (see Migration).

rlundeen2 and others added 4 commits June 6, 2026 20:38
Move prompt_target_identifier to a new Conversations table (hydrated on
read) and remove attack_identifier from MessagePiece (it now lives only on
AttackResult.atomic_attack_identifier). The deprecated attack_id query
filter resolves via get_attack_results() to the attack's main conversation.
Adds the Conversation model and an alembic migration for the Conversations
table, and updates all call sites and unit tests accordingly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Migrate remaining test sites off the removed MessagePiece.prompt_target_identifier
field, thread target_identifier through duplication call sites, and update the
memory schema/data-type docs.

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

# Conflicts:
#	pyrit/memory/azure_sql_memory.py
#	pyrit/memory/sqlite_memory.py
#	tests/unit/executor/attack/single_turn/test_skeleton_key.py
Correct the stale ConversationEntry docstring (target metadata is read via
get_conversation_metadata, not rehydrated onto pieces) and add a regression
test asserting a None target_identifier on a later write does not overwrite
the target already recorded for a conversation.

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.

1 participant