Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

pyrit.models

Public model exports for PyRIT core data structures and helpers.

pyrit.models is the canonical data layer. Files in this package must import only from the standard library, pydantic, pyrit.common.deprecation, and other pyrit.models.* submodules. The CI test tests/unit/models/test_import_boundary.py enforces this. See .github/instructions/models.instructions.md for the rule.

Identifier types and helpers live in the pyrit.models.identifiers sub-package but are re-exported here, so external callers should import them directly from pyrit.models (e.g. from pyrit.models import ComponentIdentifier). The previous pyrit.identifiers location is kept as a deprecation shim through 0.16.0.

Functions

build_atomic_attack_identifier

build_atomic_attack_identifier(technique_identifier: ComponentIdentifier | None = None, attack_identifier: ComponentIdentifier | None = None, seed_group: SeedGroup | None = None) → ComponentIdentifier

Build a composite ComponentIdentifier for an atomic attack.

The identifier places the attack technique in children["attack_technique"] and all seeds from the seed group in children["seed_identifiers"] for traceability.

Callers that have an AttackTechnique object should pass technique_identifier=attack_technique.get_identifier(). Callers that only have a raw attack strategy identifier (e.g. legacy backward-compat paths) can pass attack_identifier instead, which is wrapped in a minimal technique node automatically.

ParameterTypeDescription
technique_identifier`ComponentIdentifierNone`
attack_identifier`ComponentIdentifierNone`
seed_group`SeedGroupNone`

Returns:

Raises:

build_seed_identifier

build_seed_identifier(seed: Seed) → ComponentIdentifier

Build a ComponentIdentifier from a seed’s behavioral properties.

Captures the seed’s content hash, dataset name, and class type so that different seeds produce different identifiers while the same seed content always produces the same identifier.

ParameterTypeDescription
seedSeedThe seed to build an identifier for.

Returns:

class_name_to_snake_case

class_name_to_snake_case(class_name: str, suffix: str = '') → str

Convert a PascalCase class name to snake_case, optionally stripping a suffix.

ParameterTypeDescription
class_namestrThe class name to convert (e.g., “SelfAskRefusalScorer”).
suffixstrOptional explicit suffix to strip before conversion (e.g., “Scorer”). Defaults to ''.

Returns:

compute_eval_hash

compute_eval_hash(identifier: ComponentIdentifier, child_eval_rules: dict[str, ChildEvalRule], own_rule: Optional[ChildEvalRule] = None) → str

Compute a behavioral equivalence hash for evaluation grouping.

Unlike ComponentIdentifier.hash (which includes all params of self and children), the eval hash applies per-child rules to strip operational params (like endpoint, max_requests_per_minute), exclude children entirely, or filter list items. own_rule extends this to the root entity itself, which is required for leaf components (e.g., a target) whose own params need filtering and which have no relevant children to delegate to. This ensures the same logical configuration on different deployments produces the same eval hash.

Children not listed in child_eval_rules receive full recursive treatment.

When both child_eval_rules is empty and own_rule is None, no filtering occurs and the result equals identifier.hash.

ParameterTypeDescription
identifierComponentIdentifierThe component identity to compute the hash for.
child_eval_rulesdict[str, ChildEvalRule]Per-child eval rules.
own_ruleOptional[ChildEvalRule]Rule applied to the root entity’s own params and fallbacks. Only included_params and param_fallbacks are honored; exclude, included_item_values, and inner_child_name are not meaningful at the root and will raise ValueError if set. Defaults to None. Defaults to None.

Returns:

Raises:

config_hash

config_hash(config_dict: dict[str, Any]) → str

Compute a deterministic SHA256 hash from a config dictionary.

This is the single source of truth for identity hashing across the entire system. The dict is serialized with sorted keys and compact separators to ensure determinism.

ParameterTypeDescription
config_dictDict[str, Any]A JSON-serializable dictionary.

Returns:

Raises:

construct_response_from_request

construct_response_from_request(request: MessagePiece, response_text_pieces: list[str], response_type: PromptDataType = 'text', prompt_metadata: Optional[dict[str, Union[str, int]]] = None, error: PromptResponseError = 'none') → Message

Construct a response message from a request message piece.

ParameterTypeDescription
requestMessagePieceSource request message piece.
response_text_pieceslist[str]Response values to include.
response_typePromptDataTypeData type for original and converted response values. Defaults to 'text'.
prompt_metadataOptional[Dict[str, Union[str, int]]]Additional metadata to merge. Defaults to None.
errorPromptResponseErrorError classification for the response. Defaults to 'none'.

Returns:

data_serializer_factory

data_serializer_factory(data_type: PromptDataType, value: Optional[str] = None, extension: Optional[str] = None, category: AllowedCategories) → DataTypeSerializer

Create a DataTypeSerializer instance.

ParameterTypeDescription
data_typestrThe type of the data (e.g., ‘text’, ‘image_path’, ‘audio_path’).
valuestrThe data value to be serialized. Defaults to None.
extensionOptional[str]The file extension, if applicable. Defaults to None.
categoryAllowedCategoriesThe category or context for the data (e.g., ‘seed-prompt-entries’).

Returns:

Raises:

flatten_to_message_pieces

flatten_to_message_pieces(messages: Sequence[Message]) → MutableSequence[MessagePiece]

Flatten messages into a single list of message pieces.

ParameterTypeDescription
messagesSequence[Message]Messages to flatten.

Returns:

get_all_harm_definitions

get_all_harm_definitions() → dict[str, HarmDefinition]

Load all harm definitions from the standard harm_definition directory.

This function scans the HARM_DEFINITION_PATH directory for all YAML files and loads each one as a HarmDefinition.

Returns:

Raises:

get_all_values

get_all_values(messages: Sequence[Message]) → list[str]

Return all converted values across the provided messages.

ParameterTypeDescription
messagesSequence[Message]Messages to aggregate.

Returns:

group_conversation_message_pieces_by_sequence

group_conversation_message_pieces_by_sequence(message_pieces: Sequence[MessagePiece]) → MutableSequence[Message]

Example:

>>> message_pieces = [
>>>     MessagePiece(conversation_id=1, sequence=1, text="Given this list of creatures, which is your
>>>     favorite:"),
>>>     MessagePiece(conversation_id=1, sequence=2, text="Good question!"),
>>>     MessagePiece(conversation_id=1, sequence=1, text="Raccoon, Narwhal, or Sloth?"),
>>>     MessagePiece(conversation_id=1, sequence=2, text="I'd have to say raccoons are my favorite!"),
>>> ]
>>> grouped_responses = group_conversation_message_pieces(message_pieces)
... [
...     Message(message_pieces=[
...         MessagePiece(conversation_id=1, sequence=1, text="Given this list of creatures, which is your
...         favorite:"),
...         MessagePiece(conversation_id=1, sequence=1, text="Raccoon, Narwhal, or Sloth?")
...     ]),
...     Message(message_pieces=[
...         MessagePiece(conversation_id=1, sequence=2, text="Good question!"),
...         MessagePiece(conversation_id=1, sequence=2, text="I'd have to say raccoons are my favorite!")
...     ])
... ]
ParameterTypeDescription
message_piecesSequence[MessagePiece]A list of MessagePiece objects representing individual message pieces.

Returns:

Raises:

group_message_pieces_into_conversations

group_message_pieces_into_conversations(message_pieces: Sequence[MessagePiece]) → list[list[Message]]

Example:

>>> message_pieces = [
>>>     MessagePiece(conversation_id="conv1", sequence=1, text="Hello"),
>>>     MessagePiece(conversation_id="conv2", sequence=1, text="Hi there"),
>>>     MessagePiece(conversation_id="conv1", sequence=2, text="How are you?"),
>>>     MessagePiece(conversation_id="conv2", sequence=2, text="I'm good"),
>>> ]
>>> conversations = group_message_pieces_into_conversations(message_pieces)
>>> # Returns a list of 2 conversations:
>>> # [
>>> #   [Message(seq=1), Message(seq=2)],  # conv1
>>> #   [Message(seq=1), Message(seq=2)]   # conv2
>>> # ]
ParameterTypeDescription
message_piecesSequence[MessagePiece]A list of MessagePiece objects from potentially different conversations.

Returns:

print_deprecation_message

print_deprecation_message(old_item: type | Callable[..., Any] | str, new_item: type | Callable[..., Any] | str, removed_in: str) → None

Emit a deprecation warning.

ParameterTypeDescription
old_item`typeCallable[..., Any]
new_item`typeCallable[..., Any]
removed_instrThe version in which the deprecated item will be removed

snake_case_to_class_name

snake_case_to_class_name(snake_case_name: str, suffix: str = '') → str

Convert a snake_case name to a PascalCase class name.

ParameterTypeDescription
snake_case_namestrThe snake_case name to convert (e.g., “my_custom”).
suffixstrOptional suffix to append to the class name (e.g., “Scenario” would convert “my_custom” to “MyCustomScenario”). Defaults to ''.

Returns:

sort_message_pieces

sort_message_pieces(message_pieces: list[MessagePiece]) → list[MessagePiece]

Group by conversation_id, ordering by earliest timestamp then sequence.

Conversations are ordered by their earliest piece’s timestamp; pieces within a conversation are ordered by sequence.

ParameterTypeDescription
message_pieceslist[MessagePiece]The pieces to sort. Not mutated.

Returns:

validate_registry_name

validate_registry_name(name: str) → None

Validate that name is a legal registry name.

ParameterTypeDescription
namestrThe name to validate.

Raises:

AtomicAttackEvaluationIdentifier

Bases: EvaluationIdentifier

Evaluation identity for atomic attacks.

Per-child rules:

Non-target children (e.g., request_converters, response_converters, technique_seeds) receive full recursive eval treatment.

AttackOutcome

Bases: str, Enum

Enum representing the possible outcomes of an attack.

Inherits from str so that values serialize naturally in Pydantic models and REST responses without a dedicated mapping function.

AttackResult

Bases: StrategyResult

Base class for all attack results.

Methods:

from_dict

from_dict(data: dict[str, Any]) → AttackResult

Reconstruct an AttackResult from a dictionary.

Deprecated: use model_validate(...) for the canonical Pydantic deserialization. This shim accepts the legacy to_dict() wire shape (base fields only) through the deprecation window.

ParameterTypeDescription
datadict[str, Any]Dictionary as produced by to_dict().

Returns:

get_active_conversation_ids

get_active_conversation_ids() → set[str]

Return the main conversation ID plus pruned (user-visible) related conversation IDs.

Excludes adversarial chat conversations which are internal implementation details.

Returns:

get_all_conversation_ids

get_all_conversation_ids() → set[str]

Return the main conversation ID plus all related conversation IDs.

Returns:

get_attack_strategy_identifier

get_attack_strategy_identifier() → ComponentIdentifier | None

Return the attack strategy identifier from the composite atomic identifier.

This is the non-deprecated replacement for the attack_identifier property. Extracts the "attack" child from the nested "attack_technique" child of atomic_attack_identifier.

Falls back to children["attack"] for rows created before the nested structure was introduced.

Returns:

get_conversations_by_type

get_conversations_by_type(conversation_type: ConversationType) → list[ConversationReference]

Return all related conversations of the requested type.

ParameterTypeDescription
conversation_typeConversationTypeThe type of conversation to filter by.

Returns:

get_pruned_conversation_ids

get_pruned_conversation_ids() → list[str]

Return IDs of pruned (branched) conversations only.

Returns:

includes_conversation

includes_conversation(conversation_id: str) → bool

Check whether a conversation belongs to this attack (main or any related).

ParameterTypeDescription
conversation_idstrThe conversation ID to check.

Returns:

to_dict

to_dict() → dict[str, Any]

Serialize this attack result to a JSON-compatible dictionary.

Deprecated: use model_dump(mode="json") for the canonical Pydantic serialization. This shim preserves the legacy wire shape (base fields only, raw metadata, sorted related_conversations) through the deprecation window.

Returns:

AudioPathDataTypeSerializer

Bases: DataTypeSerializer

Serializer for audio path values stored on disk.

Constructor Parameters:

ParameterTypeDescription
categorystrData category folder name.
prompt_textOptional[str]Optional existing audio path. Defaults to None.
extensionOptional[str]Optional audio extension. Defaults to None.

Methods:

data_on_disk

data_on_disk() → bool

Indicate whether this serializer persists data on disk.

Returns:

AzureBlobStorageIO

Bases: StorageIO

Implementation of StorageIO for Azure Blob Storage.

Constructor Parameters:

ParameterTypeDescription
container_urlOptional[str]Azure Blob container URL. Defaults to None.
sas_tokenOptional[str]Optional SAS token. Defaults to None.
blob_content_typeSupportedContentTypeBlob content type for uploads. Defaults to SupportedContentType.PLAIN_TEXT.

Methods:

create_directory_if_not_exists_async

create_directory_if_not_exists_async(directory_path: Union[Path, str]) → None

Log a no-op directory creation for Azure Blob Storage.

ParameterTypeDescription
directory_pathUnion[Path, str]Requested directory path.

is_file_async

is_file_async(path: Union[Path, str]) → bool

Check whether the path refers to a file (blob) in Azure Blob Storage.

ParameterTypeDescription
pathUnion[Path, str]Blob URL or path to test.

Returns:

parse_blob_url

parse_blob_url(file_path: str) → tuple[str, str]

Parse a blob URL to extract the container and blob name.

ParameterTypeDescription
file_pathstrFull blob URL.

Returns:

Raises:

path_exists_async

path_exists_async(path: Union[Path, str]) → bool

Check whether a given path exists in the Azure Blob Storage container.

ParameterTypeDescription
pathUnion[Path, str]Blob URL or path to test.

Returns:

read_file_async

read_file_async(path: Union[Path, str]) → bytes

Asynchronously reads the content of a file (blob) from Azure Blob Storage.

If the provided path is a full URL (e.g., https://account.blob.core.windows.net/container/dir1/dir2/sample.png), it extracts the relative blob path (e.g., dir1/dir2/sample.png) to correctly access the blob. If a relative path is provided, it will use it as-is.

ParameterTypeDescription
pathstrThe path to the file (blob) in Azure Blob Storage. This can be either a full URL or a relative path.

Returns:

write_file_async

write_file_async(path: Union[Path, str], data: bytes) → None

Write data to Azure Blob Storage at the specified path.

If the provided path is a full URL, the blob name is extracted from it. If a relative path is provided, it is used as the blob name directly.

ParameterTypeDescription
pathUnion[Path, str]Full blob URL or relative blob path.
databytesThe data to write.

BinaryPathDataTypeSerializer

Bases: DataTypeSerializer

Serializer for generic binary path values stored on disk.

Constructor Parameters:

ParameterTypeDescription
categorystrThe category or context for the data.
prompt_textOptional[str]The binary file path or identifier. Defaults to None.
extensionOptional[str]The file extension, defaults to ‘bin’. Defaults to None.

Methods:

data_on_disk

data_on_disk() → bool

Indicate whether this serializer persists data on disk.

Returns:

ChatMessage

Bases: BaseModel

Represents a chat message for API consumption.

The content field can be:

Methods:

from_json

from_json(json_str: str) → ChatMessage

Deserialize a ChatMessage from a JSON string (deprecated, use model_validate_json instead).

ParameterTypeDescription
json_strstrA JSON string representation of a ChatMessage.

Returns:

to_dict

to_dict() → dict[str, Any]

Convert the ChatMessage to a dictionary.

Returns:

to_json

to_json() → str

Serialize the ChatMessage to a JSON string (deprecated, use model_dump_json instead).

Returns:

ChatMessagesDataset

Bases: BaseModel

Represents a dataset of chat messages.

ChildEvalRule

Bases: BaseModel

Per-child configuration for eval-hash computation.

Controls how a specific named child is treated when building the evaluation hash:

ComponentIdentifier

Bases: BaseModel

Immutable snapshot of a component’s behavioral configuration.

A single type for all component identity — scorers, targets, converters, and any future component types all produce a ComponentIdentifier with their relevant params and children.

The hash is content-addressed: two ComponentIdentifiers with the same class, params, and children produce the same hash. This enables deterministic metrics lookup, DB deduplication, and registry keying.

Serialization

model_dump() returns a flat dict where reserved keys (class_name, class_module, hash, pyrit_version, eval_hash, children) sit at the top level alongside the inlined param values. This shape is also the storage / REST format. Pass context={"max_value_length": N} to truncate long string param values. model_validate() accepts the same flat shape (plus a structured form with an explicit params dict).

Mutability

The model is frozen, but params and children are dicts whose contents are not deep-frozen — mutating them after construction creates an identifier whose stored hash no longer matches its content. Treat every identifier as a fully immutable value.

Methods:

from_dict

from_dict(data: dict[str, Any]) → ComponentIdentifier

Reconstruct from a flat dict (deprecated; use model_validate instead).

ParameterTypeDescription
datadict[str, Any]The flat storage dict.

Returns:

get_child

get_child(key: str) → Optional[ComponentIdentifier]

Get a single child by key.

ParameterTypeDescription
keystrChild name.

Returns:

Raises:

get_child_list

get_child_list(key: str) → list[ComponentIdentifier]

Get a list of children by key. Wraps singletons; [] if missing.

ParameterTypeDescription
keystrChild name.

Returns:

of

of(obj: object, params: Optional[dict[str, Any]] = None, children: Optional[dict[str, Union[ComponentIdentifier, list[ComponentIdentifier]]]] = None) → ComponentIdentifier

Build a ComponentIdentifier from a live object instance.

Extracts class_name and class_module from the object’s type automatically. None-valued params and children are filtered out to keep schemas backward-compatible.

ParameterTypeDescription
objobjectThe live object whose class metadata will populate the identifier.
paramsOptional[dict[str, Any]]Optional behavioral params. Defaults to None.
childrenOptional[dict[str, Union[ComponentIdentifier, list[ComponentIdentifier]]]]Optional child identifiers. Defaults to None.

Returns:

to_dict

to_dict(max_value_length: Optional[int] = None) → dict[str, Any]

Return the flat storage dict (deprecated; use model_dump instead).

ParameterTypeDescription
max_value_lengthOptional[int]Optional truncation length for string params. Defaults to None.

Returns:

with_eval_hash

with_eval_hash(eval_hash: str) → ComponentIdentifier

Return a new identifier with eval_hash set.

Builds a fresh instance, passing the existing hash through explicitly so it is preserved rather than recomputed. This matters for identifiers reconstructed from truncated DB data, where recomputing from the truncated params would produce a wrong hash.

ParameterTypeDescription
eval_hashstrThe evaluation hash to attach.

Returns:

ConversationReference

Bases: BaseModel

Immutable reference to a conversation that played a role in the attack.

Methods:

from_dict

from_dict(data: dict[str, str | None]) → ConversationReference

Reconstruct a ConversationReference from a dictionary.

.. deprecated:: Use model_validate instead. This method will be removed in version 0.16.0.

ParameterTypeDescription
data`dict[str, strNone]`

Returns:

to_dict

to_dict() → dict[str, str | None]

Serialize to a JSON-compatible dictionary.

.. deprecated:: Use model_dump with mode="json" instead. This method will be removed in version 0.16.0.

Returns:

ConversationStats

Bases: BaseModel

Lightweight aggregate statistics for a conversation.

Used to build attack summaries without loading full message pieces.

ConversationType

Bases: Enum

Types of conversations that can be associated with an attack.

DataTypeSerializer

Bases: abc.ABC

Abstract base class for data type normalizers.

Responsible for reading and saving multi-modal data types to local disk or Azure Storage Account.

Methods:

data_on_disk

data_on_disk() → bool

Indicate whether the data is stored on disk.

Returns:

get_data_filename

get_data_filename(file_name: Optional[str] = None) → Union[Path, str]

Generate or retrieve a unique filename for the data file (deprecated alias of get_data_filename_async).

ParameterTypeDescription
file_nameOptional[str]Optional file name override. Defaults to None.

Returns:

get_data_filename_async

get_data_filename_async(file_name: Optional[str] = None) → Union[Path, str]

Generate or retrieve a unique filename for the data file.

ParameterTypeDescription
file_nameOptional[str]Optional file name override. Defaults to None.

Returns:

Raises:

get_extension

get_extension(file_path: str) → str | None

Get the file extension from the file path.

ParameterTypeDescription
file_pathstrInput file path.

Returns:

get_mime_type

get_mime_type(file_path: str) → str | None

Get the MIME type of the file path.

ParameterTypeDescription
file_pathstrInput file path.

Returns:

get_sha256

get_sha256() → str

Compute SHA256 hash for this serializer’s current value (deprecated alias of get_sha256_async).

Returns:

get_sha256_async

get_sha256_async() → str

Compute SHA256 hash for this serializer’s current value.

Returns:

Raises:

read_data

read_data() → bytes

Read data from storage (deprecated alias of read_data_async).

Returns:

read_data_async

read_data_async() → bytes

Read data from storage.

Returns:

Raises:

read_data_base64

read_data_base64() → str

Read data and return it as a base64 string (deprecated alias of read_data_base64_async).

Returns:

read_data_base64_async

read_data_base64_async() → str

Read data from storage and return it as a base64 string.

Returns:

save_b64_image

save_b64_image(data: str | bytes, output_filename: str | None = None) → None

Save a base64-encoded image to storage (deprecated alias of save_b64_image_async).

ParameterTypeDescription
data`strbytes`
output_filename`strNone`

save_b64_image_async

save_b64_image_async(data: str | bytes, output_filename: str | None = None) → None

Save a base64-encoded image to storage.

ParameterTypeDescription
data`strbytes`
output_filename(optional, str)filename to store image as. Defaults to UUID if not provided Defaults to None.

Raises:

save_data

save_data(data: bytes, output_filename: Optional[str] = None) → None

Save data to storage (deprecated alias of save_data_async).

ParameterTypeDescription
databytesThe data to be saved.
output_filenameOptional[str]Optional filename to store data as. Defaults to None.

save_data_async

save_data_async(data: bytes, output_filename: Optional[str] = None) → None

Save data to storage.

ParameterTypeDescription
databytesbytes: The data to be saved.
output_filename(optional, str)filename to store data as. Defaults to UUID if not provided Defaults to None.

Raises:

save_formatted_audio

save_formatted_audio(data: bytes, num_channels: int = 1, sample_width: int = 2, sample_rate: int = 16000, output_filename: Optional[str] = None) → None

Save formatted audio data to storage (deprecated alias of save_formatted_audio_async).

ParameterTypeDescription
databytesAudio data bytes.
num_channelsintNumber of channels in audio data. Defaults to 1.
sample_widthintSample width in bytes. Defaults to 2.
sample_rateintSample rate in Hz. Defaults to 16000.
output_filenameOptional[str]Optional filename to store audio as. Defaults to None.

save_formatted_audio_async

save_formatted_audio_async(data: bytes, num_channels: int = 1, sample_width: int = 2, sample_rate: int = 16000, output_filename: Optional[str] = None) → None

Save PCM16 or similarly formatted audio data to storage.

ParameterTypeDescription
databytesbytes with audio data
output_filename(optional, str)filename to store audio as. Defaults to UUID if not provided Defaults to None.
num_channels(optional, int)number of channels in audio data. Defaults to 1 Defaults to 1.
sample_width(optional, int)sample width in bytes. Defaults to 2 Defaults to 2.
sample_rate(optional, int)sample rate in Hz. Defaults to 16000 Defaults to 16000.

Raises:

DiskStorageIO

Bases: StorageIO

Implementation of StorageIO for local disk storage.

Methods:

create_directory_if_not_exists_async

create_directory_if_not_exists_async(path: Union[Path, str]) → None

Asynchronously creates a directory if it doesn’t exist on the local disk.

ParameterTypeDescription
pathPathThe directory path to create.

is_file_async

is_file_async(path: Union[Path, str]) → bool

Check whether the given path is a file (not a directory).

ParameterTypeDescription
pathPathThe path to check.

Returns:

path_exists_async

path_exists_async(path: Union[Path, str]) → bool

Check whether a path exists on the local disk.

ParameterTypeDescription
pathPathThe path to check.

Returns:

read_file_async

read_file_async(path: Union[Path, str]) → bytes

Asynchronously reads a file from the local disk.

ParameterTypeDescription
pathUnion[Path, str]The path to the file.

Returns:

write_file_async

write_file_async(path: Union[Path, str], data: bytes) → None

Asynchronously writes data to a file on the local disk.

ParameterTypeDescription
pathPathThe path to the file.
databytesThe content to write to the file.

EmbeddingData

Bases: BaseModel

Single embedding vector payload with index and object metadata.

EmbeddingResponse

Bases: BaseModel

Embedding API response containing vectors, model metadata, and usage.

Methods:

load_from_file

load_from_file(file_path: Path) → EmbeddingResponse

Load the embedding response from disk.

ParameterTypeDescription
file_pathPathThe path to load the file from.

Returns:

save_to_file

save_to_file(directory_path: Path) → str

Save the embedding response to disk and return the path of the new file.

ParameterTypeDescription
directory_pathPathThe path to save the file to.

Returns:

to_json

to_json() → str

Serialize this embedding response to JSON (deprecated, use model_dump_json instead).

Returns:

EmbeddingSupport

Bases: ABC

Protocol-like interface for classes that generate text embeddings.

Methods:

generate_text_embedding

generate_text_embedding(text: str, kwargs: object = {}) → EmbeddingResponse

Generate text embedding synchronously.

ParameterTypeDescription
textstrThe text to generate the embedding for
**kwargsobjectAdditional arguments to pass to the function. Defaults to {}.

Returns:

generate_text_embedding_async

generate_text_embedding_async(text: str, kwargs: object = {}) → EmbeddingResponse

Generate text embedding asynchronously.

ParameterTypeDescription
textstrThe text to generate the embedding for
**kwargsobjectAdditional arguments to pass to the function. Defaults to {}.

Returns:

EmbeddingUsageInformation

Bases: BaseModel

Token usage metadata returned by an embedding API.

ErrorDataTypeSerializer

Bases: DataTypeSerializer

Serializer for error payloads stored as in-memory text.

Constructor Parameters:

ParameterTypeDescription
prompt_textstrError payload text.

Methods:

data_on_disk

data_on_disk() → bool

Indicate whether this serializer persists data on disk.

Returns:

EvaluationIdentifier

Bases: ABC

Wraps a ComponentIdentifier with domain-specific eval-hash configuration.

Subclasses set CHILD_EVAL_RULES — a mapping of child names to ChildEvalRule instances that control how each child is treated during eval-hash computation. Children not listed receive full recursive treatment.

Leaf-entity subclasses (no relevant children to delegate to) may also set OWN_RULE to filter the root entity’s own params. See ObjectiveTargetEvaluationIdentifier for an example.

The concrete eval_hash property delegates to the module-level compute_eval_hash free function.

HarmDefinition

Bases: BaseModel

A harm definition loaded from a YAML file.

This class represents the structured content of a harm definition YAML file, which includes the version, category name, and scale descriptions that define how to score content for this harm category.

Methods:

from_yaml

from_yaml(harm_definition_path: Union[str, Path]) → HarmDefinition

Load and validate a harm definition from a YAML file.

The function first checks if the path is a simple filename (e.g., “violence.yaml”) and if so, looks for it in the standard HARM_DEFINITION_PATH directory. Otherwise, it treats the path as a full or relative path.

ParameterTypeDescription
harm_definition_pathUnion[str, Path]Path to the harm definition YAML file. Can be a simple filename like “violence.yaml” which will be resolved relative to the standard harm_definition directory, or a full path.

Returns:

Raises:

get_scale_description

get_scale_description(score_value: str) → Optional[str]

Get the description for a specific score value.

ParameterTypeDescription
score_valuestrThe score value to look up (e.g., “1”, “2”).

Returns:

validate_category

validate_category(category: str, check_exists: bool = False) → bool

Validate a harm category name.

Validates that the category name follows the naming convention (lowercase letters and underscores only) and optionally checks if it exists in the standard harm definitions.

ParameterTypeDescription
categorystrThe category name to validate.
check_existsboolIf True, also verify the category exists in get_all_harm_definitions(). Defaults to False. Defaults to False.

Returns:

Identifiable

Bases: ABC

Abstract base class for components that provide a behavioral identity.

Components implement _build_identifier() to return a frozen ComponentIdentifier snapshot. The identifier is built lazily on first access and cached for the component’s lifetime.

Methods:

get_identifier

get_identifier() → ComponentIdentifier

Get the component’s identifier, building it lazily on first access.

The identifier is computed once via _build_identifier() and then cached for subsequent calls. This ensures consistent identity throughout the component’s lifetime while deferring computation until actually needed.

Returns:

IdentifierFilter

Bases: BaseModel

Immutable filter definition for matching JSON-backed identifier properties.

IdentifierType

Bases: Enum

Enumeration of supported identifier types for filtering.

ImagePathDataTypeSerializer

Bases: DataTypeSerializer

Serializer for image path values stored on disk.

Constructor Parameters:

ParameterTypeDescription
categorystrData category folder name.
prompt_textOptional[str]Optional existing image path. Defaults to None.
extensionOptional[str]Optional image extension. Defaults to None.

Methods:

data_on_disk

data_on_disk() → bool

Indicate whether this serializer persists data on disk.

Returns:

Message

Bases: BaseModel

Represents a message in a conversation, for example a prompt or a response to a prompt.

This is a single request to a target. It can contain multiple message pieces.

Methods:

duplicate

duplicate() → Message

Create a deep copy of this message with new IDs and timestamp for all message pieces.

This is useful when you need to reuse a message template but want fresh IDs to avoid database conflicts (e.g., during retry attempts).

The original_prompt_id is intentionally kept the same to track the origin. Generates a new timestamp to reflect when the duplicate is created.

Returns:

duplicate_message

duplicate_message() → Message

Create a deep copy of this message (DEPRECATED — use duplicate).

Returns:

flatten_to_message_pieces

flatten_to_message_pieces(messages: Sequence[Message]) → MutableSequence[MessagePiece]

Flatten messages into a single list of message pieces (DEPRECATED — use the module function).

ParameterTypeDescription
messagesSequence[Message]Messages to flatten.

Returns:

from_dict

from_dict(data: dict[str, Any]) → Message

Reconstruct a Message from a dictionary (DEPRECATED — use model_validate).

ParameterTypeDescription
datadict[str, Any]Dictionary as produced by to_dict().

Returns:

from_prompt

from_prompt(prompt: str, role: ChatMessageRole, prompt_metadata: Optional[dict[str, Union[str, int]]] = None) → Message

Build a single-piece message from prompt text.

ParameterTypeDescription
promptstrPrompt text.
roleChatMessageRoleRole assigned to the message piece.
prompt_metadataOptional[Dict[str, Union[str, int]]]Optional prompt metadata. Defaults to None.

Returns:

from_system_prompt

from_system_prompt(system_prompt: str) → Message

Build a message from a system prompt.

ParameterTypeDescription
system_promptstrSystem instruction text.

Returns:

get_all_values

get_all_values(messages: Sequence[Message]) → list[str]

Return all converted values across the provided messages (DEPRECATED — use the module function).

ParameterTypeDescription
messagesSequence[Message]Messages to aggregate.

Returns:

get_piece

get_piece(n: int = 0) → MessagePiece

Return the nth message piece.

ParameterTypeDescription
nintZero-based index of the piece to return. Defaults to 0.

Returns:

Raises:

get_piece_by_type

get_piece_by_type(data_type: Optional[PromptDataType] = None, original_value_data_type: Optional[PromptDataType] = None, converted_value_data_type: Optional[PromptDataType] = None) → Optional[MessagePiece]

Return the first message piece matching the given data type, or None.

ParameterTypeDescription
data_typeOptional[PromptDataType]Alias for converted_value_data_type (for convenience). Defaults to None.
original_value_data_typeOptional[PromptDataType]The original_value_data_type to filter by. Defaults to None.
converted_value_data_typeOptional[PromptDataType]The converted_value_data_type to filter by. Defaults to None.

Returns:

get_pieces_by_type

get_pieces_by_type(data_type: Optional[PromptDataType] = None, original_value_data_type: Optional[PromptDataType] = None, converted_value_data_type: Optional[PromptDataType] = None) → list[MessagePiece]

Return all message pieces matching the given data type.

ParameterTypeDescription
data_typeOptional[PromptDataType]Alias for converted_value_data_type (for convenience). Defaults to None.
original_value_data_typeOptional[PromptDataType]The original_value_data_type to filter by. Defaults to None.
converted_value_data_typeOptional[PromptDataType]The converted_value_data_type to filter by. Defaults to None.

Returns:

get_value

get_value(n: int = 0) → str

Return the converted value of the nth message piece.

ParameterTypeDescription
nintZero-based index of the piece to read. Defaults to 0.

Returns:

Raises:

get_values

get_values() → list[str]

Return the converted values of all message pieces.

Returns:

is_error

is_error() → bool

Check whether any message piece indicates an error.

Returns:

set_response_not_in_database

set_response_not_in_database() → None

Mark every piece in this message as ephemeral (DEPRECATED — use set_response_not_in_memory).

set_response_not_in_memory

set_response_not_in_memory() → None

Mark every piece in this message as ephemeral.

This is needed when we’re scoring prompts or other things that have not been sent by PyRIT. Ephemeral pieces are skipped by add_message_pieces_to_memory.

set_simulated_role

set_simulated_role() → None

Set the role of all message pieces to simulated_assistant.

This marks the message as coming from a simulated conversation rather than an actual target response.

to_dict

to_dict() → dict[str, object]

Convert the message to a dictionary representation (DEPRECATED — use model_dump).

Includes the original top-level fields (‘role’, ‘converted_value’, ‘conversation_id’, ‘sequence’, ‘converted_value_data_type’) for backward compatibility, plus a ‘pieces’ list containing each piece’s Pydantic JSON dump.

Returns:

validate

validate() → None

Validate that all message pieces are internally consistent.

Retained as a public instance method because callers invoke message.validate() directly. Shadows the deprecated BaseModel.validate classmethod.

Raises:

MessagePiece

Bases: BaseModel

A single piece of a message exchanged with a target.

Targets that accept multimodal input (e.g., text + image) are represented as a list of MessagePiece instances grouped under one Message.

Methods:

copy_lineage_from

copy_lineage_from(source: MessagePiece) → None

Copy lineage metadata from source onto this piece.

Lineage fields are the metadata that tie a piece back to its originating conversation, attack, and target. Mutable containers (labels, prompt_metadata) are shallow-copied so that mutations on one piece do not affect others.

ParameterTypeDescription
sourceMessagePieceThe piece whose lineage will be copied onto self.

from_dict

from_dict(data: dict[str, Any]) → MessagePiece

Construct a MessagePiece from a dict (DEPRECATED — use model_validate).

ParameterTypeDescription
datadict[str, Any]A dict matching the MessagePiece field schema.

Returns:

has_error

has_error() → bool

Return True when response_error is not "none".

Returns:

is_blocked

is_blocked() → bool

Return True when response_error is "blocked".

Returns:

set_piece_not_in_database

set_piece_not_in_database() → None

Mark this piece as ephemeral (DEPRECATED — set not_in_memory directly).

Example::

piece.not_in_memory = True

set_sha256_values_async

set_sha256_values_async() → None

Compute SHA256 hash values for original and converted payloads.

Async because blob payloads may need to be fetched. Must be called explicitly after construction.

to_dict

to_dict() → dict[str, Any]

Return a JSON-mode dict representation (DEPRECATED — use model_dump).

Returns:

to_message

to_message() → Message

Wrap this piece in a single-piece Message.

Returns:

Modality

Bases: str, Enum

Not yet used by TargetCapabilities (which still uses PromptDataType with finer-grained image_path/audio_path/video_path storage tokens). Unifying the two is tracked as a follow-up — see PR #1780.

NextMessageSystemPromptPaths

Bases: enum.Enum

Enum for predefined next message generation system prompt paths.

ObjectiveTargetEvaluationIdentifier

Bases: EvaluationIdentifier

Evaluation identity for an objective target.

Mirrors how ScorerEvaluationIdentifier filters its inner prompt_target child, except the target itself is the root of this identifier (it has no children carrying behavioral configuration). The target’s own params are filtered to the behavioral set (underlying_model_name, temperature, top_p) via OWN_RULE, so the same logical target on different deployments produces the same eval hash.

Wrapper targets (e.g., RoundRobinTarget) are not unwrapped — the caller must pass the inner target’s ComponentIdentifier directly if behavioral equivalence with the unwrapped form is desired. This mirrors the constraint on OWN_RULE (no inner_child_name at the root).

QuestionAnsweringDataset

Bases: BaseModel

Represents a dataset for question answering.

QuestionAnsweringEntry

Bases: BaseModel

Represents a question model.

Methods:

get_correct_answer_text

get_correct_answer_text() → str

Get the text of the correct answer.

Returns:

Raises:

QuestionChoice

Bases: BaseModel

Represents a choice for a question.

RetryEvent

Bases: BaseModel

A single retry attempt captured during attack execution.

Records structured information about a Tenacity retry event, including which component was retrying, what exception triggered the retry, and timing information. These events are collected by a RetryCollector and attached to AttackResult objects for persistence and REST API exposure.

Methods:

from_dict

from_dict(data: dict) → RetryEvent

Deserialize from a dictionary.

.. deprecated:: Use model_validate instead. This method will be removed in version 0.16.0.

ParameterTypeDescription
datadictDictionary representation of a retry event.

Returns:

to_dict

to_dict() → dict

Serialize to a dictionary suitable for JSON storage.

.. deprecated:: Use model_dump with mode="json" instead. This method will be removed in version 0.16.0.

Returns:

ScaleDescription

Bases: BaseModel

A single scale description entry from a harm definition.

ScenarioIdentifier

Bases: BaseModel

Identifier describing the executed scenario.

Methods:

from_dict

from_dict(data: dict[str, Any]) → ScenarioIdentifier

Reconstruct a ScenarioIdentifier from a dictionary.

Deprecated: use model_validate(...) instead.

ParameterTypeDescription
datadict[str, Any]Dictionary as produced by model_dump(by_alias=True).

Returns:

to_dict

to_dict() → dict[str, Any]

Serialize to a JSON-compatible dictionary.

Deprecated: use model_dump(by_alias=True) instead.

Returns:

ScenarioResult

Bases: BaseModel

Scenario result class for aggregating scenario results.

Methods:

from_dict

from_dict(data: dict[str, Any]) → ScenarioResult

Reconstruct a ScenarioResult from a dictionary.

Deprecated: use model_validate(...) instead.

ParameterTypeDescription
datadict[str, Any]Dictionary as produced by model_dump(mode="json").

Returns:

get_display_groups

get_display_groups() → dict[str, list[AttackResult]]

Aggregate attack results by display group.

When a display_group_map was provided, results from multiple atomic_attack_name keys that share the same display group are merged into a single list. When no map was provided, this returns the same structure as attack_results (identity mapping).

Returns:

get_objectives

get_objectives(atomic_attack_name: str | None = None) → list[str]

Get the list of unique objectives for this scenario.

ParameterTypeDescription
atomic_attack_name`strNone`

Returns:

get_strategies_used

get_strategies_used() → list[str]

Get the list of strategies used in this scenario.

Returns:

normalize_scenario_name

normalize_scenario_name(scenario_name: str) → str

Normalize a scenario name to match the stored class name format.

Converts CLI-style snake_case names (e.g., “foundry” or “content_harms”) to PascalCase class names (e.g., “Foundry” or “ContentHarms”) for database queries. If the input is already in PascalCase or doesn’t match the snake_case pattern, it is returned unchanged.

This is the inverse of ScenarioRegistry._class_name_to_scenario_name().

ParameterTypeDescription
scenario_namestrThe scenario name to normalize.

Returns:

objective_achieved_rate

objective_achieved_rate(atomic_attack_name: str | None = None) → int

Get the success rate of this scenario.

ParameterTypeDescription
atomic_attack_name`strNone`

Returns:

to_dict

to_dict() → dict[str, Any]

Serialize this scenario result to a JSON-compatible dictionary.

Deprecated: use model_dump(mode="json", by_alias=True) instead.

Returns:

Score

Bases: BaseModel

Represents a normalized score generated by a scorer component.

Methods:

from_dict

from_dict(data: dict[str, Any]) → Score

Construct a Score from a dict (DEPRECATED — use model_validate).

ParameterTypeDescription
datadict[str, Any]A dict matching the Score field schema.

Returns:

get_value

get_value() → bool | float

Return the value of the score based on its type.

If the score type is “true_false”, it returns True if the score value is “true” (case-insensitive), otherwise it returns False.

If the score type is “float_scale”, it returns the score value as a float.

Returns:

Raises:

to_dict

to_dict() → dict[str, Any]

Return a JSON-mode dict representation (DEPRECATED — use model_dump).

Returns:

validate

validate(args: Any = (), kwargs: Any = {}) → None

Re-run construction-time validation (DEPRECATED).

Validation now happens automatically when a Score is constructed, so there is no need to call this. It is retained only as a no-op-style shim that re-validates the current instance. Any positional/keyword arguments are ignored.

Raises:

ScorerEvaluationIdentifier

Bases: EvaluationIdentifier

Evaluation identity for scorers.

The prompt_target child is filtered to behavioral params only (underlying_model_name, temperature, top_p), so the same scorer configuration on different deployments produces the same eval hash.

Seed

Bases: BaseModel

Represents seed data with various attributes and metadata.

Methods:

escape_for_jinja

escape_for_jinja(value: str) → str

Wrap a string in Jinja2 {% raw %}...{% endraw %} tags to prevent template evaluation.

Use this for any untrusted or externally-fetched text that will be stored as a Seed value, to ensure it is treated as literal text by the Jinja2 renderer.

ParameterTypeDescription
valuestrThe raw string to escape.

Returns:

from_yaml_file

from_yaml_file(file: str | Path) → T

Create a new Seed from a YAML file, marking it as a trusted Jinja2 template.

Thin shim that delegates to load_seed_from_yaml in the yaml_seed_loader module; file I/O and the is_jinja_template trust marker live in the loader module.

ParameterTypeDescription
file`strPath`

Returns:

Raises:

render_template_value

render_template_value(kwargs: Any = {}) → str

Render self.value as a template with provided parameters.

ParameterTypeDescription
kwargsAnyKey-value pairs to replace in the SeedPrompt value. Defaults to {}.

Returns:

Raises:

render_template_value_silent

render_template_value_silent(kwargs: Any = {}) → str

Render self.value as a template with provided parameters. For parameters in the template that are not provided as kwargs here, this function will leave them as is instead of raising an error.

ParameterTypeDescription
kwargsAnyKey-value pairs to replace in the SeedPrompt value. Defaults to {}.

Returns:

Raises:

set_sha256_value_async

set_sha256_value_async() → None

Compute the SHA256 hash value asynchronously. It should be called after prompt value is serialized to text, as file paths used in the value may have changed from local to memory storage paths.

Note, this method is async due to the blob retrieval. And because of that, we opted to take it out of main and setter functions. The disadvantage is that it must be explicitly called.

SeedAttackGroup

Bases: SeedGroup

A group of seeds for use in attack scenarios.

This class extends SeedGroup with attack-specific validation:

All other functionality (simulated conversation, prepended conversation, next_message, etc.) is inherited from SeedGroup.

Methods:

filter_compatible

filter_compatible(seed_groups: Sequence[SeedAttackGroup], technique: SeedAttackTechniqueGroup) → list[SeedAttackGroup]

Return only the seed groups compatible with the given technique.

A seed group is incompatible when the technique carries a SeedSimulatedConversation whose sequence range overlaps with the group’s prompt sequences.

ParameterTypeDescription
seed_groupsSequence[SeedAttackGroup]Candidate seed groups.
techniqueSeedAttackTechniqueGroupThe technique to check compatibility against.

Returns:

is_compatible_with_technique

is_compatible_with_technique(technique: SeedAttackTechniqueGroup) → bool

Check whether this seed group can be merged with the given technique.

A technique containing a SeedSimulatedConversation is incompatible with seed groups that have SeedPrompt objects whose sequences fall within the simulated conversation’s range.

ParameterTypeDescription
techniqueSeedAttackTechniqueGroupThe technique group to check compatibility with.

Returns:

with_technique

with_technique(technique: SeedAttackTechniqueGroup) → SeedAttackGroup

Return a new SeedAttackGroup with technique seeds merged in.

The original group is not mutated. Technique seeds are inserted at technique.insertion_index (or appended at the end when None).

ParameterTypeDescription
techniqueSeedAttackTechniqueGroupA validated SeedAttackTechniqueGroup whose seeds will be merged.

Returns:

Raises:

SeedAttackTechniqueGroup

Bases: SeedGroup

A group of seeds representing a general attack technique.

This class extends SeedGroup with technique-specific validation:

All other functionality (simulated conversation, prepended conversation, next_message, etc.) is inherited from SeedGroup.

SeedDataset

Bases: BaseModel

SeedDataset manages seed prompts plus optional top-level defaults. Prompts are stored as a Sequence[Seed], so references to prompt properties are straightforward (e.g. ds.seeds[0].value).

Methods:

from_dict

from_dict(data: dict[str, Any]) → SeedDataset

Build a SeedDataset, assigning per-seed prompt_group_id by alias.

Default merging now lives in _build_seeds so direct construction and from_dict produce equivalent results. This method handles the YAML-only concerns: rejecting pre-set prompt_group_id on input seeds and resolving prompt_group_alias into a shared prompt_group_id.

ParameterTypeDescription
dataDict[str, Any]Dataset payload with top-level defaults and seed entries.

Returns:

Raises:

from_yaml_file

from_yaml_file(file: str | Path) → SeedDataset

Create a SeedDataset from a YAML file, marking nested seeds as trusted templates.

Thin shim that delegates to pyrit.models.seeds.yaml_seed_loader.load_seed_dataset_from_yaml; file I/O and the is_jinja_template trust marker live in the loader module.

ParameterTypeDescription
file`strPath`

Returns:

Raises:

get_random_values

get_random_values(number: PositiveInt, harm_categories: Sequence[str] | None = None) → Sequence[str]

Extract and return random prompt values from the dataset.

ParameterTypeDescription
numberintThe number of random prompt values to return.
harm_categories`Sequence[str]None`

Returns:

get_values

get_values(first: PositiveInt | None = None, last: PositiveInt | None = None, harm_categories: Sequence[str] | None = None) → Sequence[str]

Extract and return prompt values from the dataset.

ParameterTypeDescription
first`intNone`
last`intNone`
harm_categories`Sequence[str]None`

Returns:

group_seed_prompts_by_prompt_group_id

group_seed_prompts_by_prompt_group_id(seeds: Sequence[Seed]) → Sequence[SeedGroup]

Group the given list of seeds by prompt_group_id and create SeedGroup or SeedAttackGroup instances.

For each group, this method first attempts to create a SeedAttackGroup (which has attack-specific properties like objective). If validation fails, it falls back to a basic SeedGroup.

ParameterTypeDescription
seedsSequence[Seed]A list of Seed objects.

Returns:

render_template_value

render_template_value(kwargs: object = {}) → None

Render seed values as templates using provided parameters.

ParameterTypeDescription
kwargsobjectKey-value pairs to replace in the SeedDataset value. Defaults to {}.

Raises:

SeedGroup

Bases: BaseModel

A container for grouping prompts that need to be sent together.

This class handles:

All prompts in the group share the same prompt_group_id.

Methods:

is_single_part_single_text_request

is_single_part_single_text_request() → bool

Check if this is a single text prompt.

Returns:

is_single_request

is_single_request() → bool

Check if all prompts are in a single sequence.

Returns:

is_single_turn

is_single_turn() → bool

Check if this is a single-turn group (single request without objective).

Returns:

render_template_value

render_template_value(kwargs: Any = {}) → None

Render seed values as templates with provided parameters.

ParameterTypeDescription
kwargsAnyKey-value pairs to replace in seed values. Defaults to {}.

SeedObjective

Bases: Seed

Represents a seed objective with various attributes and metadata.

SeedPrompt

Bases: Seed

Represents a seed prompt with various attributes and metadata.

Methods:

from_messages

from_messages(messages: list[Message], starting_sequence: int = 0, prompt_group_id: uuid.UUID | None = None) → list[SeedPrompt]

Convert a list of Messages to a list of SeedPrompts.

Each MessagePiece becomes a SeedPrompt. All pieces from the same message share the same sequence number, preserving the grouping.

ParameterTypeDescription
messageslist[Message]List of Messages to convert.
starting_sequenceintThe starting sequence number. Defaults to 0. Defaults to 0.
prompt_group_id`uuid.UUIDNone`

Returns:

from_yaml_with_required_parameters

from_yaml_with_required_parameters(template_path: str | Path, required_parameters: list[str], error_message: str | None = None) → SeedPrompt

Load a SeedPrompt from a YAML file and validate that it declares each required parameter.

Thin shim that delegates to pyrit.models.seeds.yaml_seed_loader.load_seed_prompt_from_yaml_with_required_parameters.

ParameterTypeDescription
template_path`strPath`
required_parameterslist[str]List of parameter names that must exist in the template.
error_message`strNone`

Returns:

Raises:

set_encoding_metadata

set_encoding_metadata() → None

Set encoding metadata for the prompt within metadata dictionary. For images, this is just the file format. For audio and video, this also includes bitrate (kBits/s as int), samplerate (samples/second as int), bitdepth (as int), filesize (bytes as int), and duration (seconds as int) if the file type is supported by TinyTag. Example supported file types include: MP3, MP4, M4A, and WAV.

SeedSimulatedConversation

Bases: Seed

Configuration for generating a simulated conversation dynamically.

This class holds the paths and parameters needed to generate prepended conversation content by running an adversarial chat against a simulated (compliant) target.

This is a pure configuration class. The actual generation is performed by generate_simulated_conversation_async in the executor layer, which accepts this config along with runtime dependencies (adversarial_chat target, scorer).

The value property returns a JSON serialization of the config for database storage and deduplication.

Methods:

compute_hash

compute_hash() → str

Compute a deterministic hash of this configuration.

Returns:

get_identifier

get_identifier() → dict[str, Any]

Get an identifier dict capturing this configuration for comparison/storage.

Returns:

load_simulated_target_system_prompt

load_simulated_target_system_prompt(objective: str, num_turns: int, simulated_target_system_prompt_path: str | Path | None = None) → str | None

Load and render the simulated target system prompt.

If no path is provided, returns None (no system prompt). Validates that the template has required objective and num_turns parameters.

ParameterTypeDescription
objectivestrThe objective to render into the template.
num_turnsintThe number of turns to render into the template.
simulated_target_system_prompt_path`strPath

Returns:

Raises:

SimulatedTargetSystemPromptPaths

Bases: enum.Enum

Enum for predefined simulated target system prompt paths.

StorageIO

Bases: ABC

Abstract interface for storage systems (local disk, Azure Storage Account, etc.).

Methods:

create_directory_if_not_exists

create_directory_if_not_exists(path: Union[Path, str]) → None

Create a directory if it does not exist (deprecated alias of create_directory_if_not_exists_async).

ParameterTypeDescription
pathUnion[Path, str]The directory path to create.

create_directory_if_not_exists_async

create_directory_if_not_exists_async(path: Union[Path, str]) → None

Asynchronously creates a directory or equivalent in the storage system if it doesn’t exist.

is_file

is_file(path: Union[Path, str]) → bool

Check whether the given path is a file (deprecated alias of is_file_async).

ParameterTypeDescription
pathUnion[Path, str]The path to check.

Returns:

is_file_async

is_file_async(path: Union[Path, str]) → bool

Asynchronously checks if the path refers to a file (not a directory or container).

path_exists

path_exists(path: Union[Path, str]) → bool

Check whether a path exists (deprecated alias of path_exists_async).

ParameterTypeDescription
pathUnion[Path, str]The path to check.

Returns:

path_exists_async

path_exists_async(path: Union[Path, str]) → bool

Asynchronously checks if a file or blob exists at the given path.

read_file

read_file(path: Union[Path, str]) → bytes

Read a file from storage (deprecated alias of read_file_async).

ParameterTypeDescription
pathUnion[Path, str]The path to the file.

Returns:

read_file_async

read_file_async(path: Union[Path, str]) → bytes

Asynchronously reads the file (or blob) from the given path.

write_file

write_file(path: Union[Path, str], data: bytes) → None

Write data to storage (deprecated alias of write_file_async).

ParameterTypeDescription
pathUnion[Path, str]The path to the file.
databytesThe content to write to the file.

write_file_async

write_file_async(path: Union[Path, str], data: bytes) → None

Asynchronously writes data to the given path.

StrategyResult

Bases: BaseModel, ABC

Base class for all strategy results.

Methods:

duplicate

duplicate() → Self

Create a deep copy of the result.

Returns:

TextDataTypeSerializer

Bases: DataTypeSerializer

Serializer for text and text-like prompt values that stay in-memory.

Constructor Parameters:

ParameterTypeDescription
prompt_textstrPrompt value.
data_typePromptDataTypeText-like prompt data type. Defaults to 'text'.

Methods:

data_on_disk

data_on_disk() → bool

Indicate whether this serializer persists data on disk.

Returns:

UnvalidatedScore

Score is an object that validates all the fields. However, we need a common data class that can be used to store the raw score value before it is normalized and validated.

Methods:

to_score

to_score(score_value: str, score_type: ScoreType) → Score

Convert this unvalidated score into a validated Score.

ParameterTypeDescription
score_valuestrNormalized score value.
score_typeScoreTypeScore type.

Returns:

VideoPathDataTypeSerializer

Bases: DataTypeSerializer

Serializer for video path values stored on disk.

Constructor Parameters:

ParameterTypeDescription
categorystrThe category or context for the data.
prompt_textOptional[str]The video path or identifier. Defaults to None.
extensionOptional[str]The file extension, defaults to ‘mp4’. Defaults to None.

Methods:

data_on_disk

data_on_disk() → bool

Indicate whether this serializer persists data on disk.

Returns: