pyrit.memory.AttackResultEntry#
- class AttackResultEntry(*, entry)[source]#
Bases:
BaseRepresents 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 MessagePiece.
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)#
Initialize an AttackResultEntry from an AttackResult object.
- Parameters:
entry (AttackResult) – The attack result object to convert into a database entry.
Methods
__init__(*, entry)Initialize an AttackResultEntry from an AttackResult object.
filter_json_serializable_metadata(metadata)Filter a dictionary to only include JSON-serializable values.
Convert this database entry back into an AttackResult object.
Attributes
metadataRefers to the
_schema.MetaDatacollection that will be used for new_schema.Tableobjects.registryRefers to the
_orm.registryin use where new_orm.Mapperobjects will be associated.- 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]#
Convert this database entry back into an AttackResult object.
- Returns:
The reconstructed attack result including related conversations and scores.
- Return type:
AttackResult
- id#
- last_response: Mapped[PromptMemoryEntry | None]#
- objective#
- objective_sha256#
- outcome_reason#
- timestamp#