Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

PyRIT Initializers

You can configure PyRIT using:

  1. Built-in initializers - TargetInitializer, ScorerInitializer, TechniqueInitializer, LoadDefaultDatasets

  2. External scripts - Custom PyRITInitializer classes for project-specific needs

Execution Order

When initialize_pyrit_async is called:

  1. Environment files are loaded (.env, .env.local)

  2. Memory database is configured

  3. Initializers execute in the order they are passed

Creating an Initializer

The following is a minimal PyRITInitializer class. It doesn’t need much! In this case, it sets the default value for temperature for all OpenAIChatTargets to .9.

<__main__.CustomInitializer at 0x1d5a2fdb440>

Built-in Initializers

PyRIT includes a few built-in initializers that set more intelligent defaults!

  • TargetInitializer: Registers targets from environment variables. With only OPENAI_CHAT_ENDPOINT, OPENAI_CHAT_MODEL, and OPENAI_CHAT_KEY set, it registers a sensible default objective/converter target.

  • ScorerInitializer: Registers default scorers (run it after TargetInitializer, since scorers use those targets).

  • TechniqueInitializer: Registers the attack techniques used by scenarios.

  • LoadDefaultDatasets: Loads the datasets required by registered scenarios into memory.

These are easy to include.

Found default environment files: ['./.pyrit/.env', './.pyrit/.env.local']
Loaded environment file: ./.pyrit/.env
Loaded environment file: ./.pyrit/.env.local
No new upgrade operations detected.

External Scripts

External scripts allow custom configurations without modifying PyRIT. For example, you can write your own library, include them, and never have to check out pyrit in editable mode. Here are some use cases:

  • Custom targets for security assessments

  • Project-specific defaults

  • Organization-specific defaults

As an example, say you are building a product, and want to set all your adversarial_chat in one place. You can using this!

Like the built-in initializers, external scripts have the same format and must contain PyRITInitializer classes. In fact, using something like TargetInitializer() as a template for your own is not a bad place to start.

Created: ./AppData/Local/Temp/tmprs016r1e/custom_init.py
Found default environment files: ['./.pyrit/.env', './.pyrit/.env.local']
Loaded environment file: ./.pyrit/.env
Loaded environment file: ./.pyrit/.env.local

The initialization_scripts argument ultimately uses pathlib.Path, so the scripts are loaded relative to the current working directory (where you’re executing the script from, not where PyRIT library is). To avoid ambiguity, it is usually better to use full paths if possible.

More information: