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` |
Returns:
Sink— The default sink instance.
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, 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”. Defaults to 'pretty'. |
sink | `Sink | None` |
include_auxiliary_scores | bool | Whether to include auxiliary scores. Defaults to False. Defaults to False. |
include_pruned_conversations | bool | Whether to include pruned conversations. Defaults to False. Defaults to False. |
include_adversarial_conversation | bool | Whether to include the adversarial conversation. Defaults to False. 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. Defaults to False. |
blur_radius | int | Gaussian blur radius applied when blur_images is True. Defaults to 20. Defaults to 20. |
blurred_dir | `str | PathLike |
output_conversation_async¶
output_conversation_async(messages: list[Message], format: OutputFormat = 'pretty', sink: Sink | None = None, include_scores: bool = False, include_reasoning_trace: 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 “markdown”. Defaults to “pretty”. Defaults to 'pretty'. |
sink | `Sink | None` |
include_scores | bool | Whether to include scores. Defaults to False. Defaults to False. |
include_reasoning_trace | bool | Whether to include reasoning traces. Defaults to False. Defaults to False. |
blur_images | bool | If True, apply a Gaussian blur to image outputs before rendering them. For “pretty” output (the only format supported here), 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. Defaults to False. |
blur_radius | int | Gaussian blur radius applied when blur_images is True. Defaults to 20. Defaults to 20. |
Raises:
ValueError— Ifformatis not a supported value.
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 — “pretty” or “markdown”. Defaults to “pretty”. Defaults to 'pretty'. |
sink | `Sink | None` |
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. Defaults to False, which preserves the original insertion order. Defaults to False. |
Raises:
ValueError— Ifformatis not a supported value.
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 “markdown”. Defaults to “pretty”. Defaults to 'pretty'. |
sink | `Sink | None` |
Raises:
ValueError— Ifformatis not a supported value.
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` |
format | OutputFormat | Output format — “pretty” or “markdown”. Defaults to “pretty”. Defaults to 'pretty'. |
sink | `Sink | None` |
Raises:
ValueError— Ifformatis not a supported value.
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. Defaults to 'w'. |
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` |
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.
Methods:
write_async¶
write_async(data: str) → NoneWrite data to stdout.
| Parameter | Type | Description |
|---|---|---|
data | str | The text to print. |