Skip to content

Commit 8741624

Browse files
authored
[BREAKING] FIX: CLI Updates (microsoft#1545)
1 parent 8872f97 commit 8741624

24 files changed

Lines changed: 508 additions & 399 deletions

.pyrit_conf_example

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ memory_db_type: sqlite
2424
# Available initializers:
2525
# - simple: Basic OpenAI configuration (requires OPENAI_CHAT_* env vars)
2626
# - airt: AI Red Team setup with Azure OpenAI (requires AZURE_OPENAI_* env vars)
27-
# - targets: Registers available prompt targets into the TargetRegistry
28-
# - scorers: Registers pre-configured scorers into the ScorerRegistry
27+
# - target: Registers available prompt targets into the TargetRegistry
28+
# - scorer: Registers pre-configured scorers into the ScorerRegistry
2929
# - load_default_datasets: Loads default datasets for all registered scenarios
3030
# - objective_list: Sets default objectives for scenarios
3131
#
@@ -39,16 +39,16 @@ memory_db_type: sqlite
3939
# Example:
4040
# initializers:
4141
# - simple
42-
# - name: targets
42+
# - name: target
4343
# args:
4444
# tags:
4545
# - default
4646
# - scorer
4747
initializers:
4848
- name: simple
4949
- name: load_default_datasets
50-
- name: scorers
51-
- name: targets
50+
- name: scorer
51+
- name: target
5252
args:
5353
tags:
5454
- default

build_scripts/env_local_integration_test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ OPENAI_TTS_KEY=${OPENAI_TTS_KEY2}
1717
AZURE_SQL_DB_CONNECTION_STRING=${AZURE_SQL_DB_CONNECTION_STRING_TEST}
1818
AZURE_STORAGE_ACCOUNT_DB_DATA_CONTAINER_URL=${AZURE_STORAGE_ACCOUNT_DB_DATA_CONTAINER_URL_TEST}
1919

20-
# E2E scenario test variables (used by openai_objective_target initializer)
20+
# E2E scenario test variables (used by target initializer)
2121
DEFAULT_OPENAI_FRONTEND_ENDPOINT=${AZURE_OPENAI_INTEGRATION_TEST_ENDPOINT}
2222
DEFAULT_OPENAI_FRONTEND_KEY=${AZURE_OPENAI_INTEGRATION_TEST_KEY}
2323
DEFAULT_OPENAI_FRONTEND_MODEL=${AZURE_OPENAI_INTEGRATION_TEST_MODEL}

doc/code/front_end/1_pyrit_scan.ipynb

Lines changed: 236 additions & 61 deletions
Large diffs are not rendered by default.

doc/code/front_end/1_pyrit_scan.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
# extension: .py
66
# format_name: percent
77
# format_version: '1.3'
8-
# jupytext_version: 1.17.3
9-
# kernelspec:
10-
# display_name: pyrit-dev
11-
# language: python
12-
# name: python3
8+
# jupytext_version: 1.19.1
139
# ---
1410

1511
# %% [markdown]
@@ -47,7 +43,7 @@
4743
#
4844
# PyRITInitializers are how you can configure the CLI scanner. PyRIT includes several built-in initializers you can use with the `--initializers` flag.
4945
#
50-
# The `--list-initializers` command shows all available initializers. Initializers are referenced by their filename (e.g., `objective_target`, `objective_list`, `simple`) regardless of which subdirectory they're in.
46+
# The `--list-initializers` command shows all available initializers. Initializers are referenced by their filename (e.g., `target`, `objective_list`, `simple`) regardless of which subdirectory they're in.
5147
#
5248
# List the available initializers using the --list-initializers flag.
5349

@@ -60,13 +56,13 @@
6056
# You need a single scenario to run, you need two things:
6157
#
6258
# 1. A Scenario. Many are defined in `pyrit.scenario.scenarios`. But you can also define your own in initialization_scripts.
63-
# 2. Initializers (which can be supplied via `--initializers` or `--initialization-scripts`). Scenarios often don't need many arguments, but they can be configured in different ways. And at the very least, most need an `objective_target` (the thing you're running a scan against).
59+
# 2. Initializers (which can be supplied via `--initializers` or `--initialization-scripts` or `initializers` section of config file (see [here](../../getting_started/pyrit_conf.md))). Scenarios often don't need many arguments, but they can be configured in different ways. And at the very least, most need an `objective_target` (the thing you're running a scan against) which you can configure by using the `--target` flag if your initializer registers targets (e.g. `target` initializer)
6460
# 3. Scenario Strategies (optional). These are supplied by the `--scenario-strategies` flag and tell the scenario what to test, but they are always optional. Also note you can obtain these by running `--list-scenarios`
6561
#
6662
# Basic usage will look something like:
6763
#
6864
# ```shell
69-
# pyrit_scan <scenario> --initializers <initializer1> <initializer2> --scenario-strategies <strategy1> <strategy2>
65+
# pyrit_scan <scenario> --target <target_name> --initializers <initializer1> <initializer2> --scenario-strategies <strategy1> <strategy2>
7066
# ```
7167
#
7268
# You can also override scenario parameters directly from the CLI:
@@ -78,29 +74,29 @@
7874
# Or concretely:
7975
#
8076
# ```shell
81-
# !pyrit_scan foundry.red_team_agent --initializers simple openai_objective_target --scenario-strategies base64
77+
# !pyrit_scan foundry.red_team_agent --target openai_chat --initializers load_default_datasets target --scenario-strategies base64
8278
# ```
8379
#
84-
# Example with a basic configuration that runs the Foundry scenario against the objective target defined in `openai_objective_target` (which just is an OpenAIChatTarget with `DEFAULT_OPENAI_FRONTEND_ENDPOINT` and `DEFAULT_OPENAI_FRONTEND_KEY`).
80+
# Example with a basic configuration that runs the Foundry scenario against the objective target defined in the `target` initializer.
8581

8682
# %%
87-
# !pyrit_scan foundry.red_team_agent --initializers openai_objective_target --strategies base64
83+
# !pyrit_scan foundry.red_team_agent --target openai_chat --initializers load_default_datasets target --strategies base64
8884

8985
# %% [markdown]
9086
# Or with all options and multiple initializers and multiple strategies:
9187
#
9288
# ```shell
93-
# pyrit_scan foundry.red_team_agent --database InMemory --initializers simple objective_target objective_list --scenario-strategies easy crescendo
89+
# pyrit_scan foundry.red_team_agent --target openai_chat --initializers load_default_datasets target --strategies easy crescendo
9490
# ```
9591
#
9692
# You can also override scenario execution parameters:
9793
#
9894
# ```shell
9995
# # Override concurrency and retry settings
100-
# pyrit_scan foundry.red_team_agent --initializers simple objective_target --max-concurrency 10 --max-retries 3
96+
# pyrit_scan foundry.red_team_agent --target openai_chat --initializers load_default_datasets target --max-concurrency 10 --max-retries 3
10197
#
10298
# # Add custom memory labels for tracking (must be valid JSON)
103-
# pyrit_scan foundry.red_team_agent --initializers simple objective_target --memory-labels '{"experiment": "test1", "version": "v2", "researcher": "alice"}'
99+
# pyrit_scan foundry.red_team_agent --target openai_chat --initializers load_default_datasets target --memory-labels '{"experiment": "test1", "version": "v2", "researcher": "alice"}'
104100
# ```
105101
#
106102
# Available CLI parameter overrides:
@@ -175,6 +171,7 @@ async def _get_atomic_attacks_async(self):
175171
await initialize_pyrit_async(memory_db_type="InMemory") # type: ignore
176172
MyCustomScenario()
177173

174+
178175
# %% [markdown]
179176
# Then discover and run it:
180177
#

doc/code/front_end/2_pyrit_shell.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,29 @@ pyrit_shell
1313
With startup options:
1414

1515
```bash
16-
# Set default database for all runs
17-
pyrit_shell --database InMemory
16+
# Load configuration file (if not provided, defaults to ~/.pyrit/.pyrit_conf if it exists)
17+
# to set database preference, initializers, labels, env_file, and more.
18+
pyrit_shell --config-file ./.pyrit_conf
1819

1920
# Set default log level
2021
pyrit_shell --log-level DEBUG
2122

2223
# Load initializers at startup
23-
pyrit_shell --initializers openai_objective_target load_default_datasets
24+
pyrit_shell --initializers load_default_datasets
2425

2526
# Load custom initialization scripts
2627
pyrit_shell --initialization-scripts ./my_config.py
2728
```
2829

2930
## Available Commands
3031

31-
Once in the shell, you have access to:
32+
Once starting the shell, you will see the list of commands you have access to. Some of them are shown below:
3233

3334
| Command | Description |
3435
|---------|-------------|
3536
| `list-scenarios` | List all available scenarios |
3637
| `list-initializers` | List all available initializers |
38+
| `list-targets` | List all available targets from the registry |
3739
| `run <scenario> [options]` | Run a scenario with optional parameters |
3840
| `scenario-history` | List all previous scenario runs in this session |
3941
| `print-scenario [N]` | Print detailed results for scenario run(s) |
@@ -48,32 +50,32 @@ The `run` command executes scenarios with the same options as `pyrit_scan`:
4850
### Basic Usage
4951

5052
```bash
51-
pyrit> run foundry.red_team_agent --initializers openai_objective_target load_default_datasets
53+
pyrit> run foundry.red_team_agent --target my_target --initializers target load_default_datasets
5254
```
5355

5456
### With Strategies
5557

5658
```bash
57-
pyrit> run garak.encoding --initializers openai_objective_target load_default_datasets --strategies base64 rot13
59+
pyrit> run garak.encoding --target my_target --initializers target load_default_datasets --strategies base64 rot13
5860

59-
pyrit> run foundry.red_team_agent --initializers openai_objective_target load_default_datasets -s jailbreak crescendo
61+
pyrit> run foundry.red_team_agent --target my_target --initializers target load_default_datasets -s jailbreak crescendo
6062
```
6163

6264
### With Runtime Parameters
6365

6466
```bash
6567
# Set concurrency and retries
66-
pyrit> run foundry.red_team_agent --initializers openai_objective_target load_default_datasets --max-concurrency 10 --max-retries 3
68+
pyrit> run foundry.red_team_agent --target my_target --initializers target load_default_datasets --max-concurrency 10 --max-retries 3
6769

6870
# Add memory labels for tracking
69-
pyrit> run garak.encoding --initializers openai_objective_target load_default_datasets --memory-labels '{"experiment":"test1","version":"v2"}'
71+
pyrit> run garak.encoding --target my_target --initializers target load_default_datasets --memory-labels '{"experiment":"test1","version":"v2"}'
7072
```
7173

7274
### Override Defaults Per-Run
7375

7476
```bash
75-
# Override database and log level for this run only
76-
pyrit> run garak.encoding --initializers openai_objective_target load_default_datasets --database InMemory --log-level DEBUG
77+
# Override log level for this run only
78+
pyrit> run garak.encoding --target my_target --initializers target load_default_datasets --log-level DEBUG
7779
```
7880

7981
### Run Command Options
@@ -85,7 +87,6 @@ pyrit> run garak.encoding --initializers openai_objective_target load_default_da
8587
--max-concurrency <N> Maximum concurrent operations
8688
--max-retries <N> Maximum retry attempts
8789
--memory-labels <JSON> JSON string of labels
88-
--database <type> Override default database (InMemory, SQLite, AzureSQL)
8990
--log-level <level> Override default log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
9091
```
9192

@@ -114,9 +115,9 @@ pyrit> scenario-history
114115
115116
Scenario Run History:
116117
================================================================================
117-
1) foundry.red_team_agent --initializers openai_objective_target load_default_datasets --strategies base64
118-
2) garak.encoding --initializers openai_objective_target load_default_datasets --strategies rot13
119-
3) foundry.red_team_agent --initializers openai_objective_target load_default_datasets -s jailbreak
118+
1) foundry.red_team_agent --initializers target load_default_datasets --strategies base64
119+
2) garak.encoding --initializers target load_default_datasets --strategies rot13
120+
3) foundry.red_team_agent --initializers target load_default_datasets -s jailbreak
120121
================================================================================
121122
122123
Total runs: 3
@@ -130,7 +131,7 @@ The shell excels at interactive testing workflows:
130131

131132
```bash
132133
# Start shell with defaults
133-
pyrit_shell --database InMemory --initializers openai_objective_target load_default_datasets
134+
pyrit_shell --initializers target load_default_datasets
134135

135136
# Quick exploration
136137
pyrit> list-scenarios
@@ -161,7 +162,7 @@ pyrit> print-scenario 2
161162

162163
2. **Use short strategy aliases** with `-s`:
163164
```bash
164-
pyrit> run foundry.red_team_agent --initializers openai_objective_target load_default_datasets -s base64 rot13
165+
pyrit> run foundry.red_team_agent --initializers target load_default_datasets -s base64 rot13
165166
```
166167

167168
3. **Review history regularly** to track what you've tested:

doc/code/registry/1_class_registry.ipynb

Lines changed: 13 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@
2020
"name": "stdout",
2121
"output_type": "stream",
2222
"text": [
23-
"Available scenarios: ['airt.content_harms', 'airt.cyber', 'airt.scam', 'foundry.red_team_agent', 'garak.encoding']...\n",
23+
"Available scenarios: ['airt.content_harms', 'airt.cyber', 'airt.jailbreak', 'airt.leakage', 'airt.psychosocial']...\n",
2424
"\n",
25-
"airt.content_harms:\n",
26-
" Class: ContentHarms\n",
25+
"ContentHarms:\n",
2726
" Description: Content Harms Scenario implementation for PyRIT. This scenario contains various ...\n",
2827
"\n",
29-
"airt.cyber:\n",
30-
" Class: Cyber\n",
28+
"Cyber:\n",
3129
" Description: Cyber scenario implementation for PyRIT. This scenario tests how willing models ...\n"
3230
]
3331
}
@@ -74,8 +72,6 @@
7472
}
7573
],
7674
"source": [
77-
"# Get a scenario class\n",
78-
"\n",
7975
"scenario_class = registry.get_class(\"garak.encoding\")\n",
8076
"\n",
8177
"print(f\"Got class: {scenario_class}\")\n",
@@ -102,56 +98,15 @@
10298
"name": "stdout",
10399
"output_type": "stream",
104100
"text": [
105-
"Found default environment files: ['./.pyrit/.env', './.pyrit/.env.local']\n",
106-
"Loaded environment file: ./.pyrit/.env\n",
107-
"Loaded environment file: ./.pyrit/.env.local\n"
108-
]
109-
},
110-
{
111-
"name": "stderr",
112-
"output_type": "stream",
113-
"text": [
114-
"\r\n",
115-
"Loading datasets - this can take a few minutes: 0%| | 0/45 [00:00<?, ?dataset/s]"
116-
]
117-
},
118-
{
119-
"name": "stderr",
120-
"output_type": "stream",
121-
"text": [
122-
"\r\n",
123-
"Loading datasets - this can take a few minutes: 2%|▋ | 1/45 [00:00<00:16, 2.70dataset/s]"
124-
]
125-
},
126-
{
127-
"name": "stderr",
128-
"output_type": "stream",
129-
"text": [
130-
"\r\n",
131-
"Loading datasets - this can take a few minutes: 38%|██████████▉ | 17/45 [00:00<00:00, 46.49dataset/s]"
132-
]
133-
},
134-
{
135-
"name": "stderr",
136-
"output_type": "stream",
137-
"text": [
138-
"\r\n",
139-
"Loading datasets - this can take a few minutes: 69%|███████████████████▉ | 31/45 [00:00<00:00, 56.82dataset/s]"
140-
]
141-
},
142-
{
143-
"name": "stderr",
144-
"output_type": "stream",
145-
"text": [
146-
"\r\n",
147-
"Loading datasets - this can take a few minutes: 100%|█████████████████████████████| 45/45 [00:00<00:00, 66.94dataset/s]"
101+
"Found default environment files: ['./.pyrit/.env']\n",
102+
"Loaded environment file: ./.pyrit/.env\n"
148103
]
149104
},
150105
{
151106
"name": "stderr",
152107
"output_type": "stream",
153108
"text": [
154-
"\n"
109+
"Loading datasets - this can take a few minutes: 100%|██████████| 58/58 [00:00<00:00, 68.45dataset/s]\n"
155110
]
156111
},
157112
{
@@ -178,7 +133,7 @@
178133
"await scenario.initialize_async(objective_target=target) # type: ignore\n",
179134
"\n",
180135
"# Option 2: Use create_instance() shortcut\n",
181-
"# scenario = registry.create_instance(\"encoding\", objective_target=my_target, ...)\n",
136+
"# scenario = registry.create_instance(\"garak.encoding\", objective_target=my_target, ...)\n",
182137
"\n",
183138
"print(\"Scenarios can be instantiated with your target and parameters\")"
184139
]
@@ -205,10 +160,10 @@
205160
"text": [
206161
"'garak.encoding' registered: True\n",
207162
"'nonexistent' registered: False\n",
208-
"Total scenarios: 5\n",
163+
"Total scenarios: 8\n",
209164
" - airt.content_harms\n",
210165
" - airt.cyber\n",
211-
" - airt.scam\n"
166+
" - airt.jailbreak\n"
212167
]
213168
}
214169
],
@@ -245,13 +200,13 @@
245200
"name": "stdout",
246201
"output_type": "stream",
247202
"text": [
248-
"Available initializers: ['airt', 'load_default_datasets', 'objective_list', 'openai_objective_target', 'simple']...\n",
203+
"Available initializers: ['airt', 'load_default_datasets', 'scenario_objective_list', 'scorer', 'simple']...\n",
249204
"\n",
250-
"airt:\n",
205+
"AIRT Default Configuration:\n",
251206
" Class: AIRTInitializer\n",
252207
" Description: AI Red Team setup with Azure OpenAI converters, composite harm/objective scorers...\n",
253208
"\n",
254-
"load_default_datasets:\n",
209+
"Default Dataset Loader for Scenarios:\n",
255210
" Class: LoadDefaultDatasets\n",
256211
" Description: This configuration uses the DatasetLoader to load default datasets into memory.\n",
257212
"...\n"
@@ -286,7 +241,7 @@
286241
"name": "python",
287242
"nbconvert_exporter": "python",
288243
"pygments_lexer": "ipython3",
289-
"version": "3.13.5"
244+
"version": "3.11.9"
290245
}
291246
},
292247
"nbformat": 4,

0 commit comments

Comments
 (0)