Skip to content

Preserve roles when converting messages to seed prompts#1508

Merged
rlundeen2 merged 1 commit intomicrosoft:mainfrom
biefan:preserve-seed-prompt-roles
Apr 13, 2026
Merged

Preserve roles when converting messages to seed prompts#1508
rlundeen2 merged 1 commit intomicrosoft:mainfrom
biefan:preserve-seed-prompt-roles

Conversation

@biefan
Copy link
Copy Markdown
Contributor

@biefan biefan commented Mar 17, 2026

Summary

  • preserve API-compatible message roles when converting Message objects to SeedPrompt records
  • keep the existing simulated_assistant -> assistant normalization by relying on message.api_role
  • add regression coverage for system, developer, tool, and simulated_assistant

Problem

SeedPrompt.from_messages() currently collapses every non-assistant message role to user. That loses supported roles such as system, developer, and tool when messages are converted into seed prompts.

Validation

  • .venv/bin/pytest tests/unit/models/test_seed.py -q
  • .venv/bin/ruff check pyrit/models/seeds/seed_prompt.py tests/unit/models/test_seed.py

Copy link
Copy Markdown
Contributor

@romanlutz romanlutz left a comment

Choose a reason for hiding this comment

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

This looks correct. I'm wondering why we had that here...

@rlundeen2 rlundeen2 requested a review from Copilot April 13, 2026 17:18
@rlundeen2 rlundeen2 self-assigned this Apr 13, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Preserves API-compatible message roles during MessageSeedPrompt conversion, preventing loss of roles like system, developer, and tool.

Changes:

  • Update SeedPrompt.from_messages() to use message.api_role directly instead of collapsing non-assistant roles to user.
  • Add regression tests covering system, developer, tool, and simulated_assistant → assistant normalization.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/unit/models/test_seed.py Adds parametric regression test to ensure supported roles are preserved (and simulated_assistant normalizes to assistant).
pyrit/models/seeds/seed_prompt.py Adjusts conversion logic to preserve message.api_role when creating SeedPrompt records.

@rlundeen2 rlundeen2 merged commit 6744a37 into microsoft:main Apr 13, 2026
41 checks passed
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.

4 participants