pyrit.memory.AttackResultEntry#

class AttackResultEntry(*, entry)[source]#

Bases: Base

Represents the attack result data in the database.

Parameters:
  • __tablename__ (str) – The name of the database table.

  • __table_args__ (dict) – Additional arguments for the database table.

  • id (Uuid) – The unique identifier for the attack result entry.

  • conversation_id (str) – The unique identifier of the conversation that produced this result.

  • objective (str) – Natural-language description of the attacker’s objective.

  • attack_identifier (dict[str, str]) – Identifier of the attack (e.g., name, module).

  • objective_sha256 (str) – The SHA256 hash of the objective.

  • last_response_id (Uuid) – Foreign key to the last response PromptRequestPiece.

  • last_score_id (Uuid) – Foreign key to the last score ScoreEntry.

  • executed_turns (int) – Total number of turns that were executed.

  • execution_time_ms (int) – Total execution time of the attack in milliseconds.

  • outcome (AttackOutcome) – The outcome of the attack, indicating success, failure, or undetermined.

  • outcome_reason (str) – Optional reason for the outcome, providing additional context.

  • attack_metadata (dict[str, Any]) – Metadata can be included as key-value pairs to provide extra context.

  • pruned_conversation_ids (List[str]) – List of conversation IDs that were pruned from the attack.

  • adversarial_chat_conversation_ids (List[str]) – List of conversation IDs used for adversarial chat.

  • timestamp (DateTime) – The timestamp of the attack result entry.

  • last_response (PromptMemoryEntry) – Relationship to the last response prompt memory entry.

  • last_score (ScoreEntry) – Relationship to the last score entry.

__str__()#

Returns a string representation of the attack result entry.

__init__(*, entry)#

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

Methods

__init__(*, entry)

A simple constructor that allows initialization from kwargs.

filter_json_serializable_metadata(metadata)

Filter a dictionary to only include JSON-serializable values.

get_attack_result()

Attributes

adversarial_chat_conversation_ids

attack_identifier

attack_metadata

conversation_id

executed_turns

execution_time_ms

id

last_response

last_response_id

last_score

last_score_id

metadata

Refers to the _schema.MetaData collection that will be used for new _schema.Table objects.

objective

objective_sha256

outcome

outcome_reason

pruned_conversation_ids

registry

Refers to the _orm.registry in use where new _orm.Mapper objects will be associated.

timestamp

adversarial_chat_conversation_ids: Mapped[List[str] | None]#
attack_identifier: Mapped[dict[str, str]]#
attack_metadata: Mapped[dict[str, str | int | float | bool]]#
conversation_id#
executed_turns#
execution_time_ms#
static filter_json_serializable_metadata(metadata: Dict[str, Any]) Dict[str, Any][source]#

Filter a dictionary to only include JSON-serializable values.

This function iterates through the metadata dictionary and keeps only values that can be serialized to JSON, discarding any non-serializable objects.

Parameters:

metadata – Dictionary with potentially non-serializable values

Returns:

Dictionary with only JSON-serializable values

get_attack_result() AttackResult[source]#
id#
last_response: Mapped[PromptMemoryEntry | None]#
last_response_id: Mapped[UUID | None]#
last_score: Mapped[ScoreEntry | None]#
last_score_id: Mapped[UUID | None]#
objective#
objective_sha256#
outcome: Mapped[Literal['success', 'failure', 'undetermined']]#
outcome_reason#
pruned_conversation_ids: Mapped[List[str] | None]#
timestamp#