Skip to content

FEAT: Adding PyRITInitializer parameters#1456

Open
rlundeen2 wants to merge 12 commits intoAzure:mainfrom
rlundeen2:users/rlundeen/2026_03_10_initializer_tags
Open

FEAT: Adding PyRITInitializer parameters#1456
rlundeen2 wants to merge 12 commits intoAzure:mainfrom
rlundeen2:users/rlundeen/2026_03_10_initializer_tags

Conversation

@rlundeen2
Copy link
Contributor

Previously, initializer configuration (like target tags) was passed through constructor arguments, which didn't
translate cleanly to YAML config or CLI usage. This unifies the approach so parameters flow the same way regardless
of entry point.

This change adds a uniform params system for PyRIT initializers that works consistently across YAML config, CLI, and the
programmatic API.

What changed:

  • New InitializerParameter dataclass for initializers to declare their supported parameters (name, description,
    required, default)
  • initialize_async() now accepts an optional params: dict[str, list[str]] argument
  • Parameter values are lists of strings, mapping naturally to YAML lists, CLI comma-separated values, and direct
    API usage
  • CLI supports name:key=val1,val2 syntax (e.g., --initializers target:tags=default,scorer)
  • Validation rejects unknown params and enforces required params
  • TargetInitializer and ScorerInitializer migrated from constructor-based tags to the new params system
  • InitializerMetadata now exposes supported_parameters for discoverability
  • Backward-compatible with old-style initializers that don't accept params

rlundeen2 and others added 7 commits March 10, 2026 15:57
Add a dict[str, str] params system for PyRIT initializers that works
uniformly across YAML config, CLI, and the programmatic API.

Key changes:
- Add InitializerParameter dataclass for declaring supported params
- Add params: dict[str, str] | None to initialize_async signature
- Migrate TargetInitializer/ScorerInitializer from constructor tags to
  params-based (tags as comma-separated string)
- Update ConfigurationLoader to set _params instead of constructor kwargs
- Update FrontendCore with _initializer_configs and name:key=val;key2=val2
  CLI syntax for passing params
- Add param validation (ValueError on unknown/missing required params)
- Backward-compatible with old-style initializer scripts (no params arg)
- Update InitializerMetadata with supported_parameters for discovery
- Add comprehensive tests (294 passing)
- Update documentation and .pyrit_conf_example

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…list[str]]

Each parameter value is now a list of strings, which maps naturally to:
- YAML: native list syntax under args
- CLI: comma-separated values (tags=default,scorer -> ['default', 'scorer'])
- Programmatic API: direct list passing

This eliminates the need for comma-separated string parsing inside
initializers and provides a cleaner, more uniform API.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add name:key=val1,val2 syntax hints to --initializers help in shell.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Simple name: "simple" → {"name": "simple"}
- Name with params: "target:tags=default,scorer" → {"name": "target", "args": {"tags": "default,scorer"}}

For multiple params, separate with semicolons: "name:key1=val1;key2=val2"
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe this is not common and I don't have a solution for this but this has the potential to get long esp if a user has many initializers with many tags

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Potentially! But I hope people use the config, and also I could see this shortening things in some cases (e.g. something that would otherwise take several initializers can use an argument).

await self.initialize_async()
params = self.params if self.params else None
try:
await self.initialize_async(params=params)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused on these lines. We're passing an instance variable as an arg to the initializer's own method. Curious as to the reason we need to store the params as both an internal attribute of the instance and allow it to be passed in as an arg to initialize_async?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah good point, I was initially going this route due to thinking standardizing param names, but then went a diff route so we likely can just ref the params property. Updating.

# - A dictionary with 'name' and optional 'args' for parameters
#
# Parameters are lists of strings. Use the CLI command
# `pyrit_scan --list-initializers` to see available parameters.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we implement something like pyrit_scan --list-initializers --help or pyrit_scan --list-parameters simple instead to see available parameters? I imagine that users would want a dedicated interface for figuring out parameters once they choose one or more initializers and don't need to list them all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the idea, but lots of things to do in the CLI, I'd rather punt :)

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.

5 participants