Repository navigation
MAINT: Type the initializer info payloads as TypedDicts (P311-02) - #4542
Merged
Roman Lutz (romanlutz) merged 5 commits intoNov 23, 2026
Merged
Roman Lutz (romanlutz) merged 5 commits into
Roman Lutz (romanlutz) merged 5 commits into
Conversation
get_info_async() and get_dynamic_default_values_info_async() now return InitializerInfo and InitializerDefaultsInfo instead of dict[str, Any], so the optional keys and the message-string arms are part of the signature. Case 2a of microsoft#4505.
Copilot started reviewing on behalf of
Mohammed Shoaib Choudry (DevShoaib78)
November 21, 2026 17:25
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The test clears the process-wide memory singleton without restoring it, potentially leaving subsequent callers with uninitialized memory; a scoped patch is needed to avoid leaking state.
1 open issue
What changed in this PR
This PR gives PyRIT’s initializer metadata APIs explicit TypedDict contracts, implementing case 2a of #4505 and following the existing BuildInfo pattern.
Changes:
- Defines required and optional payload fields, including list-or-error-string values and a private tracking type.
- Exports the three public contracts through
pyrit.setup.initializers. - Adds tests for complete and minimal payloads, key contracts, and failure responses.
| File | Description |
|---|---|
tests/unit/setup/test_pyrit_initializer.py |
Tests TypedDict contracts, optional-key omission, and message-string responses. |
pyrit/setup/pyrit_initializer.py |
Adds typed payloads and return annotations; builds required keys before optional keys. |
pyrit/setup/initializers/__init__.py |
Adds lazy exports and type-checking imports for the public contracts. |
Review effort: Balanced
The no-memory get_info_async test cleared CentralMemory for the rest of the process; it now patches get_memory_instance for the one call.
…fo_async The committed output cell still showed supported_parameters before default_values/global_variables; get_info_async now inserts the required keys first, so a notebook regeneration would have produced this diff. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Roman Lutz (romanlutz)
approved these changes
Nov 22, 2026
Roman Lutz (romanlutz)
enabled auto-merge
November 22, 2026 08:28
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

Description
Case 2a of #4505:
PyRITInitializer.get_info_async()andget_dynamic_default_values_info_async()now return TypedDicts instead ofdict[str, Any], following theBuildInfopattern from #4106.InitializerInfo(functional syntax, sinceclassis a keyword):description,class,default_valuesandglobal_variablesare Required;supported_parametersandrequired_env_varsare NotRequired, as they are only added when the initializer declares some.InitializerDefaultsInfo: both keys Required, typedlist[str] | str. Thestrarm is the message returned when memory is not initialized or the sandbox run raises; the docstrings now say so.InitializerParameterInfotypes eachsupported_parametersentry (name,description,default)._InitializationTrackingtypes the dict yielded by_track_initialization_changes, which only ever holds lists.get_dynamic_default_values_info_asyncbuilds its return value from it, since the list-only TypedDict is not assignable to thelist[str] | strone.pyrit.setup.initializers, next toPyRITInitializer, so callers can annotate with them.get_info_asyncnow builds the dict with its Required keys first, sodefault_valuesandglobal_variablescome before the optional keys when iterating (the configuration notebook printsinfo.items()). Happy to restore the old order if you prefer it; it needs either a cast or building the dict per case.tests/unit/setup/test_pyrit_initializer.pypin the Required and NotRequired keys of all three TypedDicts, the full payload when every key is present, the required-only payload, and bothstrarms (no memory, and a raising sandbox run or lookup).I left the
# type: ignoreoninfo = await TargetInitializer.get_info_async()indoc/code/setup/1_configuration.py. Checking that file with ty without it reportsawaitoutside of an asynchronous function, the same as the other top-level awaits there, so it covers the top-level await rather than the return type.Case 2b (
pyrit.outputJSON payloads) is not part of this PR, so #4505 stays open.