Skip to content

[BREAKING] FEAT: Save converters and scorers created through the API (part 12) - #4051

Open
varunj-msft wants to merge 447 commits into
microsoft:mainfrom
varunj-msft:varunj-msft/13178-Save-Converters-Scorers
Open

varunj-msft wants to merge 447 commits into
microsoft:mainfrom
varunj-msft:varunj-msft/13178-Save-Converters-Scorers

Conversation

@varunj-msft

@varunj-msft varunj-msft commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

Part 12 of saving Registry entries across restarts. It builds on part 9 (#4027, merged); part 13 (#4052) builds on it.

Design: 4.1 What gets saved, 4.5 Entries that use other entries. Where every part fits: PR map.

This is one of the changes for saving Registry entries across restarts. It builds on #4027, which is merged.

A converter or scorer created through the API is gone when the backend restarts. With "persist": true, POST /api/converters and POST /api/scorers now save it the way POST /api/targets does (#4026), so restore brings it back at every start.

  • The first commit only moves code. The target save steps go from target_service.py to a shared services/saved_entries.py: turn off the server values an entry would read, refuse what it can't hold or a Temporary entry it uses, write the recipe create-only, register it, and delete the recipe again if registering fails. The owner and not-saveable helpers move to routes/common.py, and TargetOrigin (new in FEAT: Save targets created through the API (part 8) #4026) becomes RegistryEntryOrigin. Targets behave as before.
  • persist on converters and scorers follows the target rules. It needs register and a name matching ^[a-z][a-z0-9_]{0,63}$ (422 otherwise). A refusal is a typed 400 (/errors/not-saveable, with the cause in not_saveable_reason), and unreadable storage is 503. A taken converter name is 409 whether or not it's saved; a taken scorer name is 409 when saving and stays 400 otherwise. The owner is recorded in the saved file as for targets. As with targets, a private converter or scorer can't be saved (422).
  • A saved converter or scorer may only use saved or configuration entries. A reference left out of the request but filled from the configured default values (@apply_defaults) is written into the recipe by name, each entry of a list included, so restore uses the same entries even if nothing sets that default at the next start. A default that is Temporary, or isn't a registered entry, is refused. Other configured defaults apply again from the configuration at every start, as they do for startup entries.
  • A saved converter or scorer can use this server's keys and Azure identity, as the ones from the configuration do (DOC: Clarify framework security boundaries and component reuse #4465), so the Azure Speech converters and the Content Safety, audio and local refusal scorers can be saved. It still can't hold a typed key, and a saved Content Safety scorer's endpoint can't carry a credential in its URL (a user name, password, SAS token or other query), as for targets; left empty, it takes this server's setting. This takes out the refusals from FIX: Refuse saved converters and scorers that would use this server's credentials (part 11) #4050, which was closed.
  • Breaking: LocalRefusalClassifierScorer.model_id now names a Hugging Face Hub repository only, checked when the scorer is built. A local checkpoint folder goes in the new model_path (a Path), which the API refuses like other server paths, so a caller can't make a saved or Temporary scorer load a folder on the server. Python code that passed a folder as model_id now gets a ValueError and should pass model_path=Path(...) instead. The scorer is experimental, and a deprecation period would keep the gap open, since the constructor can't tell an API call from Python. A scorer without model_path keeps its identity.
  • A converter to save can't take an uploaded file yet, and is built without file parameters, as restore builds it. An optional file left empty (None or '') is left out, so the converter still saves. A type that needs a file gives only that cause in not_saveable_reason. A copy made with source can't be saved yet (422).
  • Saving a scorer finds its class and builds it off the event loop, since finding the class can take over a second.
  • Converters and scorers now have origin (saved, configuration or temporary) on list, get and create, and the startup entries of all three kinds are marked as configuration.
  • DELETE /api/converters/{id} returns 409 for a saved converter, since it would come back from its file at the next start. Temporary and configuration converters are removed as before.
  • The scorer name types is now reserved, as it is for targets and converters, since GET /api/scorers/types would hide a scorer with that name.
  • The backend README and pyrit_conf.md describe saving converters and scorers.

Not covered:

  • Converters that pick randomly without a seed, such as the bijection and policy puppetry ones, come back with a new mapping after a restart, as startup converters do.
  • GET /api/scorers/types doesn't say yet why a scorer type can't be saved; saving one refuses it with the reason.
  • Saving converters from the GUI is FEAT: Save converters from the Registry (part 13) #4052 (part 13). Saving copies, deleting or editing saved entries, and keeping uploaded or Blob files on saved converters come later.

Copilot AI balanced review requested due to automatic review settings November 7, 2026 23:56

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

Saved LocalViolenceClassifierScorer instances can still download models using the server’s cached Hugging Face token or HF_TOKEN, with no save-policy refusal or safeguard disabling authenticated downloads.

4 open issues
What changed in this PR

Extends PyRIT’s saved-target infrastructure to converters and scorers created through the API, allowing eligible registry entries to survive backend restarts.

Changes:

  • Adds optional persistence with shared validation, dependency checks, ownership metadata, and rollback on registration failure.
  • Restores saved entries during startup and reinitialization, reports their origin, and protects them from replacement.
  • Includes target-origin and ownership UI, isolated test storage, regression coverage, and configuration documentation.
File Description
tests/​unit/​setup/​test_targets_initializer.py Tests saved-target collision protection.
tests/​unit/​setup/​test_scorer_initializer.py Tests saved-scorer tagging safeguards.
tests/​unit/​setup/​test_converter_initializer.py Tests saved-converter replacement refusal.
tests/​unit/​setup/​test_configuration_loader.py Tests recipe-storage configuration.
tests/​unit/​registry/​test_instance_registry.py Tests origin metadata and replacement guards.
tests/​unit/​registry/​test_attack_technique_registry.py Tests saved-technique collision handling.
tests/​unit/​backend/​test_scorer_service.py Covers scorer persistence and restoration.
tests/​unit/​backend/​test_scorer_routes.py Covers persistence requests and HTTP errors.
tests/​unit/​backend/​test_scenario_suite_routes.py Tests sanitized storage failures.
tests/​unit/​backend/​test_scenario_suite_execution_service.py Tests saved-entry launch conflict reporting.
tests/​unit/​backend/​test_scenario_run_service.py Tests launch-script replacement safeguards.
tests/​unit/​backend/​test_scenario_preset_routes.py Tests sanitized storage failures.
tests/​unit/​backend/​test_saved_entries.py Tests persistent-reference eligibility.
tests/​unit/​backend/​test_mappers.py Tests target origin and ownership mapping.
tests/​unit/​backend/​test_initializer_service.py Tests unavailable local storage responses.
tests/​unit/​backend/​test_auth_middleware.py Tests signed-in user ID extraction.
tests/​unit/​backend/​test_analytics_benchmark.py Verifies benchmark storage isolation.
tests/​unit/​backend/​conftest.py Isolates saved recipes in backend tests.
tests/​end_to_end/​conftest.py Isolates launched backend recipe storage.
test_support/​analytics_benchmark.py Configures benchmark-specific recipe storage.
pyrit/​setup/​initializers/​tools.py Rejects saved-entry collisions during tool setup.
pyrit/​setup/​initializers/​targets.py Guards target grouping against saved collisions.
pyrit/​setup/​initializers/​scorers.py Guards automatic tagging of saved scorers.
pyrit/​setup/​configuration_loader.py Adds recipe-storage source configuration.
pyrit/​score/​true_false/​local_refusal_classifier_scorer.py Declares the scorer unsuitable for persistence.
pyrit/​score/​true_false/​audio_true_false_scorer.py Declares credential-dependent persistence refusal.
pyrit/​score/​scorer.py Adds scorer persistence-policy metadata.
pyrit/​score/​float_scale/​azure_content_filter_scorer.py Declares server credential fallback.
pyrit/​score/​float_scale/​audio_float_scale_scorer.py Declares credential-dependent persistence refusal.
pyrit/​registry/​registry_recipe_storage.py Implements per-registry JSON recipe storage.
pyrit/​registry/​instance_registry.py Tracks origins, owners, and replacement refusals.
pyrit/​registry/​components/​scorer_registry.py Reserves the types instance name.
pyrit/​registry/​components/​attack_technique_registry.py Adds saved metadata and collision protection.
pyrit/​prompt_target/​websocket_copilot_target.py Declares persistence refusal for server sign-in.
pyrit/​prompt_target/​prompt_shield_target.py Declares credential and destination policies.
pyrit/​prompt_target/​openai/​openai_target.py Declares credential, header, and destination policies.
pyrit/​prompt_target/​litellm_chat_target.py Declares API-key fallback.
pyrit/​prompt_target/​hugging_face/​hugging_face_chat_target.py Declares token fallback and persistence refusal.
pyrit/​prompt_target/​http_target/​http_target.py Refuses persistence of raw HTTP requests.
pyrit/​prompt_target/​hack_a_prompt_target.py Declares session and cookie fallbacks.
pyrit/​prompt_target/​github_copilot_target.py Declares GitHub token fallback.
pyrit/​prompt_target/​common/​prompt_target.py Defines target persistence-policy metadata.
pyrit/​prompt_target/​azure_ml_chat_target.py Declares credential and endpoint policies.
pyrit/​prompt_target/​azure_blob_storage_target.py Declares token and container-URL policies.
pyrit/​prompt_target/​a2a_target.py Declares destination parameters for validation.
pyrit/​models/​catalog/​target.py Adds target origin and ownership fields.
pyrit/​models/​catalog/​scorer.py Adds scorer origin.
pyrit/​models/​catalog/​registry_recipe.py Defines recipes, origins, owners, and restore reports.
pyrit/​models/​catalog/​__init__.py Exports recipe-related models lazily.
pyrit/​converter/​converter.py Adds converter credential-fallback metadata.
pyrit/​converter/​azure_speech_text_to_audio_converter.py Declares Azure Speech credential fallback.
pyrit/​converter/​azure_speech_audio_to_text_converter.py Declares Azure Speech credential fallback.
pyrit/​backend/​services/​scorer_service.py Saves scorers and exposes their origins.
pyrit/​backend/​services/​scenario_suite_execution_service.py Exposes actionable saved-entry launch conflicts.
pyrit/​backend/​services/​scenario_run_service.py Detects launch scripts conflicting with saved entries.
pyrit/​backend/​services/​saved_entries.py Shares validation, saving, registration, and rollback.
pyrit/​backend/​services/​runtime_lifecycle.py Restores recipes and reports startup failures.
pyrit/​backend/​services/​converter_service.py Saves converters and guards saved-entry deletion.
pyrit/​backend/​routes/​targets.py Passes persistence context and maps save errors.
pyrit/​backend/​routes/​scorers.py Adds scorer persistence response handling.
pyrit/​backend/​routes/​scenarios.py Documents saved-entry launch conflicts.
pyrit/​backend/​routes/​scenario_suites.py Sanitizes storage diagnostics and list failures.
pyrit/​backend/​routes/​scenario_presets.py Sanitizes storage diagnostics and list failures.
pyrit/​backend/​routes/​initializers.py Handles local storage failures safely.
pyrit/​backend/​routes/​converters.py Maps persistence and deletion errors.
pyrit/​backend/​routes/​common.py Shares owner extraction and save-refusal responses.
pyrit/​backend/​README.md Documents persistence APIs and restrictions.
pyrit/​backend/​models/​targets.py Adds persistence validation and saveability fields.
pyrit/​backend/​models/​scorers.py Adds validated scorer persistence requests.
pyrit/​backend/​models/​converters.py Adds persistence validation and origin fields.
pyrit/​backend/​middleware/​auth.py Exposes the current user’s object ID.
pyrit/​backend/​mappers/​target_mappers.py Maps target origin and saver information.
pyrit/​backend/​mappers/​converter_mappers.py Maps converter origin.
frontend/​src/​utils/​targetOrigin.ts Defines target-origin display labels.
frontend/​src/​utils/​registryName.ts Generates valid, available registry names.
frontend/​src/​utils/​registryName.test.ts Tests name validation and suggestions.
frontend/​src/​types/​index.ts Adds target persistence and ownership types.
frontend/​src/​test-utils/​targetFixtures.ts Supports origin and ownership fixtures.
frontend/​src/​services/​errors.ts Recognizes typed save refusals.
frontend/​src/​services/​errors.test.ts Tests save-refusal recognition.
frontend/​src/​components/​Config/​TargetTable.tsx Displays origins, savers, and ownership filtering.
frontend/​src/​components/​Config/​TargetTable.test.tsx Tests origin display and ownership filtering.
frontend/​src/​components/​Config/​TargetTable.styles.ts Styles saver captions and filter controls.
frontend/​src/​components/​Config/​TargetOriginBadge.tsx Renders target-origin badges.
frontend/​playwright.config.ts Isolates seeded backend recipe storage.
frontend/​e2e/​registry.spec.ts Tests target saving through the GUI.
frontend/​e2e/​fixtures/​manual_send_backend.py Isolates offline fixture recipe storage.
frontend/​e2e/​config.spec.ts Tests saving and ownership UI behavior.
frontend/​e2e/​_targets.ts Extends target mocks with persistence metadata.
doc/​gui/​0_gui.md Explains saved targets and ownership controls.
doc/​getting_started/​pyrit_conf.md Documents recipe storage and restoration behavior.
.pyrit_conf_example Adds commented recipe-storage configuration.

Review effort: Balanced

Comment thread pyrit/score/scorer.py Resolved
Comment thread pyrit/backend/services/saved_entries.py Resolved
Comment thread pyrit/backend/services/saved_entries.py Resolved
@varunj-msft varunj-msft changed the title FEAT: Save converters and scorers created through the API FEAT: Save converters and scorers created through the API (part 12) Nov 9, 2026
# Conflicts:
#	tests/unit/registry/test_registry_recipe_restore.py
This goes back to the behavior before the runtime stayed ready with held
names. If any saved entry can't be restored, the runtime is failed with
outcome restore-failed and doesn't publish, so a scan can't run without
an entry it expects. The held names, the technique selection check, and
their 409 handlers are removed. Each failure is still logged, and the
administrator warning and the apply-after-restore test stay.

Apply now runs from the failed state. It resets the registries and
restores again, so fixing or deleting the listed files and applying
recovers without a restart. The failure message says to apply or
restart when live apply is on, and to restart when it's off; applying
with live apply off says to restart.
… a saveability answer once its request goes away

The private-target test now controls the debounce clock, so a slow run can't check the values chosen before Only me.
Signed-in users may create shared converters and scorers that connect with this server's credentials, so a saved one
isn't refused for that. This takes out the refusals of the Azure Speech converters and the Content Safety, audio and
local refusal scorers. A saved entry still can't hold a typed key.

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.

The saved local-checkpoint path needs fixing before approval; two nonblocking notes are inline.

Comment thread pyrit/backend/README.md Resolved
…t set

LocalRefusalClassifierScorer.model_id now names a Hugging Face Hub repository only, checked when the
scorer is built. A local checkpoint folder goes in the new Path-typed model_path, which the API refuses
like other server paths, so a saved or Temporary scorer can't load a folder a caller chose. A scorer
without model_path keeps its identity.
…credential

The scorer now declares its endpoint as a destination. Saving refuses an endpoint URL with a user name,
password, SAS token or other query, as for targets. An empty endpoint still takes this server's setting.
Converters answer a taken name with 409 whether or not the request saves the converter. Scorers answer
409 only when saving.
@varunj-msft varunj-msft changed the title FEAT: Save converters and scorers created through the API (part 12) [BREAKING] FEAT: Save converters and scorers created through the API (part 12) Nov 23, 2026

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.

The earlier findings are fixed. One P2 regression-test gap remains; see the inline comment.

The local-folder test built the private encoder itself, so it passed even if the scorer stopped passing
model_path on. It now builds the scorer with model_path or a Hub model_id and calls load_model_async.
Only registry_recipe_save and its tests use it, and it isn't exported, so it keeps the underscore it
had before this change.
not_saveable_reason is the cause alone, and the GUI already shows that the converter can't be saved, so
the reason no longer starts with "'X' can't be saved."
An optional file parameter sent as null or an empty string means no file, so saving leaves it out, as
restore builds the converter, instead of refusing it as an uploaded file.

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.

The P2 checkpoint-test gap is fixed, and I found no blocking issues at this head. Two nonblocking P3 items remain: the inline comment about empty optional files, and the description correction below.

[P3] Correct the description's first bullet

The first bullet describes moves that are already on main. Before this PR, targets already used prepare_saved_params_async and save_then_register_async, and RegistryEntryOrigin already existed. At this head, services/saved_entries.py adds only SavedEntryRemovalError. Describe the converter and scorer use of the library save helpers instead, and keep the route-helper move.

requested = {
name: value
for name, value in request.params.items()
if name not in upload_params or value not in (None, "")

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.

[P3] Use the same empty-file rule on both create paths

With AddTextImageConverter and params={"text_to_add":"hi","font_name":""}, persist=true succeeds because this filter removes the empty font. Changing only persist to false returns 400 because font_name must be uploaded as a data URI. The same parameters should have the same meaning on both paths. Either treat an empty optional file as omitted on both paths, or refuse it on both paths. Keep the required-file checks, and add one parametrized test for both persist values.

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.

Automated review completed. No blocking concerns remain. This review records source coverage; merging is handled separately.

[P3] inline:4686259966: This run's published copy of local CR-7 on converter_service.py:433 RIGHT at head 7e1970e. Same supported, unfixed P3 cause as finding CR-7 (feedback-readiness/feedback.json reproduction): empty optional font_name saves with persist=true and is refused with persist=false. No source change since verification.

[P3] review:6047058516: This run's COMMENT review at head 7e1970e. Its body states the P2 gap is fixed and carries the published copy of local CR-5 (stale first description bullet), plus a pointer to the CR-7 inline comment. Same supported open P3 causes as findings CR-5 and CR-7; no additional concern.

[P3] local:CR-7: Supported, unfixed, P3. converter_service.py:428-434 (added by 7e1970e) drops an optional upload valued '' when saving, but the Temporary path's _persist_data_uri_params_async (663-674) skips only None and refuses ''. Reproduced: AddTextImageConverter {'text_to_add':'hi','font_name':''} saves with persist=true and raises 'Path parameter font_name must be uploaded as a data URI' with persist=false; None works on both. P3 because documented inputs (omit/null) agree, the refusal is loud, nothing wrong is saved, and the GUI does not use this persist path. Fix: one shared rule for an empty optional file on both paths (treat as omitted, or refuse on both), with one parametrized public test.

[P3] local:CR-5: Supported, unfixed, P3. PR body's first bullet claims target save steps move to services/saved_entries.py and TargetOrigin becomes RegistryEntryOrigin. At base 604faf8 target_service.py already uses prepare_saved_params_async/save_then_register_async and RegistryEntryOrigin (registry_recipe.py:22); TargetOrigin is absent; at head saved_entries.py holds only SavedEntryRemovalError and target_service.py's diff only inlines ComponentRecipe. The routes/common.py helper move is real. Description-only; correct the bullet in a PR-level note.

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