Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5eb9200
moved initialization to setup
rlundeen2 Oct 9, 2025
18b07ed
added default values
rlundeen2 Oct 9, 2025
fde8790
basics working
rlundeen2 Oct 11, 2025
0d3fb06
restoring ipynb from main
rlundeen2 Oct 11, 2025
c8371d2
adding attack factory
rlundeen2 Oct 11, 2025
8092af9
adding more templates
rlundeen2 Oct 11, 2025
71d01fd
moving things around
rlundeen2 Oct 11, 2025
a036ef0
attack factory updated
rlundeen2 Oct 11, 2025
a56911b
Added dataset factory config
rlundeen2 Oct 11, 2025
27a96f0
Added scenarios
rlundeen2 Oct 11, 2025
69a091f
end of day
rlundeen2 Oct 12, 2025
434d5c2
Renaming scenario to attackRun
rlundeen2 Oct 12, 2025
bc6f2b6
scenario factory
rlundeen2 Oct 13, 2025
176519f
fixed some corruption
rlundeen2 Oct 13, 2025
001a41f
pre-commit
rlundeen2 Oct 13, 2025
da2ed83
test fixes
rlundeen2 Oct 14, 2025
8f078e7
cleaning up
rlundeen2 Oct 15, 2025
c7cacd5
cleaning up more
rlundeen2 Oct 15, 2025
9443290
Pruning scenarios
rlundeen2 Oct 16, 2025
9eae6a9
Merge branch 'main' into users/rlundeen/2025_10_09_default_values
rlundeen2 Oct 16, 2025
e7a2db2
pre-commit and adding apply_defaults
rlundeen2 Oct 16, 2025
a3f0a04
updating import paths for notebooks
rlundeen2 Oct 16, 2025
9078bd2
Adding second set of simple defaults
rlundeen2 Oct 16, 2025
022b5cc
pre-commit and pr feedback
rlundeen2 Oct 17, 2025
3b90b47
pre-commit and pr feedback
rlundeen2 Oct 17, 2025
05a4db9
small init edits
rlundeen2 Oct 17, 2025
27486df
set_global_value added
rlundeen2 Oct 17, 2025
d0e9b17
class structure for initializers
rlundeen2 Oct 18, 2025
5f2a95d
structuring docs
rlundeen2 Oct 18, 2025
4df7fb2
merging main
rlundeen2 Oct 23, 2025
49346da
updating documentation
rlundeen2 Oct 23, 2025
3de8c45
updating tests
rlundeen2 Oct 23, 2025
d5e9d78
pre-commit
rlundeen2 Oct 24, 2025
4b51c71
fixing build issues
rlundeen2 Oct 24, 2025
115d3b1
Fixing bug in get_info
rlundeen2 Oct 24, 2025
39e454b
typos
rlundeen2 Oct 24, 2025
b6c8630
pre-commit
rlundeen2 Oct 24, 2025
35b941a
merge conflicts
rlundeen2 Oct 24, 2025
abdff22
pr feedback and pre-commit
rlundeen2 Oct 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/instructions/unittests.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@ When generating unit tests for PyRIT components, follow these comprehensive guid
## Core Testing Requirements

### Database/Memory Isolation
- Always use `@pytest.mark.usefixtures("patch_central_database")` decorator on test classes that may interact with the Central Memory

For unit tests (in tests/unit):
- Always use `@pytest.mark.usefixtures("patch_central_database")` decorator on unit test classes that may interact with the Central Memory
- This ensures tests run in isolation without affecting the actual database

### Async Testing
- Use `@pytest.mark.asyncio` decorator for all async test methods
- Use `AsyncMock` instead of `MagicMock` when mocking async methods
- Properly await all async operations in tests


### Using Pre-Configured Settings

Check conftest and mocks.py to see if there are common utilities that can be reused across tests.

One common issue is setting the central database. Use the `patch_central_database` is a common solution.
Comment thread
rlundeen2 marked this conversation as resolved.


### Test Organization
- Group related tests into classes with descriptive names starting with `Test`
- Place tests in `tests/unit/[module]/test_[component].py`
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ doc/_autosummary/

# ignore all VSCode settings
.vscode/*
.vscode

# ignore jetbrains IDE settings
.idea/
Expand Down
4 changes: 4 additions & 0 deletions doc/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ chapters:
- file: code/memory/11_harm_categories
- file: code/memory/azure_embeddings
- file: code/memory/chat_message
- file: code/setup/0_configuration
sections:
- file: code/setup/default_values
- file: code/setup/pyrit_initializer
- file: code/auxiliary_attacks/0_auxiliary_attacks
sections:
- file: code/auxiliary_attacks/1_gcg_azure_ml
Expand Down
38 changes: 37 additions & 1 deletion doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,30 @@ API Reference
:nosignatures:
:toctree: _autosummary/

apply_defaults
apply_defaults_to_method
combine_dict
combine_list
convert_local_image_to_data_url
DefaultValueScope
deprecation_message
display_image_response
download_chunk
download_file
download_files
download_specific_files
get_available_files
get_global_default_values
get_httpx_client
get_kwarg_param
get_non_required_value
get_random_indices
get_required_value
initialize_pyrit
is_in_ipython_session
make_request_and_raise_if_error_async
print_chat_messages_with_color
reset_default_values
set_default_value
Singleton
warn_if_set
YamlLoadable
Expand Down Expand Up @@ -523,3 +528,34 @@ API Reference
TrueFalseQuestionPaths
TrueFalseScoreAggregator
TrueFalseScorer

:py:mod:`pyrit.setup`
=====================

.. automodule:: pyrit.setup
:no-members:
:no-inherited-members:

.. autosummary::
:nosignatures:
:toctree: _autosummary/

initialize_pyrit
AZURE_SQL
SQLITE
IN_MEMORY

:py:mod:`pyrit.setup.initializers`
==================================

.. automodule:: pyrit.setup.initializers
:no-members:
:no-inherited-members:

.. autosummary::
:nosignatures:
:toctree: _autosummary/

PyRITInitializer
AIRTInitializer
SimpleInitializer
4 changes: 2 additions & 2 deletions doc/code/auxiliary_attacks/0_auxiliary_attacks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@
}
],
"source": [
"from pyrit.common import IN_MEMORY, initialize_pyrit\n",
"from pyrit.executor.attack import (\n",
" AttackScoringConfig,\n",
" ConsoleAttackResultPrinter,\n",
" PromptSendingAttack,\n",
")\n",
"from pyrit.prompt_target import AzureMLChatTarget, OpenAIChatTarget\n",
"from pyrit.score import SelfAskRefusalScorer, TrueFalseInverterScorer\n",
"from pyrit.setup import IN_MEMORY, initialize_pyrit\n",
"\n",
"initialize_pyrit(memory_db_type=IN_MEMORY)\n",
"\n",
Expand Down Expand Up @@ -225,7 +225,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.11"
"version": "3.12.11"
}
},
"nbformat": 4,
Expand Down
3 changes: 2 additions & 1 deletion doc/code/auxiliary_attacks/0_auxiliary_attacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
# First, we send a harmful prompt to Phi-3-mini without a GCG suffix. If the environment variables `PHI3_MINI_ENDPOINT` and `PHI3_MINI_KEY` are not set in your .env file, the target will default to the model with `AZURE_ML_MANAGED_ENDPOINT` and `AZURE_ML_MANAGED_KEY`.

# %%
from pyrit.common import IN_MEMORY, initialize_pyrit

from pyrit.executor.attack import (
AttackScoringConfig,
ConsoleAttackResultPrinter,
PromptSendingAttack,
)
from pyrit.prompt_target import AzureMLChatTarget, OpenAIChatTarget
from pyrit.score import SelfAskRefusalScorer, TrueFalseInverterScorer
from pyrit.setup import IN_MEMORY, initialize_pyrit

initialize_pyrit(memory_db_type=IN_MEMORY)

Expand Down
2 changes: 1 addition & 1 deletion doc/code/converters/0_converters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@
}
],
"source": [
"from pyrit.common import IN_MEMORY, initialize_pyrit\n",
"from pyrit.prompt_converter import (\n",
" AsciiArtConverter,\n",
" BinaryConverter,\n",
" FirstLetterConverter,\n",
" RandomCapitalLettersConverter,\n",
" ROT13Converter,\n",
")\n",
"from pyrit.setup import IN_MEMORY, initialize_pyrit\n",
"\n",
"initialize_pyrit(memory_db_type=IN_MEMORY)\n",
"\n",
Expand Down
3 changes: 2 additions & 1 deletion doc/code/converters/0_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
# Converters can be used to perform these types of transformations. Here is a simple program that uses Rot13Converter converter, RandomCapitalLettersConverter, and AsciiArtConverter.

# %%
from pyrit.common import IN_MEMORY, initialize_pyrit

from pyrit.prompt_converter import (
AsciiArtConverter,
BinaryConverter,
FirstLetterConverter,
RandomCapitalLettersConverter,
ROT13Converter,
)
from pyrit.setup import IN_MEMORY, initialize_pyrit

initialize_pyrit(memory_db_type=IN_MEMORY)

Expand Down
2 changes: 1 addition & 1 deletion doc/code/converters/1_llm_converters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
"source": [
"import pathlib\n",
"\n",
"from pyrit.common import IN_MEMORY, initialize_pyrit\n",
"from pyrit.common.path import DATASETS_PATH\n",
"from pyrit.models import SeedPrompt\n",
"from pyrit.prompt_converter import VariationConverter\n",
"from pyrit.prompt_target import OpenAIChatTarget\n",
"from pyrit.setup import IN_MEMORY, initialize_pyrit\n",
"\n",
"initialize_pyrit(memory_db_type=IN_MEMORY)\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion doc/code/converters/1_llm_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
# %%
import pathlib

from pyrit.common import IN_MEMORY, initialize_pyrit
from pyrit.common.path import DATASETS_PATH
from pyrit.models import SeedPrompt
from pyrit.prompt_converter import VariationConverter
from pyrit.prompt_target import OpenAIChatTarget
from pyrit.setup import IN_MEMORY, initialize_pyrit

initialize_pyrit(memory_db_type=IN_MEMORY)

Expand Down
2 changes: 1 addition & 1 deletion doc/code/converters/2_using_converters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
}
],
"source": [
"from pyrit.common import IN_MEMORY, initialize_pyrit\n",
"from pyrit.executor.attack import (\n",
" AttackConverterConfig,\n",
" ConsoleAttackResultPrinter,\n",
Expand All @@ -67,6 +66,7 @@
"from pyrit.prompt_converter import StringJoinConverter, VariationConverter\n",
"from pyrit.prompt_normalizer import PromptConverterConfiguration\n",
"from pyrit.prompt_target import OpenAIChatTarget, TextTarget\n",
"from pyrit.setup import IN_MEMORY, initialize_pyrit\n",
"\n",
"initialize_pyrit(memory_db_type=IN_MEMORY)\n",
"\n",
Expand Down
4 changes: 3 additions & 1 deletion doc/code/converters/2_using_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
# "t-e-l-l- - m-e- -h-o-w- -t-o- -c-u-t- -d-o-w-n - a- -t-r-e-e"

# %%
from pyrit.common import IN_MEMORY, initialize_pyrit


from pyrit.executor.attack import (
AttackConverterConfig,
ConsoleAttackResultPrinter,
Expand All @@ -32,6 +33,7 @@
from pyrit.prompt_converter import StringJoinConverter, VariationConverter
from pyrit.prompt_normalizer import PromptConverterConfiguration
from pyrit.prompt_target import OpenAIChatTarget, TextTarget
from pyrit.setup import IN_MEMORY, initialize_pyrit

initialize_pyrit(memory_db_type=IN_MEMORY)

Expand Down
2 changes: 1 addition & 1 deletion doc/code/converters/3_audio_converters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"source": [
"import os\n",
"\n",
"from pyrit.common import IN_MEMORY, initialize_pyrit\n",
"from pyrit.prompt_converter import AzureSpeechTextToAudioConverter\n",
"from pyrit.setup import IN_MEMORY, initialize_pyrit\n",
"\n",
"initialize_pyrit(memory_db_type=IN_MEMORY)\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion doc/code/converters/3_audio_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# %%
import os

from pyrit.common import IN_MEMORY, initialize_pyrit
from pyrit.prompt_converter import AzureSpeechTextToAudioConverter
from pyrit.setup import IN_MEMORY, initialize_pyrit

initialize_pyrit(memory_db_type=IN_MEMORY)

Expand Down
2 changes: 1 addition & 1 deletion doc/code/converters/4_image_converters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
"from IPython.display import display\n",
"from PIL import Image\n",
"\n",
"from pyrit.common import IN_MEMORY, initialize_pyrit\n",
"from pyrit.datasets import TextJailBreak\n",
"from pyrit.prompt_converter import AddTextImageConverter\n",
"from pyrit.setup import IN_MEMORY, initialize_pyrit\n",
"\n",
"initialize_pyrit(memory_db_type=IN_MEMORY)\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion doc/code/converters/4_image_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from IPython.display import display
from PIL import Image

from pyrit.common import IN_MEMORY, initialize_pyrit
from pyrit.datasets import TextJailBreak
from pyrit.prompt_converter import AddTextImageConverter
from pyrit.setup import IN_MEMORY, initialize_pyrit

initialize_pyrit(memory_db_type=IN_MEMORY)

Expand Down
2 changes: 1 addition & 1 deletion doc/code/converters/5_selectively_converting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
}
],
"source": [
"from pyrit.common import IN_MEMORY, initialize_pyrit\n",
"from pyrit.executor.attack import (\n",
" AttackConverterConfig,\n",
" ConsoleAttackResultPrinter,\n",
Expand All @@ -60,6 +59,7 @@
"from pyrit.prompt_converter import Base64Converter\n",
"from pyrit.prompt_normalizer import PromptConverterConfiguration\n",
"from pyrit.prompt_target import TextTarget\n",
"from pyrit.setup import IN_MEMORY, initialize_pyrit\n",
"\n",
"initialize_pyrit(memory_db_type=IN_MEMORY)\n",
"\n",
Expand Down
4 changes: 2 additions & 2 deletions doc/code/converters/5_selectively_converting.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
# # 5. Selectively Converting
#
# You can selectively convert strings from text converters using most attacks or the `convert_tokens_async` function. This function uses a `start_token` and `end_token` to determine where to do the converting (by default these are the unicode characters ⟪ and ⟫). Here is an example that uses `PromptSendingAttack` to convert pieces of the text to base64.

# %%
from pyrit.common import IN_MEMORY, initialize_pyrit

from pyrit.executor.attack import (
AttackConverterConfig,
ConsoleAttackResultPrinter,
Expand All @@ -23,6 +22,7 @@
from pyrit.prompt_converter import Base64Converter
from pyrit.prompt_normalizer import PromptConverterConfiguration
from pyrit.prompt_target import TextTarget
from pyrit.setup import IN_MEMORY, initialize_pyrit

initialize_pyrit(memory_db_type=IN_MEMORY)

Expand Down
2 changes: 1 addition & 1 deletion doc/code/converters/6_human_converter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@
"import logging\n",
"from pathlib import Path\n",
"\n",
"from pyrit.common import IN_MEMORY, initialize_pyrit\n",
"from pyrit.executor.attack import (\n",
" AttackAdversarialConfig,\n",
" AttackConverterConfig,\n",
Expand All @@ -362,6 +361,7 @@
"from pyrit.prompt_normalizer import PromptConverterConfiguration\n",
"from pyrit.prompt_target import OpenAIChatTarget\n",
"from pyrit.score import SelfAskTrueFalseScorer\n",
"from pyrit.setup import IN_MEMORY, initialize_pyrit\n",
"\n",
"initialize_pyrit(memory_db_type=IN_MEMORY)\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion doc/code/converters/6_human_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import logging
from pathlib import Path

from pyrit.common import IN_MEMORY, initialize_pyrit
from pyrit.executor.attack import (
AttackAdversarialConfig,
AttackConverterConfig,
Expand All @@ -50,6 +49,7 @@
from pyrit.prompt_normalizer import PromptConverterConfiguration
from pyrit.prompt_target import OpenAIChatTarget
from pyrit.score import SelfAskTrueFalseScorer
from pyrit.setup import IN_MEMORY, initialize_pyrit

initialize_pyrit(memory_db_type=IN_MEMORY)

Expand Down
2 changes: 1 addition & 1 deletion doc/code/converters/7_video_converters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"source": [
"import pathlib\n",
"\n",
"from pyrit.common import IN_MEMORY, initialize_pyrit\n",
"from pyrit.prompt_converter import AddImageVideoConverter\n",
"from pyrit.setup import IN_MEMORY, initialize_pyrit\n",
"\n",
"initialize_pyrit(memory_db_type=IN_MEMORY)\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion doc/code/converters/7_video_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
# %%
import pathlib

from pyrit.common import IN_MEMORY, initialize_pyrit
from pyrit.prompt_converter import AddImageVideoConverter
from pyrit.setup import IN_MEMORY, initialize_pyrit

initialize_pyrit(memory_db_type=IN_MEMORY)

Expand Down
2 changes: 1 addition & 1 deletion doc/code/converters/ansi_attack_converter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@
}
],
"source": [
"from pyrit.common import IN_MEMORY, initialize_pyrit\n",
"from pyrit.executor.attack import (\n",
" AttackConverterConfig,\n",
" AttackExecutor,\n",
Expand All @@ -269,6 +268,7 @@
"from pyrit.prompt_converter import AnsiAttackConverter\n",
"from pyrit.prompt_normalizer import PromptConverterConfiguration\n",
"from pyrit.prompt_target import OpenAIChatTarget\n",
"from pyrit.setup import IN_MEMORY, initialize_pyrit\n",
"\n",
"initialize_pyrit(memory_db_type=IN_MEMORY)\n",
"\n",
Expand Down
Loading