-
Notifications
You must be signed in to change notification settings - Fork 599
FEAT Content harm scenario #1174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hannahwestra25
wants to merge
17
commits into
Azure:main
Choose a base branch
from
hannahwestra25:hawestra/example_scenario
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6a3da9e
first draft of harm scenario
hannahwestra25 04d5742
Merge branch 'main' of https://github.com/Azure/PyRIT into hawestra/e…
hannahwestra25 2c03890
Merge branch 'main' of https://github.com/Azure/PyRIT into hawestra/e…
hannahwestra25 ea488f5
add tests and documentation
hannahwestra25 ddc6fe0
PR comments: simplify strategies and default to several attack types
hannahwestra25 8069f17
add prompts and tests
hannahwestra25 3dd0261
Merge branch 'main' of https://github.com/Azure/PyRIT into hawestra/e…
hannahwestra25 19dbc86
add scenario instructions
hannahwestra25 f342e50
rename and add attacks
hannahwestra25 6366e7e
rename folder, update notebook and md file
hannahwestra25 0bff470
Merge branch 'main' of https://github.com/Azure/PyRIT into hawestra/e…
hannahwestra25 e290f73
merge
hannahwestra25 5ee2103
rename file
hannahwestra25 1fe542b
update docs
hannahwestra25 4c4cdca
fix path
hannahwestra25 17c5435
fix naming
hannahwestra25 0e860e8
pre commit
hannahwestra25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
doc/code/scenarios/rapid_response_harm_dataset_loading.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # Preloading Datasets for AI RT Scenarios | ||
|
|
||
| ## Overview | ||
|
|
||
| The scenarios in the ai_rt folder class that test datasets be preloaded into PyRIT's `CentralMemory` before running any scenarios. This design ensures that: | ||
hannahwestra25 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 1. **Test data is centralized**: All prompts and objectives are stored in a consistent location | ||
| 2. **Scenarios are reusable**: Multiple scenarios can share the same datasets | ||
| 3. **Data is retrievable**: The scenario can automatically find and load the correct prompts based on strategy names | ||
| 4. **Memory is isolated**: Different test runs can use different memory instances (e.g., IN_MEMORY vs SQLite) | ||
|
|
||
| ## Dataset Naming Schema | ||
|
|
||
| The naming schema is **critical** for these scenarios to automatically retrieve the correct datasets. The schema follows this pattern: | ||
|
|
||
| ``` | ||
| <dataset_path_prefix><strategy_name> | ||
| ``` | ||
|
|
||
| ### Components | ||
|
|
||
| 1. **Dataset Path Prefix** (default: <scenario_name>): | ||
| - Can be customized via the `objective_dataset_path` parameter in the scenario constructor | ||
| - Helps organize datasets in memory when multiple scenario types are being used | ||
|
|
||
| 2. **Strategy Name** (required): | ||
| - Derived from the strategy enum value | ||
| - Converted to lowercase with underscores (e.g., `HateFictionalStory` → `hate_fictional_story`) | ||
| - Must match exactly for the scenario to find the dataset | ||
|
|
||
| ### Default Naming Examples for Rapid Response Harm Scenario | ||
|
|
||
| | Strategy Enum | Dataset Name | | ||
| |--------------|--------------| | ||
| | `RapidResponseHarmStrategy.HateFictionalStory` | `rapid_response_harm_hate_fictional_story` | | ||
| | `RapidResponseHarmStrategy.FairnessEthnicityInference` | `rapid_response_harm_fairness_ethnicity_inference` | | ||
| | `RapidResponseHarmStrategy.ViolenceCivic` | `rapid_response_harm_violence_civic` | | ||
| | `RapidResponseHarmStrategy.ViolenceProtestDisruption` | `rapid_response_harm_violence_protest_disruption` | | ||
| | `RapidResponseHarmStrategy.SexualContent` | `rapid_response_harm_sexual_content` | | ||
| | `RapidResponseHarmStrategy.HarassmentBullying` | `rapid_response_harm_harassment_bullying` | | ||
| | `RapidResponseHarmStrategy.MisinformationElection` | `rapid_response_harm_misinformation_election` | | ||
| | `RapidResponseHarmStrategy.LeakagePersonalData` | `rapid_response_harm_leakage_personal_data` | | ||
|
|
||
| ### Custom Dataset Path Prefix | ||
|
|
||
| You can customize the prefix when creating a scenario: | ||
|
|
||
| ```python | ||
| scenario = RapidResponseHarmScenario( | ||
| objective_target=my_target, | ||
| adversarial_chat=adversarial_target, | ||
| objective_dataset_path="custom_test_", # Custom prefix | ||
hannahwestra25 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| scenario_strategies=[RapidResponseHarmStrategy.HateFictionalStory] | ||
| ) | ||
|
|
||
| # Now the dataset name must be: "custom_test_hate_fictional_story" | ||
| ``` | ||
|
|
||
|
|
||
| ## Common Errors and Solutions | ||
|
|
||
| ### Error: "No objectives found in the dataset" | ||
|
|
||
| **Cause**: The dataset wasn't loaded into memory or the naming doesn't match. | ||
|
|
||
| **Solution**: | ||
| 1. Verify the dataset name matches the strategy name exactly | ||
| 2. Ensure you called `add_seed_groups_to_memory()` before running the scenario | ||
| 3. Check that the dataset includes a `SeedObjective` object | ||
|
|
||
| ```python | ||
| # Correct naming | ||
| dataset_name = "rapid_response_harm_" + strategy.value # e.g., "hate_fictional_story" | ||
| ``` | ||
|
|
||
| ### Error: Dataset not found for custom prefix | ||
|
|
||
| **Cause**: The scenario's `objective_dataset_path` doesn't match the dataset names in memory. | ||
|
|
||
| **Solution**: Ensure consistency between the scenario configuration and dataset names: | ||
|
|
||
| ```python | ||
| # Scenario configuration | ||
| scenario = RapidResponseHarmScenario( | ||
| objective_target=target, | ||
| adversarial_chat=adversarial, | ||
| objective_dataset_path="my_custom_prefix_" # Must match dataset names | ||
| ) | ||
|
|
||
| # Dataset must be named: "my_custom_prefix_hate_fictional_story" | ||
| await create_seed_dataset( | ||
| name="my_custom_prefix_hate_fictional_story", | ||
| prompts=[...], | ||
| objective="..." | ||
| ) | ||
| ``` | ||
|
|
||
| ## Additional Resources | ||
|
|
||
| - See `rapid_response_harm_scenario.ipynb` for a complete working example | ||
| - Check the `RapidResponseHarmStrategy` enum for all available strategies | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.