Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
f1b607d
FEAT: Custom ASSERT judge dimensions, presets, and repeated samples
richlundeen Nov 10, 2026
1b753ee
FIX: Keep non-default ASSERT judge settings in identity; restrict jud…
richlundeen Nov 10, 2026
54b1aba
MAINT: Simplify ASSERT judge dimensions and samples; allow technique …
richlundeen Nov 10, 2026
fe1ff0e
FEAT: Run registered attack techniques in foundry.assert_policy
richlundeen Nov 10, 2026
fb0caff
FEAT: Support ASSERT not-applicable answers and graded judge dimensions
richlundeen Nov 10, 2026
aed1b20
FEAT: assert_package technique with ASSERT's tester prompt
richlundeen Nov 10, 2026
a99189d
FIX: address #4132 review feedback
richlundeen Nov 10, 2026
a18bc4f
MAINT: typed ASSERT judgment metadata and YAML dimension framing
richlundeen Nov 11, 2026
3c26aec
FEAT: Trace-grounded ASSERT judging with OpenTelemetry execution evid…
richlundeen Nov 10, 2026
053dd5c
FIX: Order ASSERT trace steps deterministically when start times tie
richlundeen Nov 10, 2026
9780189
FIX: Address ASSERT trace evidence review feedback
richlundeen Nov 10, 2026
e2c965b
FIX: Version ASSERT trace rendering for cyclic steps
richlundeen Nov 10, 2026
4bb2163
FIX: Render ASSERT dimension trace instructions through the prompt te…
richlundeen Nov 11, 2026
a24ce22
FEAT: ASSERT headline metrics for foundry.assert_policy runs
richlundeen Nov 10, 2026
166de36
FIX: Address ASSERT metrics review feedback
richlundeen Nov 10, 2026
265a2e6
DOC: Refresh ASSERT metrics notebook output for assert_package
richlundeen Nov 10, 2026
b70cb51
FIX: Read ASSERT judgment metadata through the typed models
richlundeen Nov 11, 2026
20ceb2e
FEAT: Resumable ASSERT generation, generation estimates, and the ASSE…
richlundeen Nov 10, 2026
d199cba
FIX: Address ASSERT generation SDK review
richlundeen Nov 10, 2026
ba09380
FEAT: Run prompt generators as backend jobs
richlundeen Nov 10, 2026
7875121
FIX: Address prompt generation backend review
richlundeen Nov 10, 2026
ee00756
MAINT: merge main 1dc1d5cda into ASSERT judge dimensions (-1)
richlundeen Nov 11, 2026
9e697fd
MAINT: Merge refreshed ASSERT judge dimensions layer (main 1dc1d5cda)…
richlundeen Nov 11, 2026
78f2477
Merge commit '9e697fddfef02c1c17fb1b851cb6285c5bbc704d' into richlund…
richlundeen Nov 11, 2026
f31407f
Merge refreshed ASSERT metrics (-3) with main into staged generation …
richlundeen Nov 11, 2026
51f8472
Merge staged generation (-4) with main into generation jobs (-5)
richlundeen Nov 11, 2026
0012d16
MAINT: merge main c3cff1831 into ASSERT judge dimensions (-1)
richlundeen Nov 11, 2026
7bf65f3
MAINT: Merge refreshed ASSERT judge dimensions layer (main c3cff1831)…
richlundeen Nov 11, 2026
4848f91
Merge commit '7bf65f3969fb6cd8b2c14be28456a848baf9c370' into richlund…
richlundeen Nov 11, 2026
da0f38c
Merge refreshed ASSERT metrics (-3) with main into staged generation …
richlundeen Nov 11, 2026
0ebcd76
Merge staged generation (-4) with main into generation jobs (-5)
richlundeen Nov 11, 2026
6932faa
FEAT: accept a supplied ASSERT objective scorer and use default scori…
richlundeen Nov 11, 2026
2804b41
DOC: note default ASSERT scoring in the launch form and the supplied …
richlundeen Nov 11, 2026
8859dea
FIX: resolve the ASSERT judge target with scoring_target and report i…
richlundeen Nov 11, 2026
f696a86
MAINT: make ASSERT judgment metadata helpers keyword-only
richlundeen Nov 11, 2026
4c8ceda
MAINT: Rebuild ASSERT trace evidence layer on the supplied-scorer layer
richlundeen Nov 11, 2026
06ccdf2
MAINT: Exempt the OpenTelemetry span processor callback from keyword-…
richlundeen Nov 11, 2026
b5e5931
Merge published ASSERT metrics layer onto the rebuilt trace evidence …
richlundeen Nov 11, 2026
cee992a
FIX: Identify ASSERT runs by registry name and keep supplied scorers …
richlundeen Nov 11, 2026
880a61f
FIX: Use only proven ASSERT provenance for metrics policies and dimen…
richlundeen Nov 11, 2026
145b788
FIX: Require built-in ASSERT judge evidence for metrics policies
richlundeen Nov 11, 2026
d0b7c2a
FIX: Stop attributing ASSERT violations to the mutable assigned category
richlundeen Nov 11, 2026
1c0add0
Merge rebuilt ASSERT metrics (-3) into staged generation (-4)
richlundeen Nov 11, 2026
22c7a75
Merge rebuilt staged generation (-4) into generation jobs (-5)
richlundeen Nov 11, 2026
393112b
Merge main into generation jobs (-5)
richlundeen Nov 18, 2026
c9bdc44
MAINT: Make prompt generation parameters keyword-only
richlundeen Nov 18, 2026
96cce74
Merge main into generation jobs (-5)
richlundeen Nov 18, 2026
4066654
MAINT: Persist prompt generation jobs through memory
richlundeen Nov 18, 2026
59f121f
FIX: Recover orphaned saving generations and let the database match n…
richlundeen Nov 18, 2026
2b59341
Merge main into generation jobs (-5)
richlundeen Nov 19, 2026
5bb8d6a
Merge main into generation jobs (-5)
richlundeen Nov 19, 2026
7c315f3
Keep generation writes, requests, and batch order correct across back…
richlundeen Nov 19, 2026
883bcc6
Merge main into generation jobs (-5)
richlundeen Nov 19, 2026
c5bd484
FIX: List a batch's generations in the order they were requested
richlundeen Nov 19, 2026
20a8f4a
FIX: Say plainly when a generation can't resume under its dataset name
richlundeen Nov 19, 2026
184f9af
Merge main into generation jobs (-5)
richlundeen Nov 19, 2026
1db7362
MAINT: Trim the generation save status, bulk lookups, and duplicate r…
richlundeen Nov 19, 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
17 changes: 17 additions & 0 deletions doc/code/memory/9_schema_diagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,27 @@ flowchart LR
Sc_scorer_class_identifier["scorer_class_identifier (VARCHAR)"]
Sc_timestamp["timestamp (TIMESTAMP)"]
Sc_objective["objective (VARCHAR)"]
end
subgraph PromptGenerationEntries["PromptGenerationEntries"]
G_id["id (UUID)"]
G_generator["generator (VARCHAR)"]
G_dataset_name["dataset_name (VARCHAR)"]
G_status["status (VARCHAR)"]
G_execution_id["execution_id (UUID)"]
G_request["request (JSON)"]
G_targets["targets (JSON)"]
G_group_id["group_id (UUID)"]
G_group_index["group_index (INTEGER)"]
G_progress["progress (JSON)"]
G_checkpoint["checkpoint (JSON)"]
G_summary["summary (JSON)"]
G_created_at["created_at (TIMESTAMP)"]
G_updated_at["updated_at (TIMESTAMP)"]
end
S_value_sha256 -- N:N relationship to query --> P_original_value_sha256
P_id -- 1:N relationship to query --> Sc_prompt_request_response_id
P_conversation_id -- N:1 relationship to query --> C_conversation_id
G_dataset_name -- creates once, by name --> S_dataset_name

style S_value_sha256 fill:#ff8800ff
style P_id fill:#14a519ff
Expand Down
51 changes: 46 additions & 5 deletions pyrit/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,11 @@ server-generated storage names and are never executed. Blob uploads are opaque
attachments; local retrieval uses the existing media route's safe inline allowlist.

Names are exact, nonempty, at most 256 UTF-16 code units, and have no surrounding
whitespace or control characters. An existing stored dataset or in-progress upload
with a database-collation-equivalent name returns `409`, never append/replace or
silent deduplication. SQLite keeps its normal case-sensitive identity; SQL Server
uses the existing seed-name column collation. Exact deletion remains exact even
when legacy datasets contain collated aliases. Seed and journal names use Unicode
whitespace or control characters. An existing stored dataset, in-progress upload, or
unfinished prompt generation with a database-collation-equivalent name returns `409`,
never append/replace or silent deduplication. SQLite keeps its normal case-sensitive
identity; SQL Server uses the existing seed-name column collation. Exact deletion
remains exact even when legacy datasets contain collated aliases. Seed and journal names use Unicode
storage on SQL Server, including databases with non-UTF-8 collations.
A provider-only name is allowed; its provider registration remains unchanged.
Descriptive metadata, response schema, roles, sequence numbers, and grouping are
Expand Down Expand Up @@ -746,6 +746,47 @@ supplied arguments. Helper constructors retain their original call form.
Live components without captured inputs use `...`; this display is not executable
or lossless source. The GUI displays identity JSON, not the creation statement.

### Prompt Generations

Prompt generations run PyRIT's prompt generators as background jobs and store each
result as a new named seed dataset. `GET /api/prompt-generators` describes each
generator's stages, target roles, and, for ASSERT, the scenario that runs its datasets.
Two generators are registered: `assert` (`AssertGenerator`, with a reviewable
dimensions stage) and `target_objective` (`TargetObjectiveGenerator`).

| Endpoint | Result |
| --- | --- |
| `POST /api/prompt-generations/preflight` | Validation errors, dataset-name availability, and a call/token estimate; no target is called |
| `POST /api/prompt-generations` | 201 with a queued generation; 409 if the dataset name is taken |
| `POST /api/prompt-generations/batch` | 201 with several queued generations that share a generator, targets, settings, and a `group_id`, such as an ASSERT suite |
| `GET /api/prompt-generations` | Generations newest first; the members of one batch in the batch's order |
| `GET`, `DELETE /api/prompt-generations/{id}` | Read or delete a record; deleting keeps the dataset |
| `POST /api/prompt-generations/{id}/continue\|retry\|cancel` | Finish a review, resume from the last checkpoint, or cancel |
| `GET`, `PUT /api/prompt-generations/{id}/review` | Read or save output awaiting review |
| `GET /api/prompt-generations/{id}/estimate` | Remaining calls from the checkpoint; ASSERT is exact once the taxonomy and dimension levels are known |
| `GET /api/prompt-generations/from-dataset?selection_key=` | The request recorded in a generated dataset, to edit and regenerate under a new name |
| `GET /api/prompt-generators/assert/behaviors\|suites` | The bundled ASSERT behavior and suite library |

Each backend runs one generation at a time and queues the rest. Records are stored in
memory (`PromptGenerationEntries`), so backends that share a database list the same
generations. `pause_for_review` is rejected for generators without a reviewable stage.

Dataset names are create-only, under one rule shared with dataset uploads: a name is
taken while stored seeds use it, an upload is staging it, or a generation holds it, and
the database's collation decides which names match. A generation holds its name until
it completes or is cancelled. If the name is taken while generating, the save fails
without adding seeds to the other dataset. If another dataset or generation takes the
name of a cancelled generation, that generation can't resume: retry returns 409, and a
new generation under another name starts over and repeats the model calls.

Failed, cancelled, and interrupted generations retry from their last checkpoint.
Shutdown interrupts running generations but lets a dataset save finish. On first use
after a restart with SQLite memory, active generations become `interrupted`. Shared
memory, such as Azure SQL, leaves them active because another backend may own them:
cancel a generation whose backend stopped, then retry or delete it. A cancel from
another backend stops a run at its next checkpoint, and a save it was running then
commits nothing; cancelling a save that this backend is running returns 409.

### Manual Messages

`POST /api/attacks/{id}/messages` remains synchronous: it waits for the send and returns
Expand Down
2 changes: 2 additions & 0 deletions pyrit/backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
media,
message_sends,
operations,
prompt_generations,
scenario_presets,
scenario_suites,
scenarios,
Expand Down Expand Up @@ -145,6 +146,7 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
app.include_router(techniques.router, prefix="/api", tags=["techniques"])
app.include_router(datasets.router, prefix="/api", tags=["datasets"])
app.include_router(operations.router, prefix="/api", tags=["operations"])
app.include_router(prompt_generations.router, prefix="/api", tags=["prompt-generations"])
app.include_router(scenarios.router, prefix="/api", tags=["scenarios"])
app.include_router(scenario_presets.router, prefix="/api", tags=["scenario-presets"])
app.include_router(scenario_suites.router, prefix="/api", tags=["scenario-suites"])
Expand Down
170 changes: 170 additions & 0 deletions pyrit/backend/models/prompt_generations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

"""
REST envelopes and views for prompt generation: running generator requests as background jobs,
reviewing intermediate output, and saving the result as a named seed dataset.

The stored job, its status, and its progress are ``pyrit.models`` types. Each generator defines the
shape of its ``request``, its review payload, and its result summary; ``GET /prompt-generators``
describes the registered generators.
"""

from datetime import datetime
from typing import Annotated, Any

from pydantic import BaseModel, ConfigDict, Field, JsonValue, StringConstraints

from pyrit.backend.models.common import IdentifierStr
from pyrit.models import (
PromptGenerationEstimate,
PromptGenerationProgress,
PromptGenerationStatus,
TargetObjectiveGenerationRequest,
)
from pyrit.models.prompt_generation import DatasetNameStr, GeneratorNameStr, TargetRoleStr


class PromptGeneratorStage(BaseModel):
"""One stage a generator runs, in order."""

name: str
label: str
reviewable: bool = Field(False, description="Whether generation can pause after this stage for review")


class PromptGeneratorTargetRole(BaseModel):
"""A target a generator uses, chosen from the target registry."""

role: str
label: str
description: str
required: bool


class PromptGeneratorDescriptor(BaseModel):
"""A registered generator and what it needs."""

name: str = Field(..., description="Stable generator key, used as ``generator`` in requests")
display_name: str
description: str
stages: list[PromptGeneratorStage]
target_roles: list[PromptGeneratorTargetRole]
follow_up_scenario: str | None = Field(
None, description="A scenario that runs datasets from this generator, preselected after completion"
)


class PromptGeneratorListResponse(BaseModel):
"""The registered generators."""

items: list[PromptGeneratorDescriptor]


class PromptGenerationSummary(BaseModel):
"""A generation without its request and checkpoint, for listings."""

id: str
generator: str
dataset_name: str
status: PromptGenerationStatus
pause_for_review: bool
group_id: str | None
group_label: str | None
progress: PromptGenerationProgress
error: str | None
created_by: str | None
created_at: datetime
updated_at: datetime
completed_at: datetime | None


class PromptGenerationDetail(PromptGenerationSummary):
"""A generation with its request, targets, and result summary."""

request: dict[str, JsonValue]
targets: dict[str, str]
review_completed: bool
summary: dict[str, JsonValue] | None
started_at: datetime | None


class PromptGenerationListResponse(BaseModel):
"""Generations, newest first."""

items: list[PromptGenerationSummary]


class PromptGenerationCreateRequest(BaseModel):
"""A generation to queue."""

model_config = ConfigDict(extra="forbid")

generator: GeneratorNameStr
dataset_name: DatasetNameStr = Field(..., description="Name of the dataset to create; it must not exist yet")
request: dict[str, Any]
targets: dict[TargetRoleStr, IdentifierStr] = Field(default_factory=dict)
pause_for_review: bool = Field(False, description="Pause after a reviewable stage so its output can be edited")
Comment thread
richlundeen marked this conversation as resolved.
Resolved


class TargetObjectiveCreateRequest(TargetObjectiveGenerationRequest):
"""A ``target_objective`` request within the backend's size limits."""

count: Annotated[int, Field(strict=True, ge=1, le=1_000)]
harm_categories: list[Annotated[str, StringConstraints(pattern=r"\S", max_length=100)]] = Field(
default_factory=list, max_length=50
)


class PromptGenerationPreflightResponse(BaseModel):
"""Whether a request can start, and an estimate of its work. No target is called."""

valid: bool
errors: list[str] = Field(default_factory=list)
dataset_name_available: bool
estimate: PromptGenerationEstimate | None = None


class PromptGenerationReview(BaseModel):
"""Output awaiting review, in the generator's review shape."""

generation_id: str
stage: str
payload: dict[str, JsonValue]


class PromptGenerationReviewUpdate(BaseModel):
"""Edited review output."""

model_config = ConfigDict(extra="forbid")

payload: dict[str, Any]


class PromptGenerationBatchItem(BaseModel):
"""One generation within a batch."""

model_config = ConfigDict(extra="forbid")

dataset_name: DatasetNameStr
request: dict[str, Any]


class PromptGenerationBatchCreateRequest(BaseModel):
"""Several generations that share a generator, targets, and settings, such as an ASSERT suite."""

model_config = ConfigDict(extra="forbid")

generator: GeneratorNameStr
label: Annotated[str, StringConstraints(min_length=1, max_length=200)]
items: list[PromptGenerationBatchItem] = Field(..., min_length=1, max_length=100)
targets: dict[TargetRoleStr, IdentifierStr] = Field(default_factory=dict)
pause_for_review: bool = False


class PromptGenerationRequestFromDataset(BaseModel):
"""A generator request reconstructed from a stored dataset, to regenerate it under a new name."""

generator: str
request: dict[str, JsonValue]
source_dataset_name: str
Loading
Loading