MAINT Migrate internal callers of deprecated ScenarioResult.to_dict()/from_dict() to Pydantic API#2005
Open
immu4989 wants to merge 1 commit into
Open
Conversation
…/from_dict() to Pydantic API
ScenarioResult.to_dict() and ScenarioResult.from_dict(...) are marked for removal in 0.16.0. Internal PyRIT code still calls the deprecated forms, emitting a DeprecationWarning on every GET /api/scenarios/runs/{id}/results REST call and every CLI scenario result print.
Both deprecated methods are thin wrappers around the Pydantic API (to_dict delegates to model_dump(mode='json', by_alias=True); from_dict delegates to model_validate). Output shape is identical, so the change is behavior-preserving.
Updates the two production call sites, three docstring references, and the matching test mocks. Also tightens the REST route return annotation from dict to dict[str, Any].
romanlutz
approved these changes
Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2004.
ScenarioResult.to_dict()andScenarioResult.from_dict(...)are marked for removal in 0.16.0. Internal PyRIT code still calls the deprecated forms, which emits aDeprecationWarningon everyGET /api/scenarios/runs/{id}/resultsREST call and every CLI scenario result print.Migration
The deprecated methods are thin wrappers around the Pydantic API.
ScenarioResult.to_dict()delegates toself.model_dump(mode="json", by_alias=True)andScenarioResult.from_dict(data)delegates tocls.model_validate(data). Output shape is identical, so the change is behavior-preserving.Changes
pyrit/backend/routes/scenarios.py: REST route now returnsresult.model_dump(mode="json", by_alias=True)and the response annotation is tightened fromdicttodict[str, Any].pyrit/cli/_output.py:print_scenario_result_asyncdeserializes withScenarioResult.model_validate(result_dict).pyrit/cli/api_client.py: docstring on the matching CLI client method describes the new payload spelling.tests/unit/backend/test_scenario_run_routes.py: route test mocksmodel_dumpinstead ofto_dict.tests/unit/cli/test_output.py: one test mocksmodel_validateinstead offrom_dict; the roundtrip integration test usesmodel_dump(mode="json", by_alias=True)to produce the payload.Verification