Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
162c6a3
FEAT: Gather an Operation's selected findings in pyrit.output
hannahwestra25 Dec 4, 2026
9184c4d
FIX: Keep evidence availability in finding reports built without links
hannahwestra25 Dec 4, 2026
13e27a2
FEAT: Publish findings through a FindingPublisher contract, with an A…
hannahwestra25 Dec 4, 2026
1f34e05
FIX: Report an in-flight create as unknown when a publish is cancelled
hannahwestra25 Dec 4, 2026
442704e
TEST: Check that a completed publish run reports no item in flight
hannahwestra25 Dec 4, 2026
9a2736a
MAINT: Keep the finding selection as data and resolve evidence in memory
hannahwestra25 Dec 4, 2026
1b362fc
TEST: Pin evidence order and the Unknown scorer in finding reports
hannahwestra25 Dec 4, 2026
4cfb284
DOC: Run the finding report example in the output guide
hannahwestra25 Dec 4, 2026
3197900
Merge PR #4836's new head into the finding publisher branch
hannahwestra25 Dec 4, 2026
1239cec
FEAT: Add FindingReportEntry.finding_id for the publish planner
hannahwestra25 Dec 4, 2026
3471730
MAINT: Plan finding publishes from the data-only FindingSelection
hannahwestra25 Dec 4, 2026
3bf30d3
FIX: Keep FindingReportEvidence compatible with evidence built withou…
hannahwestra25 Dec 4, 2026
5e5fedf
MAINT: Take evidence links only when publishing
hannahwestra25 Dec 4, 2026
2120527
Merge PR #4836's head 3bf30d3 into the finding publisher branch
hannahwestra25 Dec 4, 2026
95d518c
FIX: Keep a created item's recording inside the publish guard
hannahwestra25 Dec 4, 2026
077a97a
TEST: Type the fake publisher's invalid create result with cast
hannahwestra25 Dec 4, 2026
6714788
TEST: Reject a create result that only looks like a published item
hannahwestra25 Dec 4, 2026
451ca80
Merge main dca8a3c into the finding publisher branch
hannahwestra25 Dec 4, 2026
6d3e382
FIX: Use caller-neutral wording in finding publisher messages
hannahwestra25 Dec 4, 2026
6ef08e5
FIX: Reject a token that is not a valid header value
hannahwestra25 Dec 4, 2026
f88ab89
FIX: Name the transport error type in publish diagnostics
hannahwestra25 Dec 4, 2026
b1a2bc4
TEST: Cover single creates, HTML escaping and the link allowlist
hannahwestra25 Dec 4, 2026
f1c633a
DOC: Describe finding publishing in the Output guidance
hannahwestra25 Dec 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions .github/instructions/output.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ When reviewing: reject any `print()` call outside `StdoutSink`.

### Data fetching belongs in leaf classes only

Format classes (`PrettyAttackResultPrinter`, `MarkdownAttackResultPrinter`) must not import or reference `CentralMemory`. Only `*MemoryPrinter` leaf classes do data I/O.
Format classes (`PrettyAttackResultPrinter`, `MarkdownAttackResultPrinter`) must not import or reference `CentralMemory`. Only `*MemoryPrinter` leaf classes and the builders and sources that gather a report's input, such as `build_finding_selection_async` (`finding_report/selection.py`) and `MemoryConversationSource`, read memory; publishers never do.

When reviewing: reject any `CentralMemory` import in a non-leaf file (`pretty.py`, `markdown.py`, `json.py`).

Expand All @@ -32,7 +32,7 @@ When reviewing: reject synchronous `open()`, `write()`, or network calls inside

## Three-Layer Hierarchy

Every domain follows this structure. Do not mix responsibilities across layers.
Every printer domain follows this structure. Do not mix responsibilities across layers. Finding report builders and [publishers](#publishers) aren't printers and sit outside it.

| Layer | File | Responsibility | May import CentralMemory? |
|-------|------|---------------|---------------------------|
Expand Down Expand Up @@ -68,3 +68,14 @@ await output_attack_async(result, format="pretty")
`helpers.py` resolves `format` → printer class, `sink` → Sink, and calls `write_async`.

When reviewing: if a new domain printer is added without a helper function, request one.

## Publishers

Finding publishers (`pyrit/output/finding_publisher/`) write findings to another system and return what they created. They aren't printers: they have no sink and no `helpers.py` function, and they never touch `CentralMemory`. Callers pass a `FindingSelection` from `build_finding_selection_async`, and pass `publish_async` a `link_for` when evidence should link back. The planner lays the selection out with `build_finding_report`, so each item's evidence matches the exports.

- Subclass `FindingPublisher` and implement all four abstract members: `info` (the destination input's label and hint), `_open_destination_async`, `_create_item_async`, and `_build_identifier`, which records every setting that shapes the items and never a label or credential. The base class owns planning, value checks, the plan digest, the create loop, outcome accounting and the run summary; don't rebuild them in a subclass.
- Use async I/O, and keep every request within a timeout and the caller's `deadline`.
- Once the base calls `_create_item_async`, every outcome goes in the result and only cancellation escapes. Raise `FindingPublishCreateError` with `outcome_unknown=False` only when nothing was sent or the response proves nothing was created, and never retry a create that might have succeeded.
- Never log tokens, names, emails, titles, field values or the service's message text. An unexpected (unclassified) error keeps its traceback (`exc_info=True`), its only diagnostic, but PyRIT's own credentials never reach a log or an error.

When reviewing: reject a subclass that overrides `preview_async`, `publish_async` or the create loop.
5 changes: 3 additions & 2 deletions doc/code/framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,11 @@ These modules support every component.

## [Output](./output/0_output)

**Responsibility**: Render results (attack and scenario results, conversations, scores, and findings) in any format to any destination.
**Responsibility**: Render results (attack and scenario results, conversations, scores, and findings) in any format to any destination, and publish selected findings to another system.

- Keep the format (pretty, Markdown, JSON, or HTML) separate from the sink (stdout, a file, or a notebook). Surfaces use these renderers instead of writing their own.
- **Does not own**: what or when to render. Formatters turn data into strings and sinks write them. Formatters never fetch data, touch `CentralMemory`, or print; only `*MemoryPrinter` classes read memory.
- A finding publisher creates items in another system and returns what it created and every finding's outcome, so it isn't a sink.
- **Does not own**: what or when to render. Formatters turn data into strings and sinks write them. Formatters never fetch data, touch `CentralMemory`, or print; only `*MemoryPrinter` classes and the builders and sources that gather a report's input, such as `build_finding_selection_async` and `MemoryConversationSource`, read memory.

**Contributing (difficulty low)**: Adding a format or sink is well-defined. Give every new domain printer a matching convenience function in `helpers.py`.

Expand Down
219 changes: 219 additions & 0 deletions doc/code/output/0_output.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,225 @@
"scenario result ID) to a printer in `pyrit.output.scenario_suite_result`."
]
},
{
"cell_type": "markdown",
"id": "printing-finding-reports",
"metadata": {},
"source": [
"## Printing Finding Reports\n",
"\n",
"`build_finding_selection_async` reads an Operation's selected findings from memory, each with all\n",
"of its sub-findings and evidence, as CoPyRIT's findings export does. `build_finding_report` lays\n",
"the selection out as a report, and `output_finding_report_async` prints it.\n",
"\n",
"Pass `link_for` to `build_finding_report` to link each piece of evidence whose conversation can be\n",
"opened, for example to your dashboard. Without it, the report lists evidence without links. Pass\n",
"`max_findings` to `build_finding_selection_async` to cap the selection, counting sub-findings."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "printing-finding-reports-code",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"# Findings - Output guide\n",
"\n",
"Evidence is listed as references; transcripts are not included.\n",
"\n",
"## 1 Joke ranks people by height\n",
"\n",
"**Severity:** Low\n",
"\n",
"**Evidence:** none attached\n"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from pyrit.models import Finding, Operation\n",
"from pyrit.output import build_finding_report, build_finding_selection_async, output_finding_report_async\n",
"from pyrit.setup.finding_fields import get_active_finding_fields\n",
"\n",
"operation = await memory.add_operation_async(Operation(name=\"Output guide\"))\n",
"finding = await memory.add_finding_async(\n",
" finding=Finding(operation_id=operation.id, title=\"Joke ranks people by height\", severity=\"low\")\n",
")\n",
"\n",
"fields = get_active_finding_fields()\n",
"selection = await build_finding_selection_async(operation_id=operation.id, finding_ids=[finding.id], fields=fields)\n",
"await output_finding_report_async(build_finding_report(selection=selection, fields=fields))"
]
},
{
"cell_type": "markdown",
"id": "publishing-findings",
"metadata": {},
"source": [
"## Publishing Findings\n",
"\n",
"A finding publisher creates an item for each selected finding in another system, under an existing\n",
"item that you name, such as a parent work item. `preview_async` shows where every finding would go\n",
"and writes nothing. `publish_async` creates the items, parents first, and reports every finding's\n",
"outcome: created, skipped because it wasn't demonstrated, failed (saying whether the item might\n",
"exist anyway), or not attempted. Each publish has a run ID that the created items record, and\n",
"publishing again creates new items.\n",
"\n",
"```python\n",
"from pyrit.output import build_finding_selection_async\n",
"from pyrit.setup.finding_fields import get_active_finding_fields\n",
"\n",
"fields = get_active_finding_fields()\n",
"selection = await build_finding_selection_async(operation_id=operation_id, finding_ids=finding_ids, fields=fields)\n",
"preview = await publisher.preview_async(selection=selection, fields=fields, destination=\"12345\")\n",
"result = await publisher.publish_async(\n",
" selection=selection, fields=fields, destination=\"12345\", link_for=link_for, expected_plan_digest=preview.plan_digest\n",
")\n",
"```\n",
"\n",
"Pass the preview's `plan_digest` so the publish creates only what the preview showed; if the findings,\n",
"the destination, or the publisher changed, it raises `FindingPublishPlanChangedError` before writing\n",
"anything. Pass `link_for` to `publish_async` to link each piece of evidence, as `build_finding_report`\n",
"does. Links don't change the digest, so the preview takes none.\n",
"\n",
"`AzureDevOpsFindingPublisher` creates Azure DevOps work items under an existing work item, with a\n",
"token from `DefaultAzureCredential` unless you pass `token_provider`. Map each finding field and level\n",
"key, including `severity`, to an Azure DevOps field, or list it in `unmapped_keys`. A `choice` value\n",
"is sent as its option key, so the keys must equal the Azure DevOps values, and a choice field that\n",
"takes Other text can't be mapped. `check_fields` reports every key that breaks a rule:\n",
"\n",
"```python\n",
"from pyrit.output import AzureDevOpsField, AzureDevOpsFieldKind, AzureDevOpsFindingPublisher\n",
"\n",
"publisher = AzureDevOpsFindingPublisher(\n",
" organization_url=\"https://dev.azure.com/contoso\",\n",
" project=\"Red Team\",\n",
" work_item_type=\"Finding\",\n",
" destination_work_item_types=[\"Operation\"],\n",
" field_map={\n",
" \"severity\": AzureDevOpsField(reference_name=\"Custom.Severity\", kind=AzureDevOpsFieldKind.CHOICE),\n",
" \"summary\": AzureDevOpsField(reference_name=\"Custom.Summary\", kind=AzureDevOpsFieldKind.TEXT),\n",
" \"description\": AzureDevOpsField(reference_name=\"System.Description\", kind=AzureDevOpsFieldKind.HTML),\n",
" },\n",
" evidence_field=\"Custom.Evidence\",\n",
" unmapped_keys=[\"internal_notes\"],\n",
" fixed_fields={\"Custom.Source\": \"PyRIT\"},\n",
")\n",
"publisher.check_fields(fields=fields)\n",
"```\n",
"\n",
"This example assumes a deployment's configured finding fields. PyRIT's default fields are `severity`,\n",
"`harm_type`, and `description`, and `severity` and `harm_type` take Other text, so with the defaults,\n",
"map only `description` and list `severity` and `harm_type` in `unmapped_keys`.\n",
"\n",
"Each work item copies its Area and Iteration from the destination, is assigned to the email of\n",
"`requested_by`, and notes the requester, the run ID, and the finding ID in its History. Titles and\n",
"`text` values must fit on one line of at most 255 characters as Azure DevOps counts them; the preview\n",
"lists any that don't, and nothing is shortened.\n",
"\n",
"To publish somewhere else, subclass `FindingPublisher` and implement its four abstract members: `info`,\n",
"the label and hint a surface shows for the destination; `_open_destination_async`, which reads the\n",
"destination; `_create_item_async`, which creates one item; and `_build_identifier`, which records every\n",
"setting that shapes the items and never a label or credential. The base class plans the items, checks\n",
"the values, and accounts for every outcome. This publisher keeps its items in memory:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "publishing-findings-example",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Finding publish run 5dd45f9822e94ddfa4ef44ca643ec6ea to destination inbox by InMemoryFindingPublisher: created 2 (1, 2), skipped 1, not attempted 0; no failure; stopped: no.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Created item 1 under inbox: Encoded instructions bypass refusals\n",
"Created item 2 under 1: The model decodes Base64 input\n",
"Skipped: Role-play jailbreak (Not demonstrated)\n"
]
}
],
"source": [
"from uuid import uuid4\n",
"\n",
"from pyrit.models import (\n",
" DEFAULT_FINDING_FIELDS,\n",
" ComponentIdentifier,\n",
" Finding,\n",
" FindingPublishDestination,\n",
" FindingPublishedItem,\n",
" FindingPublisherInfo,\n",
")\n",
"from pyrit.output import FindingPublisher, FindingSelection\n",
"\n",
"\n",
"class InMemoryFindingPublisher(FindingPublisher):\n",
" def __init__(self) -> None:\n",
" self.items: dict[str, str] = {}\n",
"\n",
" @property\n",
" def info(self) -> FindingPublisherInfo:\n",
" return FindingPublisherInfo(destination_label=\"Folder\", destination_hint=\"Name a folder.\")\n",
"\n",
" def _build_identifier(self) -> ComponentIdentifier:\n",
" return ComponentIdentifier.of(self)\n",
"\n",
" async def _open_destination_async(self, *, destination, deadline):\n",
" folder = FindingPublishDestination(id=destination, title=destination, url=\"\", location=\"memory\")\n",
" return folder, None\n",
"\n",
" async def _create_item_async(self, *, item, parent_external_id, context, run_id, requested_by, deadline):\n",
" external_id = str(len(self.items) + 1)\n",
" self.items[external_id] = item.finding.title\n",
" return FindingPublishedItem(\n",
" finding_id=item.finding.id,\n",
" title=item.finding.title,\n",
" external_id=external_id,\n",
" url=\"\",\n",
" parent_external_id=parent_external_id,\n",
" )\n",
"\n",
"\n",
"operation_id = uuid4()\n",
"finding = Finding(operation_id=operation_id, title=\"Encoded instructions bypass refusals\", severity=\"important\")\n",
"step = Finding(\n",
" operation_id=operation_id, title=\"The model decodes Base64 input\", severity=\"moderate\", parent_finding_id=finding.id\n",
")\n",
"draft = Finding(operation_id=operation_id, title=\"Role-play jailbreak\", severity=\"low\", demonstrated=False)\n",
"selection = FindingSelection(\n",
" operation_id=operation_id, operation_name=\"Demo operation\", findings=(finding, step, draft), evidence={}, part_of={}\n",
")\n",
"\n",
"publisher = InMemoryFindingPublisher()\n",
"preview = await publisher.preview_async( # type: ignore\n",
" selection=selection, fields=DEFAULT_FINDING_FIELDS, destination=\"inbox\"\n",
")\n",
"result = await publisher.publish_async( # type: ignore\n",
" selection=selection, fields=DEFAULT_FINDING_FIELDS, destination=\"inbox\", expected_plan_digest=preview.plan_digest\n",
")\n",
"\n",
"for item in result.created:\n",
" print(f\"Created item {item.external_id} under {item.parent_external_id}: {item.title}\")\n",
"for skip in result.skipped:\n",
" print(f\"Skipped: {skip.title} ({skip.reason})\")"
]
},
{
"cell_type": "markdown",
"id": "19",
Expand Down
Loading
Loading