pyrit.models.SeedGroup#

class SeedGroup(*, seeds: Sequence[Seed | Dict[str, Any]])[source]#

Bases: YamlLoadable

A group of prompts that need to be sent together, along with an objective. This can include multiturn and multimodal prompts. This class is useful when a target requires multiple message pieces to be grouped and sent together. All prompts in the group should share the same prompt_group_id.

__init__(*, seeds: Sequence[Seed | Dict[str, Any]])[source]#

Methods

__init__(*, seeds)

from_yaml_file(file)

Create a new object from a YAML file.

is_single_part_single_text_request()

is_single_request()

is_single_turn()

render_template_value(**kwargs)

Renders self.value as a template, applying provided parameters in kwargs.

set_objective(value)

Set or update the objective for this SeedGroup.

Attributes

harm_categories

Returns a flattened list of all harm categories from all seeds in the group.

next_message

Returns a Message containing only the last turn's prompts if it's a user message.

objective

prepended_conversation

Returns Messages that should be prepended as conversation history.

prompts

user_messages

Returns all prompts as user Messages, one per sequence.

seeds

property harm_categories: List[str]#

Returns a flattened list of all harm categories from all seeds in the group.

Returns:

A list of harm categories from all seeds, with duplicates removed.

Return type:

List[str]

is_single_part_single_text_request() bool[source]#
is_single_request() bool[source]#
is_single_turn() bool[source]#
property next_message: Message | None#

Returns a Message containing only the last turn’s prompts if it’s a user message.

If the last message in the sequence is a user message, returns that message. If the last message is not a user message, returns None.

Returns:

Message for the current/last turn if user role, or None otherwise.

Return type:

Optional[Message]

property objective: SeedObjective | None#
property prepended_conversation: List[Message] | None#

Returns Messages that should be prepended as conversation history.

If the last message in the sequence is a user message, returns all messages except the last one. If the last message is not a user message, returns the entire sequence as conversation history.

Returns:

Messages for conversation history, or None if empty.

Return type:

Optional[List[Message]]

property prompts: Sequence[SeedPrompt]#
render_template_value(**kwargs)[source]#

Renders self.value as a template, applying provided parameters in kwargs.

Parameters:

kwargs – Key-value pairs to replace in the SeedGroup value.

Returns:

None

Raises:

ValueError – If parameters are missing or invalid in the template.

seeds: List[Seed]#
set_objective(value: str) None[source]#

Set or update the objective for this SeedGroup.

If an objective already exists, updates its value. If not, creates a new SeedObjective and inserts it at the beginning.

Parameters:

value (str) – The objective value to set.

property user_messages: List[Message]#

Returns all prompts as user Messages, one per sequence.

This is used by MultiPromptSendingAttack to get user messages for multi-turn attacks. Only returns messages from prompts (not objectives).

Returns:

All user messages in sequence order, or empty list if no prompts.

Return type:

List[Message]