pyrit.executor.attack.ConsoleAttackResultPrinter#

class ConsoleAttackResultPrinter(*, width: int = 100, indent_size: int = 2, enable_colors: bool = True)[source]#

Bases: AttackResultPrinter

Console printer for attack results with enhanced formatting.

This printer formats attack results for console display with optional color coding, proper indentation, text wrapping, and visual separators. Colors can be disabled for consoles that don’t support ANSI characters.

__init__(*, width: int = 100, indent_size: int = 2, enable_colors: bool = True)[source]#

Initialize the console printer.

Parameters:
  • width (int) – Maximum width for text wrapping. Must be positive. Defaults to 100.

  • indent_size (int) – Number of spaces for indentation. Must be non-negative. Defaults to 2.

  • enable_colors (bool) – Whether to enable ANSI color output. When False, all output will be plain text without colors. Defaults to True.

Raises:

ValueError – If width <= 0 or indent_size < 0.

Methods

__init__(*[, width, indent_size, enable_colors])

Initialize the console printer.

print_conversation_async(result, *[, ...])

Print the conversation history to console with enhanced formatting.

print_result_async(result, *[, ...])

Print the complete attack result to console.

print_summary_async(result)

Print a summary of the attack result with enhanced formatting.

async print_conversation_async(result: AttackResult, *, include_auxiliary_scores: bool = False, include_reasoning_trace: bool = False) None[source]#

Print the conversation history to console with enhanced formatting.

Displays the full conversation between user and assistant, including: - Turn numbers - Role indicators (USER/ASSISTANT) - Original and converted values when different - Images if present - Scores for each response

Parameters:
  • result (AttackResult) – The attack result containing the conversation_id. Must have a valid conversation_id attribute.

  • include_auxiliary_scores (bool) – Whether to include auxiliary scores in the output. Defaults to False.

  • include_reasoning_trace (bool) – Whether to include model reasoning trace in the output for applicable models. Defaults to False.

async print_result_async(result: AttackResult, *, include_auxiliary_scores: bool = False) None[source]#

Print the complete attack result to console.

This method orchestrates the printing of all components of an attack result, including header, summary, conversation history, metadata, and footer.

Parameters:
  • result (AttackResult) – The attack result to print. Must not be None.

  • include_auxiliary_scores (bool) – Whether to include auxiliary scores in the output. Defaults to False.

async print_summary_async(result: AttackResult) None[source]#

Print a summary of the attack result with enhanced formatting.

Displays: - Basic information (objective, attack type, conversation ID) - Execution metrics (turns executed, execution time) - Outcome information (status, reason) - Final score if available

Parameters:

result (AttackResult) – The attack result to summarize. Must contain objective, attack_identifier, conversation_id, executed_turns, execution_time_ms, outcome, and optionally outcome_reason and last_score attributes.