API Reference#

pyrit.analytics#

ConversationAnalytics

Handles analytics operations on conversation data, such as finding similar chat messages based on conversation history or embedding similarity.

pyrit.auth#

Authenticator

AzureAuth

Azure CLI Authentication.

AzureStorageAuth

A utility class for Azure Storage authentication, providing methods to generate SAS tokens using user delegation keys.

pyrit.auxiliary_attacks#

pyrit.chat_message_normalizer#

ChatMessageNormalizer

ChatMessageNop

GenericSystemSquash

ChatMessageNormalizerChatML

ChatMessageNormalizerTokenizerTemplate

This class enables you to apply the chat template stored in a Hugging Face tokenizer to a list of chat messages.

pyrit.common#

combine_dict

Combines two dictionaries containing string keys and values into one.

combine_list

Combines two lists containing string keys, keeping only unique values.

display_image_response

Displays response images if running in notebook environment.

download_chunk

Download a chunk of the file with a specified byte range.

download_file

Download a file in multiple segments (splits) using byte-range requests.

download_files

Download multiple files with parallel downloads and segmented downloading.

download_specific_files

Downloads specific files from a Hugging Face model repository.

get_available_files

Fetches available files for a model from the Hugging Face repository.

get_httpx_client

Get the httpx client for making requests.

get_non_required_value

Gets a non-required value from an environment variable or a passed value, prefering the passed value.

get_required_value

Gets a required value from an environment variable or a passed value, prefering the passed value

initialize_pyrit

Initializes PyRIT with the provided memory instance and loads environment files.

is_in_ipython_session

Determines if the code is running in an IPython session.

make_request_and_raise_if_error_async

Make a request and raise an exception if it fails.

print_chat_messages_with_color

Print chat messages with color to console.

Singleton

A metaclass for creating singleton classes.

YamlLoadable

Abstract base class for objects that can be loaded from YAML files.

pyrit.datasets#

fetch_decoding_trust_stereotypes_dataset

Fetch DecodingTrust examples and create a SeedPromptDataset.

fetch_examples

Fetch examples from a specified source with caching support.

fetch_harmbench_dataset

Fetch HarmBench examples and create a SeedPromptDataset.

fetch_many_shot_jailbreaking_dataset

Fetch many-shot jailbreaking dataset from a specified source.

fetch_seclists_bias_testing_dataset

Fetch SecLists AI LLM Bias Testing examples from a specified source and create a SeedPromptDataset.

fetch_xstest_dataset

Fetch XSTest examples and create a SeedPromptDataset.

fetch_pku_safe_rlhf_dataset

Fetch PKU-SafeRLHF examples and create a SeedPromptDataset.

fetch_adv_bench_dataset

Fetch AdvBench examples and create a SeedPromptDataset.

fetch_wmdp_dataset

Fetch WMDP examples and create a QuestionAnsweringDataset.

fetch_forbidden_questions_dataset

Fetch Forbidden question dataset and return it as a SeedPromptDataset

fetch_llm_latent_adversarial_training_harmful_dataset

fetch_tdc23_redteaming_dataset

Fetch TDC23-RedTeaming examples and create a SeedPromptDataset.

pyrit.embedding#

pyrit.exceptions#

BadRequestException

Exception class for bad client requests.

EmptyResponseException

Exception class for empty response errors.

handle_bad_request_exception

InvalidJsonException

Exception class for blocked content errors.

MissingPromptPlaceholderException

Exception class for missing prompt placeholder errors.

PyritException

pyrit_json_retry

A decorator to apply retry logic with exponential backoff to a function.

pyrit_target_retry

A decorator to apply retry logic with exponential backoff to a function.

pyrit_placeholder_retry

A decorator to apply retry logic.

RateLimitException

Exception class for authentication errors.

remove_markdown_json

Checks if the response message is in JSON format and removes Markdown formatting if present.

pyrit.memory#

AzureSQLMemory

A class to manage conversation memory using Azure SQL Server as the backend database.

CentralMemory

Provides a centralized memory instance across the framework.

DuckDBMemory

A class to manage conversation memory using DuckDB as the backend database.

EmbeddingDataEntry

Represents the embedding data associated with conversation entries in the database.

MemoryInterface

Represents a conversation memory that stores chat messages.

MemoryEmbedding

The MemoryEmbedding class is responsible for encoding the memory embeddings.

MemoryExporter

Handles the export of data to various formats, currently supporting only JSON format.

PromptMemoryEntry

Represents the prompt data.

pyrit.models#

ALLOWED_CHAT_MESSAGE_ROLES

Built-in mutable sequence.

AudioPathDataTypeSerializer

AzureBlobStorageIO

Implementation of StorageIO for Azure Blob Storage.

ChatMessage

ChatMessagesDataset

Represents a dataset of chat messages.

ChatMessageRole

alias of Literal['system', 'user', 'assistant']

ChatMessageListDictContent

construct_response_from_request

Constructs a response entry from a request.

DataTypeSerializer

Abstract base class for data type normalizers.

data_serializer_factory

Factory method to create a DataTypeSerializer instance.

DiskStorageIO

Implementation of StorageIO for local disk storage.

EmbeddingData

EmbeddingResponse

EmbeddingSupport

EmbeddingUsageInformation

ErrorDataTypeSerializer

group_conversation_request_pieces_by_sequence

Groups prompt request pieces from the same conversation into PromptRequestResponses.

Identifier

ImagePathDataTypeSerializer

PromptRequestPiece

Represents a prompt request piece.

PromptResponse

PromptResponseError

alias of Literal['blocked', 'none', 'processing', 'empty', 'unknown']

PromptDataType

alias of Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'error']

PromptRequestResponse

Represents a response to a prompt request.

QuestionAnsweringDataset

Represents a dataset for question answering.

QuestionAnsweringEntry

Represents a question model.

QuestionChoice

Represents a choice for a question.

Score

ScoreType

alias of Literal['true_false', 'float_scale']

SeedPrompt

Represents a seed prompt with various attributes and metadata.

SeedPromptDataset

SeedPromptDataset manages seed prompts plus optional top-level defaults.

SeedPromptGroup

A group of prompts that need to be sent together.

StorageIO

Abstract interface for storage systems (local disk, Azure Storage Account, etc.).

TextDataTypeSerializer

UnvalidatedScore

Score is an object that validates all the fields.

pyrit.orchestrator#

CrescendoOrchestrator

The CrescendoOrchestrator class represents an orchestrator that executes the Crescendo attack.

FlipAttackOrchestrator

This orchestrator implements the Flip Attack method found here: https://arxiv.org/html/2410.02832v1.

FuzzerOrchestrator

MultiTurnAttackResult

The result of a multi-turn attack.

MultiTurnOrchestrator

The MultiTurnOrchestrator is an interface that coordinates attacks and conversations between a adversarial_chat target and an objective_target.

Orchestrator

PAIROrchestrator

This orchestrator implements the Prompt Automatic Iterative Refinement (PAIR) algorithm

PromptSendingOrchestrator

This orchestrator takes a set of prompts, converts them using the list of PromptConverters, sends them to a target, and scores the resonses with scorers (if provided).

RedTeamingOrchestrator

The RedTeamingOrchestrator class orchestrates a multi-turn red teaming attack on a target system.

ScoringOrchestrator

This orchestrator scores prompts in a parallelizable and convenient way.

SkeletonKeyOrchestrator

Creates an orchestrator that executes a skeleton key jailbreak.

TreeOfAttacksWithPruningOrchestrator

TreeOfAttacksWithPruningOrchestrator follows the TAP alogrithm to attack a chat target.

XPIAManualProcessingOrchestrator

XPIAOrchestrator

XPIATestOrchestrator

pyrit.prompt_converter#

AddImageTextConverter

Adds a string to an image and wraps the text into multiple lines if necessary.

AddTextImageConverter

Adds a string to an image and wraps the text into multiple lines if necessary.

AsciiArtConverter

Converts a string to ASCII art

AtbashConverter

Converter to encode prompt using atbash cipher.

AudioFrequencyConverter

The AudioFrequencyConverter takes an audio file and shifts its frequency, by default it will shift it above human range (=20kHz).

AzureSpeechAudioToTextConverter

The AzureSpeechAudioTextConverter takes a .wav file and transcribes it into text.

AzureSpeechTextToAudioConverter

The AzureSpeechTextToAudio takes a prompt and generates a wave file.

Base64Converter

CaesarConverter

Converter to encode prompt using caesar cipher.

CharacterSpaceConverter

CodeChameleonConverter

The CodeChameleon Converter uses a combination of personal encryption and decryption functions, code nesting, as well as a set of instructions for the response to bypass LLM safeguards.

ConverterResult

EmojiConverter

FlipConverter

FuzzerCrossOverConverter

Fuzzer converter that uses multiple prompt templates to generate new prompts.

FuzzerExpandConverter

FuzzerRephraseConverter

FuzzerShortenConverter

FuzzerSimilarConverter

HumanInTheLoopConverter

Allows review of each prompt sent to a target before sending it.

LeetspeakConverter

Converts a string to a leetspeak version

LLMGenericTextConverter

MaliciousQuestionGeneratorConverter

A PromptConverter that generates malicious questions using an LLM via an existing PromptTarget (like Azure OpenAI).

MathPromptConverter

A PromptConverter that converts natural language instructions into symbolic mathematics problems using an LLM via an existing PromptTarget (like Azure OpenAI or other supported backends).

MorseConverter

Converter to encode prompts using morse code.

NoiseConverter

PersuasionConverter

Converter to rephrase prompts using a variety of persuasion techniques.

PromptConverter

A prompt converter is responsible for converting prompts into a different representation.

QRCodeConverter

Converts a text string to a QR code image.

RandomCapitalLettersConverter

This converter takes a prompt and randomly capitalizes it by a percentage of the total characters.

RepeatTokenConverter

Repeat a specified token a specified number of times in addition to a given prompt.

ROT13Converter

SearchReplaceConverter

Converts a string by replacing chosen phrase with a new phrase of choice

StringJoinConverter

SuffixAppendConverter

TenseConverter

ToneConverter

TranslationConverter

UnicodeConfusableConverter

A PromptConverter that applies substitutions to words in the prompt to test adversarial textual robustness by replacing characters with visually similar ones.

UnicodeSubstitutionConverter

UrlConverter

VariationConverter

pyrit.prompt_normalizer#

PromptNormalizer

PromptConverterConfiguration

Represents the configuration for a prompt response converter.

NormalizerRequest

Represents a single request sent to normalizer.

pyrit.prompt_target#

AzureBlobStorageTarget

The AzureBlobStorageTarget takes prompts, saves the prompts to a file, and stores them as a blob in a provided storage account container.

AzureMLChatTarget

CrucibleTarget

GandalfLevel

GandalfTarget

HTTPTarget

HTTP_Target is for endpoints that do not have an API and instead require HTTP request(s) to send a prompt

HuggingFaceChatTarget

The HuggingFaceChatTarget interacts with HuggingFace models, specifically for conducting red teaming activities.

HuggingFaceEndpointTarget

The HuggingFaceEndpointTarget interacts with HuggingFace models hosted on cloud endpoints.

limit_requests_per_minute

A decorator to enforce rate limit of the target through setting requests per minute.

OllamaChatTarget

OpenAICompletionTarget

OpenAIDALLETarget

The Dalle3Target takes a prompt and generates images This class initializes a DALL-E image target

OpenAIChatTarget

This class facilitates multimodal (image and text) input and text output generation

OpenAITTSTarget

OpenAITarget

OllamaChatTarget

PromptChatTarget

A prompt chat target is a target where you can explicitly set the conversation history using memory.

PromptShieldTarget

PromptShield is an endpoint which detects the presence of a jailbreak.

PromptTarget

TextTarget

The TextTarget takes prompts, adds them to memory and writes them to io which is sys.stdout by default

pyrit.score#

AzureContentFilterScorer

ContentClassifierPaths

FloatScaleThresholdScorer

A scorer that applies a threshold to a float scale score to make it a true/false score.

GandalfScorer

HumanInTheLoopScorer

Create scores from manual human input and adds them to the database.

LikertScalePaths

MarkdownInjectionScorer

PromptShieldScorer

Returns true if an attack or jailbreak has been detected by Prompt Shield.

Scorer

Abstract base class for scorers.

SelfAskCategoryScorer

A class that represents a self-ask score for text classification and scoring.

SelfAskLikertScorer

A class that represents a "self-ask" score for text scoring for a likert scale.

SelfAskRefusalScorer

A self-ask scorer detects a refusal.

SelfAskScaleScorer

A class that represents a "self-ask" score for text scoring for a customizable numeric scale.

SelfAskTrueFalseScorer

A class that represents a self-ask true/false for scoring.

SubStringScorer

Scorer that checks if a given substring is present in the text.

TrueFalseInverterScorer

A scorer that inverts a true false score.

TrueFalseQuestion

A class that represents a true/false question.

TrueFalseQuestionPaths