Skip to content

FEAT: Per-preset objective scorers for scenario suites - #4384

Open
hannahwestra25 wants to merge 28 commits into
microsoft:mainfrom
hannahwestra25:hannahwestra25-per-preset-objective-scorers
Open

hannahwestra25 wants to merge 28 commits into
microsoft:mainfrom
hannahwestra25:hannahwestra25-per-preset-objective-scorers

Conversation

@hannahwestra25

@hannahwestra25 hannahwestra25 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Lets a scenario preset name its own objective scorer, so a suite can score each entry differently. For example, one preset can use a true/false refusal scorer while another uses a float-scale threshold scorer such as scale_gpt4o_temp9_threshold_09. Today a suite applies one launch-level scorer, or the scenario default, to every entry.

  • ScenarioPreset gains an optional launch_defaults section (ScenarioPresetLaunchDefaults) with objective_scorer: str | None, the name of a registered scorer. It holds only portable values (registered names, never identifier hashes or target names), so presets stay portable across deployments. Omitting it keeps the scenario default, so existing presets are unchanged. PRESET_SCHEMA_VERSION stays at 1.
  • ScenarioSuiteLaunchResolver binds the preset's scorer name to this deployment's registered scorer and resolves each entry's scorer with this precedence: launch override, then the preset's scorer, then the scenario default. A launch-level scorer replaces the scorer of every entry whose scenario accepts one; entries for scenarios with a built-in scorer (e.g. foundry.red_team_agent) skip it, so mixed suites still launch. Each child run records the scorer it used.
  • Readiness and launch preflight attribute scorer issues to their entry (entry_id, source). When the preset names an unregistered scorer, that entry reports a readiness issue and the remediation points to that preset or to a launch override; a scorer on a scenario that can't use one says to clear it. check_preset flags a scorer set on a scenario that doesn't support one.
  • Suite entry status exposes launch_defaults, and Scanner History lists each run's scorer.
  • GUI (where, since FEAT: Group the Scanner's Launch tab by scenario module #4616, a suite is a preset and a scenario preset is one of its scenarios):
    • The scenario editor (Registry > Scenario presets) has an Objective scorer picker that stores the scorer's registered name. If a saved scenario stores a scorer its scenario can't use, the editor warns and offers Remove scorer; saving otherwise keeps the stored scorer.
    • The preset launch dialog on the Scanner's Presets tab has an Objective scorer override (default: use each scenario's scorer) and shows each scenario's effective scorer as previewed by the suite readiness endpoint: from scenario, launch override, scenario default, selected scorer not applicable, unavailable, or unresolved when readiness could not configure the scenario. Readiness issues appear in a warning bar (except a missing target while one can still be selected), a shared launch issue is listed once, and Launch stays disabled until they are resolved.
    • Opening a scenario preset in the Scanner launch form (?preset=<name>) seeds its scorer when the scenario accepts one.
    • Scanner History has a Scorer column.
  • Docs: the scenario suites guide, pyrit_conf.md, and the GUI and setup pages.

A preset stores only the scorer's registered name, so it stays portable across deployments; each launch binds the name to the deployment's current scorer and records the scorer it used. PyRIT versions without this field cannot read presets that set it.

Screenshots (live GUI against fixture scorers and presets; before is main, after is this PR):

Preset launch dialog (Scanner > Presets)

Before: the dialog lists the scenarios without scorers and has no scorer override; Launch is enabled once a target is selected.

Before: the preset launch dialog lists scenarios without scorers and has no scorer override

After: each scenario shows its effective scorer. The scenario whose scorer isn't registered is marked unavailable, the warning bar names it and how to fix it, and Launch stays disabled.

After: each scenario shows its scorer; the unregistered scorer is unavailable and Launch is disabled

After: an objective scorer override replaces every scenario's scorer for this launch, clears the issue, and enables Launch.

After: a launch scorer override applies to every scenario and enables Launch

Scenario editor (Registry > Scenario presets)

Before: no objective scorer field.

Before: the scenario editor's Parameters have no objective scorer field

After: an Objective scorer picker shows the scenario's stored scorer.

After: the scenario editor has an Objective scorer picker

After: a saved scenario that stores a scorer its scenario can't use shows a warning with Remove scorer.

After: a stored scorer on a scenario that can't use one shows a warning with Remove scorer

Scanner launch form opened from a scenario preset

Before: the objective scorer starts at the scenario default.

Before: the launch form opened from a scenario preset uses the scenario default scorer

After: the objective scorer is seeded from the scenario preset.

After: the launch form opened from a scenario preset is seeded with its scorer

Scanner History

Before: no scorer column; all three runs of the same preset used the scenario default scorer.

Before: Scanner History has no Scorer column

After: a Scorer column names each run's scorer, here a different one for each scenario of the preset.

After: Scanner History has a Scorer column naming each run's scorer

Design: https://gist.github.com/hannahwestra25/a7a01f8effc09a903434f952a37407c9

Presets can pin an objective scorer in an optional launch_defaults section. Suite launches resolve each entry's scorer as launch override > preset > scenario default; readiness attributes scorer issues to their entry; Scanner History shows each run's scorer.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 16:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Saving a preset when the scorer picker is unavailable silently deletes its existing scorer pin, so even a description-only edit changes scoring configuration.

1 open issue
What changed in this PR

This PR adds per-preset objective scorers to PyRIT’s scenario suites, allowing entries to use different scoring criteria while preserving launch-level overrides.

Changes:

  • Adds preset scorer defaults with launch → preset → scenario-default precedence and entry-specific readiness feedback.
  • Adds scorer selection to preset and suite forms, and displays recorded scorers in Scanner History.
  • Adds regression coverage and documents scorer precedence and deployment-specific identities.
File Description
tests/​unit/​registry/​test_scenario_suite_resolver.py Tests scorer precedence and per-entry resolution.
tests/​unit/​registry/​test_scenario_preset_registry.py Tests structural scorer compatibility checks.
tests/​unit/​models/​test_scenario_preset.py Tests serialization, normalization, and scorer identity.
tests/​unit/​memory/​memory_interface/​test_interface_scenario_history.py Tests persisted scorer projection.
tests/​unit/​backend/​test_scenario_suite_service.py Tests scorer defaults in entry status.
tests/​unit/​backend/​test_scenario_suite_execution_service.py Tests launch overrides and issue attribution.
tests/​unit/​backend/​test_scenario_run_service.py Tests safe scorer history summaries.
pyrit/​registry/​scenario_suite_resolver.py Resolves scorer defaults and tracks their source.
pyrit/​registry/​components/​scenario_preset_registry.py Flags unsupported preset scorers.
pyrit/​registry/​__init__.py Exports launch-default resolution helpers.
pyrit/​models/​scenario_readiness.py Adds entry and source attribution.
pyrit/​models/​catalog/​scenario.py Defines scorer summaries for run history.
pyrit/​models/​catalog/​scenario_preset.py Adds optional preset launch defaults.
pyrit/​models/​catalog/​__init__.py Exports the launch-default model.
pyrit/​models/​__init__.py Exposes the launch-default model publicly.
pyrit/​memory/​memory_interface.py Adds scorer identity to history records.
pyrit/​memory/​_scenario_history.py Retrieves persisted scorer identities.
pyrit/​backend/​services/​scenario_suite_service.py Includes defaults in suite entry status.
pyrit/​backend/​services/​scenario_suite_execution_service.py Attributes readiness results to entries and sources.
pyrit/​backend/​services/​scenario_run_service.py Builds secret-free scorer history summaries.
pyrit/​backend/​services/​scenario_configuration_resolver.py Centralizes request-field role mappings.
pyrit/​backend/​models/​scenario_suites.py Exposes entry launch defaults in API responses.
frontend/​src/​types/​index.ts Adds preset defaults and scorer history types.
frontend/​src/​components/​ScenarioSuites/​LaunchSuiteDialog.tsx Adds scorer overrides and effective-scorer labels.
frontend/​src/​components/​ScenarioSuites/​LaunchSuiteDialog.test.tsx Tests scorer labels and override submission.
frontend/​src/​components/​Scenarios/​ScenarioDetail.tsx Seeds the scan form’s scorer from presets.
frontend/​src/​components/​Scenarios/​ScenarioDetail.test.tsx Tests preset scorer initialization.
frontend/​src/​components/​Scenarios/​ScenarioCatalog.tsx Passes scorer registry state to suites.
frontend/​src/​components/​Scenarios/​ScannerSuiteSection.tsx Supplies scorer options to launch dialogs.
frontend/​src/​components/​ScenarioPresets/​scenarioPresetForm.ts Serializes selected scorer defaults.
frontend/​src/​components/​ScenarioPresets/​scenarioPresetForm.test.ts Tests scorer-default writing and clearing.
frontend/​src/​components/​ScenarioPresets/​ScenarioPresetEditor.tsx Adds preset scorer selection and persistence.
frontend/​src/​components/​ScenarioPresets/​ScenarioPresetEditor.test.tsx Tests loading, changing, and clearing scorers.
frontend/​src/​components/​History/​ScenarioHistory.tsx Adds the Scorer column.
frontend/​src/​components/​History/​ScenarioHistory.test.tsx Tests scorer display and unavailable values.
frontend/​src/​components/​Chat/​ChatScorerPicker.tsx Supports custom help and empty-option labels.
frontend/​src/​App.tsx Wires scorer registry state into new controls.
doc/​gui/​0_gui.md Summarizes scorer controls and history display.
doc/​getting_started/​pyrit_conf.md Documents stored scorer defaults and compatibility.
doc/​code/​setup/​0_setup.md Explains suite scorer precedence.
doc/​code/​scenarios/​4_scenario_suites.py Adds commented guidance for per-preset scorers.
doc/​code/​scenarios/​4_scenario_suites.ipynb Adds matching notebook guidance.

Review effort: Balanced

@hannahwestra25
hannahwestra25 marked this pull request as ready for review November 19, 2026 22:07
- Suite launch scorer override applies only to entries whose scenario accepts a scorer; others record source 'unsupported'.
- Launch defaults are resolved once per suite entry.
- 'Does not support' scorer issues tell the user to clear the scorer.
- Entry status exposes supports_objective_scorer; the launch dialog labels non-applicable overrides.
- ScenarioDetail seeds a preset scorer only for scenarios that accept one.
- Preset contract docstrings and docs note that a pinned scorer is deployment-specific.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@hannahwestra25

hannahwestra25 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

two parts still conflict with the framework:

  • The hash pin. RegisteredComponentReference requires identifier_hash, and the hash includes the judge target. The PR calls this "the one exception to target-agnosticism" (scenario_preset.py:20): a pinned preset must be re-pinned after any judge change, can't move between deployments, and can't be carried by code-registered suites. Presets otherwise name components "by registered name ... so a preset can move between deployments" (L88-89). Locking scorer identity across launches isn't required.
  • The generic launch_defaults section. "A field added here therefore needs no resolver change" generalizes one field for hypothetical others ("Don't over-engineer").

Smaller form that keeps the workflow (one launch, one report, a durable pairing of preset and scorer):

  1. Store the per-preset scorer as a registered scorer name, validated like scenario_name and techniques.
  2. At launch, bind the name to the deployment's current registration, and pin it per entry at preflight as the PR does today. Results still record the scorer identifiers.
  3. Resolve this one field explicitly instead of through the mirrored ScenarioPresetLaunchDefaults loop. Where the field sits is a reviewer choice.
  4. Keep the order (launch value, then preset, then scenario default) with source reporting, check_preset's issue, readiness for unregistered names, and a name picker.
  5. Restore the portability wording, so presets have no exception to target-agnosticism.
  6. Rebase onto main's scorer selection (FEAT: Add a StrongREJECT rubric scorer #4229) and leave compatibility to OBJECTIVE_SCORER_REQUIREMENTS.
  7. Reframe the docs from expected refuse/allow to different scoring configurations per preset.

The declared skip for scenarios with a built-in scorer and the History Scorer column may stay or move to a separate PR.

hannahwestra25 and others added 8 commits November 23, 2026 21:27
Resolve doc/code/scenarios/4_scenario_suites.py by keeping the per-preset
objective scorer section and main's relocated run and summary sections.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preset launch_defaults now hold only portable, launch-owned settings: the
objective scorer is a registered scorer name, never an identifier hash or
target name. An explicit binding table maps each launch_defaults field to a
binder; the objective scorer binder resolves the stored name to the
deployment's current registered reference once per entry at preflight, and
the resolver walks the table in launch -> preset -> scenario-default order,
reporting each value's source. An unregistered preset scorer name becomes a
per-entry readiness issue instead of blocking other entries.

The preset editor picker stores a name, and saving a preset whose scenario
renders no scorer control keeps the stored scorer instead of clearing it.
Docs describe different scoring configurations per preset.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
LaunchSuiteDialog now previews each entry's effective objective scorer, its source, and any unregistered-name issue through POST /api/scenario-suites/{name}/readiness instead of mirroring the server's launch -> preset -> default precedence in the frontend.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The launch dialog no longer labels an entry 'Scenario default scorer' when readiness reports no objective scorer binding for it; it shows the entry's readiness issue (for example a configuration error) as unresolved instead.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- Preset editor shows a stored scorer the scenario cannot use, with its issue and an explicit Remove
- Readiness keeps preset scorer attribution for evaluation-requirement failures
- Launch dialog lists readiness issues and disables Launch while any are reported
- Scorer picker no longer reports a saved scorer unavailable while loading
- Keep launch-default helpers module-private; drop unused entry-status scorer support
- Notebook example as code cell, History scorer cell width, remediation wording

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- Rename bind_registered_scorer to _bind_registered_scorer
- Launch dialog lists identical readiness messages once and colours only scorer issues on entries
- Issue bar keeps its height on narrow screens; entry scorer label starts below the preset name

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ialog

Group non-scorer, non-configuration issues by role, reason and remediation; when several entries report the same one, list it once without the suite service's 'Entry N (preset): ' prefix. Raw issues still drive the Launch guard.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…iness guard

The launch dialog now has a third combobox (Objective scorer override). It also reports an invalid suite child's readiness issue before launch and disables Launch, so assert the warning and the disabled button instead of clicking.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

@hannahwestra25 hannahwestra25 left a comment •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review records source coverage.

…side, gate suite launch on readiness, clarify scorer history

- Resolve each entry's objective scorer directly (launch override, preset name, scenario default) without a binding table; /resolve rejects an unsupported preset scorer
- Return the server-bound preset scorer so the launch form never binds by name client-side; show loading instead of unavailable
- Allow suite launches only after an issue-free readiness check; report readiness failures once and keep entry labels to name, source and status
- State an unusable stored scorer once in the preset editor
- Report unreadable scorer records in history with their cause, and name scorers by matching registration hash

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
hannahwestra25 and others added 17 commits December 2, 2026 15:04
Merge main 98cb85b and resolve three conflicts while keeping both sides:

- ScenarioPresetEditor.tsx: keep the scorer picker and main's leave-guard
  ConfirmDialog. The leave guard's draft now includes the objective scorer,
  so an edit that only changes the scorer is guarded like any other edit
  and a stored scorer alone does not mark the editor dirty.
- ScenarioPresetEditor.test.tsx: keep main's data-router harness and let the
  edit route take the scorer props the PR's scorer tests pass.
- test_scenario_suite_execution_service.py: keep both import additions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…story

App now passes the scorer registry error to Scanner History. While the lookup has failed, a run whose recorded scorer matches no loaded registration keeps its recorded type and hash instead of reading "Not registered", and the page states the lookup error once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
resolve_run_request_async now reads the preset and resolves it in one worker-thread hop. Resolution reads the scenario and scorer registries, which take locks and can rebuild their catalogs. The unsupported-scorer rejection is unchanged and still reaches the caller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The issues explain a scorer the scenario cannot use. An unregistered scorer name has no issue; it surfaces at launch readiness or launch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
check-public-imports requires the public export.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…alPropertyTypes

Main now enables exactOptionalPropertyTypes. The scorer props that forward a possibly-undefined value accept undefined, as the style guide asks, and the suite readiness request builds its config with withConfig like main's other calls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…corer

When the scorer list fails to load, the shared scorer picker and the scan
form judged a saved or preset scorer as unavailable and advised replacing
it. Treat a failed lookup like loading: the picker keeps the saved name and
states that scorers could not be loaded, and the scan form reports the
lookup failure instead of the unavailable advice. Launch stays blocked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The readiness gate stored a 409 from the preview as a plain error, so Launch
stayed disabled and the dialog's stale-suite refresh could no longer run.
Move the readiness fetch into a useSuiteReadiness hook that reports the
error status, and call onSuiteChanged when readiness returns 409, as a
launch 409 already does.

Before a target is chosen, leave the library's objective_target issue out
of the warning bar while targets exist to select; keep it when none are
registered, since its remediation is then the only hint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A suite launch runs its initializers before binding a preset's scorer, but
resolving one preset binds it at once. When the scorer is unregistered and
the request carries initializers, say that they do not run here, so they
cannot register it, and how to proceed. Document the same on the service
and the /resolve route.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The library resolver turned a preset scorer it could not bind into a side
error, and the backend service decided that it blocks the entry and wrote
the preset remediation. The resolver now puts the objective_scorer issue,
with its entry, source and remediation, on the resolved entry, and the
entry exposes the preset remediation for other scorer issues; the service
only prefixes and merges issues.

Drop the leftover field-to-role maps: the target roles are an inline tuple
again and the objective scorer role is the literal the rest of PyRIT uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cover the second suite resolution after launch initializers run: the
preset's scorer is unregistered until an initializer registers it, and the
child request must carry its bound reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The History summary reads the scorer from the run's scenario identifier and
falls back to the persisted column; the tests covered only the fallback.
Add a run whose identifier and column name different scorers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_every_launch_default_stays_portable inspected field names and
annotation strings rather than behavior. The resolver tests that bind a
stored scorer name through the registry cover portability.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The missing-target filter in the suite launch dialog had no negative case:
the existing test only asserted Launch was disabled, which holds without a
target regardless of the filter. Add a test where a target is selected and
readiness reports an objective_target issue, and assert the bar lists it and
Launch stays disabled. Drop the vacuous assertion from the no-bar test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve conflicts with main's Scanner regrouping (microsoft#4616), dataset
preparation history fields (microsoft#4228), and strict ESLint rules (microsoft#4779):

- Keep the objective scorer picker, unsupported-scorer warning, and
  scorer-aware leave guard in the edit-only scenario editor; route its
  scorer props from App.
- Drop ScannerSuiteSection with main and pass scorer props through the
  new ScannerPresetsPage to LaunchSuiteDialog; take main's ScenarioCatalog.
- Keep both objective_scorer_identifier and dataset_preparation fields on
  ScenarioHistoryRunRecord, and both test imports.
- Drop showInScanner from PresetIdentity with main; keep objectiveScorer.
- Remove an assertion the new no-unnecessary-type-assertion rule rejects.
- Describe per-scenario scorers in the GUI guide with main's preset terms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After main's Scanner regrouping (microsoft#4616), the UI calls a suite a preset and
a scenario preset a scenario. The scorer strings this PR added to the launch
dialog still used the old terms, so "from preset" pointed at the preset being
launched instead of the scenario that stores the scorer.

- LaunchSuiteDialog: "from scenario", "Use each scenario's scorer", help
  text and readiness error in preset/scenario terms, and the bars' accessible
  names "Preset configuration issues" / "Preset readiness error"; update the
  unit and seeded e2e assertions.
- ScenarioPresetEditor: put the component doc comment back on the component
  and list the objective scorer among the fields it edits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants