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.output

Output module for displaying attack, scenario, and scorer results.

This module provides:

File names indicate output format (pretty.py = ANSI-colored, markdown.py = Markdown). Abstract methods inside each printer determine the data source (memory, REST, fixtures).

Functions

get_default_sink

get_default_sink(default: type[Sink] | None = None) → Sink

Return the appropriate default sink for the current environment.

When default is None, auto-detects: uses IPythonMarkdownSink inside Jupyter/IPython notebooks, otherwise StdoutSink.

ParameterTypeDescription
defaulttype[Sink] | NoneSink class to instantiate. None means auto-detect based on environment. Defaults to None.

Returns:

get_lazy_dir

get_lazy_dir(module_globals: dict[str, Any], exports: Mapping[str, LazyExport]) → list[str]

Return package attributes and unresolved public exports.

ParameterTypeDescription
module_globalsdict[str, Any]The package globals.
exportsMapping[str, LazyExport]Public names and their implementation locations.

Returns:

output_attack_async

output_attack_async(result: AttackResult, format: OutputFormat = 'pretty', sink: Sink | None = None, include_auxiliary_scores: bool = False, include_pruned_conversations: bool = False, include_adversarial_conversation: bool = False, include_reasoning_summaries: bool = False, blur_images: bool = False, blur_radius: int = 20, blurred_dir: str | os.PathLike[str] | None = None) → None

Print an attack result in the specified format to the specified destination.

ParameterTypeDescription
resultAttackResultThe attack result to print.
formatOutputFormatOutput format — “pretty” or “markdown”. Defaults to “pretty”.
sinkSink | NoneOutput sink. Defaults to StdoutSink for “pretty”; auto-detects (IPythonMarkdownSink in notebooks, StdoutSink otherwise) for “markdown”.
include_auxiliary_scoresboolWhether to include auxiliary scores. Defaults to False.
include_pruned_conversationsboolWhether to include pruned conversations. Defaults to False.
include_adversarial_conversationboolWhether to include the adversarial conversation. Defaults to False.
include_reasoning_summariesboolWhether to include the reasoning summaries. Defaults to False.
blur_imagesboolIf True, apply a Gaussian blur to image outputs before rendering them. For “pretty” output, image bytes are blurred in-memory before display. For “markdown” output, a blurred file is written to disk and the markdown links to it instead of the original. The original image file is not modified and remains accessible on disk; this flag is intended to reduce reviewer exposure, not to enforce access control. If blurring fails for any reason (I/O error, decode error, etc.), a warning is logged and a plain-text link to the original is emitted instead of an inline image — the original is not silently rendered. Defaults to False.
blur_radiusintGaussian blur radius applied when blur_images is True. Defaults to 20.
blurred_dirstr | PathLike | NoneFor “markdown” output, directory to write blurred copies into. Defaults to None (sibling of the original). Ignored when format != "markdown".

Raises:

Examples:

output_conversation_async

output_conversation_async(messages: list[Message], format: OutputFormat = 'pretty', sink: Sink | None = None, include_scores: bool = False, include_reasoning_summaries: bool = False, blur_images: bool = False, blur_radius: int = 20) → None

Print a conversation message history in the specified format.

ParameterTypeDescription
messageslist[Message]The messages to print.
formatOutputFormatOutput format — “pretty” or “json”. Defaults to “pretty”.
sinkSink | NoneOutput sink. Defaults to StdoutSink.
include_scoresboolWhether to include scores. Defaults to False.
include_reasoning_summariesboolWhether to include reasoning summaries. Defaults to False.
blur_imagesboolIf True, apply a Gaussian blur to image outputs before rendering them. For “pretty” output (the only format that renders images), image bytes are blurred in-memory before display. The original image file is not modified; this flag is intended to reduce reviewer exposure, not to enforce access control. If blurring fails for any reason, a warning is logged and the original is shown (pretty path only). Defaults to False.
blur_radiusintGaussian blur radius applied when blur_images is True. Defaults to 20.

Raises:

Examples:

output_finding_report_async

output_finding_report_async(report: FindingReport, format: OutputFormat = 'markdown', sink: Sink | None = None) → None

Print a report of an Operation’s findings in the specified format.

ParameterTypeDescription
reportFindingReportThe findings to print.
formatOutputFormatOutput format. Only “markdown” is supported, so it is the default. Defaults to 'markdown'.
sinkSink | NoneOutput sink. Defaults to IPythonMarkdownSink in notebooks, StdoutSink otherwise.

Raises:

output_scenario_async

output_scenario_async(result: ScenarioResult, format: OutputFormat = 'pretty', sink: Sink | None = None, sort_groups_by_success_rate: bool = False) → None

Print a scenario result in the specified format to the specified destination.

ParameterTypeDescription
resultScenarioResultThe scenario result to print.
formatOutputFormatOutput format. Defaults to “pretty”.
sinkSink | NoneOutput sink. Defaults to StdoutSink.
sort_groups_by_success_rateboolWhen True, the Per-Group Breakdown is sorted so that the group with the highest success rate appears first, unless different objective scorers judged the groups, which then stay unsorted with a notice. Defaults to False, which preserves the original insertion order.

Raises:

Examples:

output_scenario_attacks_async

output_scenario_attacks_async(result: ScenarioResult, attack_result_ids: list[str] | None = None, limit: int | None = None, outcome: AttackOutcome | None = None, format: OutputFormat = 'pretty', sink: Sink | None = None) → None

Print a compact per-attack table for a scenario result.

Complements output_scenario_async (which prints the aggregate overview) by listing individual attack results: id, technique, objective, outcome, and score.

ParameterTypeDescription
resultScenarioResultThe scenario result whose attacks to list.
attack_result_idslist[str] | NoneRestrict to these attack ids. Defaults to None.
limitint | NoneMaximum number of attacks to show. Defaults to None.
outcomeAttackOutcome | NoneKeep only attacks with this outcome before applying limit. Defaults to None (all outcomes).
formatOutputFormatOutput format — “pretty” or “json”. Defaults to “pretty”.
sinkSink | NoneOutput sink. Defaults to StdoutSink.

Raises:

Examples:

output_scenario_conversations_async

output_scenario_conversations_async(result: ScenarioResult, attack_result_ids: list[str] | None = None, limit: int | None = None, outcome: AttackOutcome | None = None, format: OutputFormat = 'json', sink: Sink | None = None) → None

Print every attack’s summary and conversation for a scenario result as one JSON document.

The document has the same format as the CLI’s scenario-results --view conversations --format json output, and each response keeps only the score from the objective scorer that judged its attack. Conversations are read from memory and every attack is included unless you pass attack_result_ids, outcome, or limit, so narrow large scenarios.

ParameterTypeDescription
resultScenarioResultThe scenario result whose conversations to print.
attack_result_idslist[str] | NoneRestrict to these attack ids. Defaults to None.
limitint | NoneMaximum number of conversations to include; 0 gives an empty document. Defaults to None (all).
outcomeAttackOutcome | NoneKeep only attacks with this outcome before applying limit. Defaults to None (all outcomes).
formatOutputFormatOutput format. Only “json” is supported, so it is the default. Defaults to 'json'.
sinkSink | NoneOutput sink. Defaults to StdoutSink.

Raises:

Examples:

output_scenario_full_async

output_scenario_full_async(result: ScenarioResult, attack_result_ids: list[str] | None = None, limit: int | None = None, outcome: AttackOutcome | None = None, format: OutputFormat = 'json', sink: Sink | None = None) → None

Print the full scenario report: the overview plus every attack’s conversation.

The report has the same format as the CLI’s scenario-results --view full output with --format json or --format html, and each response keeps only the score from the objective scorer that judged its attack. The overview always covers the whole scenario; attack_result_ids, outcome, and limit only choose which conversations are included.

ParameterTypeDescription
resultScenarioResultThe scenario result to report.
attack_result_idslist[str] | NoneRestrict the conversations to these attack ids. Defaults to None.
limitint | NoneMaximum number of conversations to include; 0 gives none. Defaults to None (all).
outcomeAttackOutcome | NoneKeep only attacks with this outcome before applying limit. Defaults to None (all outcomes).
formatOutputFormatOutput format — “json” or a standalone, text-only “html” report. Defaults to “json”.
sinkSink | NoneOutput sink. Defaults to StdoutSink for “json”; “html” requires an explicit sink, such as FileSink.

Raises:

Examples:

output_scenario_suite_async

output_scenario_suite_async(execution: ScenarioSuiteExecutionSummary, format: OutputFormat = 'pretty', sink: Sink | None = None) → None

Print a suite execution snapshot with each submitted entry’s stored scenario result.

Child results are loaded from CentralMemory; entries without a stored result are shown as unavailable. Snapshot states may be older than the loaded result counts.

ParameterTypeDescription
executionScenarioSuiteExecutionSummarySnapshot providing suite status and every entry.
formatOutputFormatEither “pretty” or “json”. Defaults to “pretty”.
sinkSink | NoneOutput destination. Defaults to StdoutSink.

Raises:

Examples:

output_score_async

output_score_async(scores: list[Score], format: OutputFormat = 'pretty', sink: Sink | None = None) → None

Print a list of scores in the specified format.

ParameterTypeDescription
scoreslist[Score]The scores to print.
formatOutputFormatOutput format — “pretty” or “json”. Defaults to “pretty”.
sinkSink | NoneOutput sink. Defaults to StdoutSink.

Raises:

Examples:

output_scorer_async

output_scorer_async(scorer_identifier: ComponentIdentifier, harm_category: str | None = None, format: OutputFormat = 'pretty', sink: Sink | None = None) → None

Print scorer information in the specified format to the specified destination.

Auto-detects scorer type: if harm_category is provided, renders harm metrics; otherwise renders objective metrics.

ParameterTypeDescription
scorer_identifierComponentIdentifierThe scorer identifier.
harm_categorystr | NoneThe harm category. None for objective scorers. Defaults to None.
formatOutputFormatOutput format — “pretty” or “json”. Defaults to “pretty”.
sinkSink | NoneOutput sink. Defaults to StdoutSink.

Raises:

Examples:

output_scorer_selection_report_async

output_scorer_selection_report_async(report: ScorerSelectionReport, format: OutputFormat = 'pretty', sink: Sink | None = None) → None

Print which objective scorer each planned atomic group will use, and why earlier candidates were passed over.

ParameterTypeDescription
reportScorerSelectionReportThe report, from Scenario.get_scorer_selection_report().
formatOutputFormatOutput format. Only “pretty” is supported, so it is the default. Defaults to 'pretty'.
sinkSink | NoneOutput sink. Defaults to StdoutSink.

Raises:

resolve_lazy_export

resolve_lazy_export(name: str, module_name: str, module_globals: dict[str, Any], exports: Mapping[str, LazyExport]) → Any

Resolve and cache one package export.

ParameterTypeDescription
namestrPublic attribute requested from the package.
module_namestrPackage name used in an AttributeError.
module_globalsdict[str, Any]Package globals where the resolved value is cached.
exportsMapping[str, LazyExport]Public names and their implementation locations.

Returns:

Raises:

FileSink

Bases: Sink

Sink that writes text to a file.

Constructor Parameters:

ParameterTypeDescription
pathPathThe file path to write to.
modestrThe file open mode. Defaults to “w” (write, overwrite). Use “a” for append mode.

Examples:

Methods:

write_async

write_async(data: str) → None

Write data to a file.

ParameterTypeDescription
datastrThe text to write.

IPythonMarkdownSink

Bases: Sink

Sink that renders markdown via IPython’s display(Markdown(...)).

Falls back to print() if IPython is not available (e.g., outside a Jupyter notebook).

Methods:

write_async

write_async(data: str) → None

Display data as rendered markdown in IPython, or print to stdout.

ParameterTypeDescription
datastrThe markdown text to display.

PrinterBase

Bases: ABC

Abstract base class for all printers.

Subclasses implement render_async to produce formatted text. write_async is concrete: it calls render_async then routes the result through the configured sink.

Constructor Parameters:

ParameterTypeDescription
sinkSink | NoneThe output sink. Defaults to StdoutSink() if not provided.

Methods:

render_async

render_async(args: Any = (), kwargs: Any = {}) → str

Render output and return it as a string.

Subclasses define the specific signature (e.g., scorer_identifier, result, messages, etc.).

write_async

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

Render output and write it to the configured sink.

Calls render_async with all arguments, then writes the result through the sink. Subclasses should not override this method.

Sink

Bases: ABC

Abstract base class for output sinks.

A sink defines where rendered output goes (stdout, file, etc.). All printers write their output through a sink.

Methods:

write_async

write_async(data: str) → None

Write rendered output data.

ParameterTypeDescription
datastrThe rendered text output to write.

StdoutSink

Bases: Sink

Sink that prints text to stdout.

This is the default sink used when no sink is specified.

Examples:

Methods:

write_async

write_async(data: str) → None

Write data to stdout.

ParameterTypeDescription
datastrThe text to print.