Output module for displaying attack, scenario, and scorer results.
This module provides:
Sink classes that define where output goes (stdout, file, etc.)
PrinterBase that all printers inherit from
Domain printers for attack results, scenario results, and scorer information
Convenience functions (e.g.,
output_attack_async)
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) → SinkReturn the appropriate default sink for the current environment.
When default is None, auto-detects: uses IPythonMarkdownSink
inside Jupyter/IPython notebooks, otherwise StdoutSink.
| Parameter | Type | Description |
|---|---|---|
default | type[Sink] | None | Sink class to instantiate. None means auto-detect based on environment. Defaults to None. |
Returns:
Sink— The default sink instance.
get_lazy_dir¶
get_lazy_dir(module_globals: dict[str, Any], exports: Mapping[str, LazyExport]) → list[str]Return package attributes and unresolved public exports.
| Parameter | Type | Description |
|---|---|---|
module_globals | dict[str, Any] | The package globals. |
exports | Mapping[str, LazyExport] | Public names and their implementation locations. |
Returns:
list[str]— list[str]: Sorted package attribute names.
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) → NonePrint an attack result in the specified format to the specified destination.
| Parameter | Type | Description |
|---|---|---|
result | AttackResult | The attack result to print. |
format | OutputFormat | Output format — “pretty” or “markdown”. Defaults to “pretty”. |
sink | Sink | None | Output sink. Defaults to StdoutSink for “pretty”; auto-detects (IPythonMarkdownSink in notebooks, StdoutSink otherwise) for “markdown”. |
include_auxiliary_scores | bool | Whether to include auxiliary scores. Defaults to False. |
include_pruned_conversations | bool | Whether to include pruned conversations. Defaults to False. |
include_adversarial_conversation | bool | Whether to include the adversarial conversation. Defaults to False. |
include_reasoning_summaries | bool | Whether to include the reasoning summaries. Defaults to False. |
blur_images | bool | If 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_radius | int | Gaussian blur radius applied when blur_images is True. Defaults to 20. |
blurred_dir | str | PathLike | None | For “markdown” output, directory to write blurred copies into. Defaults to None (sibling of the original). Ignored when format != "markdown". |
Raises:
ValueError— Ifformatis not a supported value.
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) → NonePrint a conversation message history in the specified format.
| Parameter | Type | Description |
|---|---|---|
messages | list[Message] | The messages to print. |
format | OutputFormat | Output format — “pretty” or “json”. Defaults to “pretty”. |
sink | Sink | None | Output sink. Defaults to StdoutSink. |
include_scores | bool | Whether to include scores. Defaults to False. |
include_reasoning_summaries | bool | Whether to include reasoning summaries. Defaults to False. |
blur_images | bool | If 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_radius | int | Gaussian blur radius applied when blur_images is True. Defaults to 20. |
Raises:
ValueError— Ifformatis not a supported value.
Examples:
output_finding_report_async¶
output_finding_report_async(report: FindingReport, format: OutputFormat = 'markdown', sink: Sink | None = None) → NonePrint a report of an Operation’s findings in the specified format.
| Parameter | Type | Description |
|---|---|---|
report | FindingReport | The findings to print. |
format | OutputFormat | Output format. Only “markdown” is supported, so it is the default. Defaults to 'markdown'. |
sink | Sink | None | Output sink. Defaults to IPythonMarkdownSink in notebooks, StdoutSink otherwise. |
Raises:
ValueError— Ifformatis not “markdown”.
output_scenario_async¶
output_scenario_async(result: ScenarioResult, format: OutputFormat = 'pretty', sink: Sink | None = None, sort_groups_by_success_rate: bool = False) → NonePrint a scenario result in the specified format to the specified destination.
| Parameter | Type | Description |
|---|---|---|
result | ScenarioResult | The scenario result to print. |
format | OutputFormat | Output format. Defaults to “pretty”. |
sink | Sink | None | Output sink. Defaults to StdoutSink. |
sort_groups_by_success_rate | bool | When 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:
ValueError— Ifformatis not a supported value.
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) → NonePrint 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.
| Parameter | Type | Description |
|---|---|---|
result | ScenarioResult | The scenario result whose attacks to list. |
attack_result_ids | list[str] | None | Restrict to these attack ids. Defaults to None. |
limit | int | None | Maximum number of attacks to show. Defaults to None. |
outcome | AttackOutcome | None | Keep only attacks with this outcome before applying limit. Defaults to None (all outcomes). |
format | OutputFormat | Output format — “pretty” or “json”. Defaults to “pretty”. |
sink | Sink | None | Output sink. Defaults to StdoutSink. |
Raises:
ValueError— Ifformatis not a supported value.
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) → NonePrint 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.
| Parameter | Type | Description |
|---|---|---|
result | ScenarioResult | The scenario result whose conversations to print. |
attack_result_ids | list[str] | None | Restrict to these attack ids. Defaults to None. |
limit | int | None | Maximum number of conversations to include; 0 gives an empty document. Defaults to None (all). |
outcome | AttackOutcome | None | Keep only attacks with this outcome before applying limit. Defaults to None (all outcomes). |
format | OutputFormat | Output format. Only “json” is supported, so it is the default. Defaults to 'json'. |
sink | Sink | None | Output sink. Defaults to StdoutSink. |
Raises:
ValueError— Ifformatis not “json” orlimitis negative.
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) → NonePrint 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.
| Parameter | Type | Description |
|---|---|---|
result | ScenarioResult | The scenario result to report. |
attack_result_ids | list[str] | None | Restrict the conversations to these attack ids. Defaults to None. |
limit | int | None | Maximum number of conversations to include; 0 gives none. Defaults to None (all). |
outcome | AttackOutcome | None | Keep only attacks with this outcome before applying limit. Defaults to None (all outcomes). |
format | OutputFormat | Output format — “json” or a standalone, text-only “html” report. Defaults to “json”. |
sink | Sink | None | Output sink. Defaults to StdoutSink for “json”; “html” requires an explicit sink, such as FileSink. |
Raises:
ValueError— Ifformatis not “json” or “html”,formatis “html” without a sink, orlimitis negative.
Examples:
output_scenario_suite_async¶
output_scenario_suite_async(execution: ScenarioSuiteExecutionSummary, format: OutputFormat = 'pretty', sink: Sink | None = None) → NonePrint 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.
| Parameter | Type | Description |
|---|---|---|
execution | ScenarioSuiteExecutionSummary | Snapshot providing suite status and every entry. |
format | OutputFormat | Either “pretty” or “json”. Defaults to “pretty”. |
sink | Sink | None | Output destination. Defaults to StdoutSink. |
Raises:
ValueError— If the format is unsupported or stored results do not match the snapshot.
Examples:
output_score_async¶
output_score_async(scores: list[Score], format: OutputFormat = 'pretty', sink: Sink | None = None) → NonePrint a list of scores in the specified format.
| Parameter | Type | Description |
|---|---|---|
scores | list[Score] | The scores to print. |
format | OutputFormat | Output format — “pretty” or “json”. Defaults to “pretty”. |
sink | Sink | None | Output sink. Defaults to StdoutSink. |
Raises:
ValueError— Ifformatis not a supported value.
Examples:
output_scorer_async¶
output_scorer_async(scorer_identifier: ComponentIdentifier, harm_category: str | None = None, format: OutputFormat = 'pretty', sink: Sink | None = None) → NonePrint 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.
| Parameter | Type | Description |
|---|---|---|
scorer_identifier | ComponentIdentifier | The scorer identifier. |
harm_category | str | None | The harm category. None for objective scorers. Defaults to None. |
format | OutputFormat | Output format — “pretty” or “json”. Defaults to “pretty”. |
sink | Sink | None | Output sink. Defaults to StdoutSink. |
Raises:
ValueError— Ifformatis not a supported value.
Examples:
output_scorer_selection_report_async¶
output_scorer_selection_report_async(report: ScorerSelectionReport, format: OutputFormat = 'pretty', sink: Sink | None = None) → NonePrint which objective scorer each planned atomic group will use, and why earlier candidates were passed over.
| Parameter | Type | Description |
|---|---|---|
report | ScorerSelectionReport | The report, from Scenario.get_scorer_selection_report(). |
format | OutputFormat | Output format. Only “pretty” is supported, so it is the default. Defaults to 'pretty'. |
sink | Sink | None | Output sink. Defaults to StdoutSink. |
Raises:
ValueError— Ifformatis not “pretty”.
resolve_lazy_export¶
resolve_lazy_export(name: str, module_name: str, module_globals: dict[str, Any], exports: Mapping[str, LazyExport]) → AnyResolve and cache one package export.
| Parameter | Type | Description |
|---|---|---|
name | str | Public attribute requested from the package. |
module_name | str | Package name used in an AttributeError. |
module_globals | dict[str, Any] | Package globals where the resolved value is cached. |
exports | Mapping[str, LazyExport] | Public names and their implementation locations. |
Returns:
Any— The resolved public value.
Raises:
AttributeError— Ifnameis not a declared lazy export.
FileSink¶
Bases: Sink
Sink that writes text to a file.
Constructor Parameters:
| Parameter | Type | Description |
|---|---|---|
path | Path | The file path to write to. |
mode | str | The file open mode. Defaults to “w” (write, overwrite). Use “a” for append mode. |
Examples:
Methods:
write_async¶
write_async(data: str) → NoneWrite data to a file.
| Parameter | Type | Description |
|---|---|---|
data | str | The 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) → NoneDisplay data as rendered markdown in IPython, or print to stdout.
| Parameter | Type | Description |
|---|---|---|
data | str | The 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:
| Parameter | Type | Description |
|---|---|---|
sink | Sink | None | The output sink. Defaults to StdoutSink() if not provided. |
Methods:
render_async¶
render_async(args: Any = (), kwargs: Any = {}) → strRender 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 = {}) → NoneRender 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) → NoneWrite rendered output data.
| Parameter | Type | Description |
|---|---|---|
data | str | The 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) → NoneWrite data to stdout.
| Parameter | Type | Description |
|---|---|---|
data | str | The text to print. |