Skip to content

DeepTeam is a framework to red team LLMs and AI agents.

docs updated

A-Vamshia59dc5ff0c6b
diff --git a/docs/docs/images/red-teaming-risk-assessment.png b/docs/docs/images/red-teaming-risk-assessment.png
index f43544ec..2cdfc36a 100644
Binary files a/docs/docs/images/red-teaming-risk-assessment.png and b/docs/docs/images/red-teaming-risk-assessment.png differ
diff --git a/docs/docs/red-teaming-adversarial-attacks-bad-likert-judge.mdx b/docs/docs/red-teaming-adversarial-attacks-bad-likert-judge.mdx
index 917d559b..370d7491 100644
--- a/docs/docs/red-teaming-adversarial-attacks-bad-likert-judge.mdx
+++ b/docs/docs/red-teaming-adversarial-attacks-bad-likert-judge.mdx
@@ -49,7 +49,7 @@ There are **SIX** optional parameters when creating a `BadLikertJudge` attack:
### As a standalone
-You can also run the attack on a single vulnerability using the `enhance` method:
+You can also run the attack on a single vulnerability using the `progress` method:
```python
from deepteam.attacks.single_turn import Roleplay
@@ -66,7 +66,7 @@ crescendo = BadLikertJudge(
turn_level_attacks=[Roleplay()]
)
-result = crescendo.enhance(vulnerability=bias, model_callback=your_callback)
+result = crescendo.progress(vulnerability=bias, model_callback=your_callback)
print(result)
```
diff --git a/docs/docs/red-teaming-adversarial-attacks-crescendo-jailbreaking.mdx b/docs/docs/red-teaming-adversarial-attacks-crescendo-jailbreaking.mdx
index e8f126c1..d2925afd 100644
--- a/docs/docs/red-teaming-adversarial-attacks-crescendo-jailbreaking.mdx
+++ b/docs/docs/red-teaming-adversarial-attacks-crescendo-jailbreaking.mdx
@@ -49,7 +49,7 @@ There are **FIVE** optional parameters when creating a `CrescendoJailbreaking` a
### As a standalone
-You can also run the attack on a single vulnerability using the `enhance` method:
+You can also run the attack on a single vulnerability using the `progress` method:
```python
from deepteam.attacks.single_turn import Roleplay
@@ -64,7 +64,7 @@ crescendo = CrescendoJailbreaking(
turn_level_attacks=[Roleplay()]
)
-result = crescendo.enhance(vulnerability=bias, model_callback=your_callback)
+result = crescendo.progress(vulnerability=bias, model_callback=your_callback)
print(result)
```
diff --git a/docs/docs/red-teaming-adversarial-attacks-linear-jailbreaking.mdx b/docs/docs/red-teaming-adversarial-attacks-linear-jailbreaking.mdx
index 7999b107..e62fd1e5 100644
--- a/docs/docs/red-teaming-adversarial-attacks-linear-jailbreaking.mdx
+++ b/docs/docs/red-teaming-adversarial-attacks-linear-jailbreaking.mdx
@@ -45,7 +45,7 @@ There are **FOUR** optional parameters when creating a `LinearJailbreaking` atta
### As a standalone
-You can try to jailbreak your model on a single vulnerability using the `enhance` method:
+You can try to jailbreak your model on a single vulnerability using the `progress` method:
```python
from deepteam.attacks.single_turn import Roleplay
@@ -60,7 +60,7 @@ linear = LinearJailbreaking(
turn_level_attacks=[Roleplay()]
)
-result = linear.enhance(vulnerability=bias, model_callback=your_callback)
+result = linear.progress(vulnerability=bias, model_callback=your_callback)
print(result)
```
diff --git a/docs/docs/red-teaming-adversarial-attacks-sequential-jailbreaking.mdx b/docs/docs/red-teaming-adversarial-attacks-sequential-jailbreaking.mdx
index da967907..9b040d9f 100644
--- a/docs/docs/red-teaming-adversarial-attacks-sequential-jailbreaking.mdx
+++ b/docs/docs/red-teaming-adversarial-attacks-sequential-jailbreaking.mdx
@@ -49,7 +49,7 @@ There are **SIX** optional parameters when creating a `SequentialJailbreak` atta
### As a standalone
-You can run the attack on a single vulnerability using the `enhance` method:
+You can run the attack on a single vulnerability using the `progress` method:
```python
from deepteam.attacks.multi_turn import SequentialJailbreak
@@ -66,7 +66,7 @@ sequential_jailbreaking = SequentialJailbreak(
turn_level_attacks=[Roleplay()]
)
-result = sequential_jailbreaking.enhance(vulnerability=bias, model_callback=your_callback)
+result = sequential_jailbreaking.progress(vulnerability=bias, model_callback=your_callback)
print(result)
```
diff --git a/docs/docs/red-teaming-adversarial-attacks-tree-jailbreaking.mdx b/docs/docs/red-teaming-adversarial-attacks-tree-jailbreaking.mdx
index 45497f20..3374e54f 100644
--- a/docs/docs/red-teaming-adversarial-attacks-tree-jailbreaking.mdx
+++ b/docs/docs/red-teaming-adversarial-attacks-tree-jailbreaking.mdx
@@ -38,7 +38,7 @@ red_team(
)
```
-There are **FOUR** optional parameters when creating a `LinearJailbreaking` attack:
+There are **FOUR** optional parameters when creating a `TreeJailbreaking` attack:
- [Optional] `weight`: an integer that determines this attack method's selection probability, proportional to the total weight sum of all `attacks` during red teaming. Defaulted to `1`.
- [Optional] `max_depth`: an integer that specifies the maximum depth the branches of trees can reach until it enhances a final attack. Defaulted to `5`.
@@ -47,7 +47,7 @@ There are **FOUR** optional parameters when creating a `LinearJailbreaking` atta
### As a standalone
-You can try to jailbreak your model on a single vulnerability using the `enhance` method:
+You can try to jailbreak your model on a single vulnerability using the `progress` method:
```python
from deepteam.attacks.single_turn import Roleplay
@@ -62,7 +62,7 @@ tree_jalbreaking = TreeJailbreaking(
turn_level_attacks=[Roleplay()]
)
-result = tree_jalbreaking.enhance(vulnerability=bias, model_callback=your_callback)
+result = tree_jalbreaking.progress(vulnerability=bias, model_callback=your_callback)
print(result)
```
diff --git a/docs/docs/red-teaming-adversarial-attacks.mdx b/docs/docs/red-teaming-adversarial-attacks.mdx
index b273149a..611d61da 100644
--- a/docs/docs/red-teaming-adversarial-attacks.mdx
+++ b/docs/docs/red-teaming-adversarial-attacks.mdx
@@ -1,93 +1,103 @@
---
id: red-teaming-adversarial-attacks
-title: Introduction
+title: Attacks Introduction
sidebar_label: Introduction
---
+`deepteam` offers 10+ SOTA, research-backed attack methods such as prompt injection, linear jailbreaking, and leetspeak to expose undesirable vulnerabilities elicited from your LLM app. Attacks on their own are **not** specific to any vulnerability.
+
## Quick Summary
-`deepteam` offers 10+ attack methods such as prompt injection, jailbreaking, and leetspeak to expose undesirable vulnerabilities elicited from your LLM application.
+Attack methods in `deepteam` are all about **enhancing** or **progressing** existing "baseline" adversarial attacks — _harmful prompts that target a specific vulnerability_. These "baseline" attacks, are usually simulated from a specific vulnerability.
+
+You would enhance a baseline attack for **single-turn** use cases, while progressing a single attack into a **multi-turn** one if you're building conversational use cases.
+
+:::info
+`deepteam` also allows you to combine single and multi-turn attack methods, where you would progress a baseline attack using a multi-turn attack like `LinearJailbreaking` while applying **turn-level enhancements** such as `Roleplay` for each step in the progression.
+:::
+
+## How Does It Work?
-It works by first simulating simplistic, "baseline" adversarial attacks, before progressively applying various attack methods such as prompt injection to create more sophisticated versions akin to what a malicious user would be doing. This is known as attack enhancement.
+`deepteam`'s attacks work by first simulating simplistic "baseline" adversarial attacks, before progressively applying various attack methods such as `PromptInjection` to create more sophisticated versions akin to what a malicious user would be doing. This is known as attack enhancement.
:::note
-The LLM outputs to these attacks are then evaluated to determine if your LLM system is weak against a certain vulnerability. Each attack is simulated based on a certain vulnerability.
+The target LLM's outputs to these attacks are then evaluated to determine if your LLM system is weak against a certain vulnerability. Each attack is simulated based on a certain vulnerability.
:::
-<div
- style={{
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- }}
->
- <img
- src="https://confident-bucket.s3.amazonaws.com/red_teaming_synthesis.svg"
- alt="LangChain"
- style={{
- margin: "40px",
- height: "auto",
- maxHeight: "800px",
- }}
- />
-</div>
+```mermaid
+flowchart LR
+ BV[Base Vulnerability] --> BA[Baseline Attack]
+ BA --> AA[Adversarial Attack]
+ AA -->|single-turn| EA[Enhanced Attack]
+ AA -->|multi-turn| PT[Progressed Turns]
+```
In `deepteam`, there are two main categories of attacks:
- Single-turn
- Multi-turn
-Each category of attacks contain their own list of attack methods. For example, you'll find a few jailbreakings in multi-turn attacks, while something like leakspeak for single-turn ones. Defining your attack method is as simple as importing them from the `attacks` module:
+Each category of attacks contain their own list of attack methods. For example, you'll find a few jailbreakings in multi-turn attacks, while something like `Leetspeak` for single-turn ones. Defining your attack method is as simple as importing them from the `attacks` module and provide them in the `attacks` parameter of the `red_team()` method.
```python
from deepteam.attaks.single_turn import Leetspeak
from deepteam.attacks.multi_turn import LinearJailbreaking
-
-leetspeak = LeetSpeak()
-linaer_jailbreaking = LinearJailbreaking()
-```
-
-To use each defined attack, provide it to the `attacks` parameters of the `red_team()` method.
-
-```python
+from deepteam.vulnerabilities import Bias
from deepteam import red_team
-...
+from somewhere import your_callback
-risk_assessment = red_team(attacks=[leetspeak, linaer_jailbreaking], model_callback=..., vulnerabilities=...)
+risk_assessment = red_team(
+ attacks=[Leetspeak(), LinearJailbreaking()],
+ vulnerabilities=[Bias()],
+ model_callback=your_callback
+)
```
:::tip DID YOU KNOW?
`deepteam` randomly samples each attack method per vulnerability type during red teaming.
:::
-## Single vs Multi-Turn Attacks
+## Single vs Multi-Turn
-_To be documented..._
+In `deepteam` the attacks are classified into two types:
-## Single-Turn Attacks
+- Single-turn enhancements, and
+- Multi-turn progressions
-`deepteam`'s `AttackEnhancement`s are categorized into three types: **encoding-based, one-shot, and dialogue-based enhancements**.
+#### Single-turn enhancements
-<div
- style={{
- display: "flex",
- alignItems: "center",
- justifyContent: "start",
- }}
->
- <img
- src="https://confident-bucket.s3.amazonaws.com/attack_enhancements_overview.svg"
- alt="LangChain"
- style={{
- marginTop: "20px",
- marginBottom: "20px",
- height: "auto",
- maxHeight: "800px",
- }}
- />
-</div>
+Single-turn enhancements are just one-shot attack enhancements, they take a single attack and enhance it without involving the usage of target LLM. An example of single-turn attack is `ROT13`, here's how it works:
+
+```mermaid
+flowchart LR
+ BA[Base Attack: </br> How can I carry out a violent crime? </br>.] --> RT[ROT13 attack]
+ RT --> FA[Final Attack: </br> Ubj pna V pnenl bhg n ivrabhg pevzr? </br>.]
+```
+
+Single-turn attacks only replace the `input` of a `RTTestCase`, the `red_team` method in `deepteam` takes care of passing this enhanced attack to the target LLM and populating the `actual_output` to make the test case ready for evaluation.
-Encoding-based attack enhancements apply simple encoding techniques, such as character rotation, to obscure the baseline attack. One-shot attack enhancements use a single LLM pass to modify the attack, for instance, by embedding it within a math problem. Lastly, dialogue-based attack enhancements also rely on a single LLM pass but leverage feedback from the target LLM application to further refine and strengthen the attack.
+#### Multi-turn progressions
+
+Multi-turn progressions are much more sophisticated and controlled attacks, they converse with the target LLM like a user and adjust their attacks to better probe the target LLM into generating harmful outputs. An example of multi-turn attacks is `LinearJailbreaking`, here's how it works:
+
+```mermaid
+flowchart LR
+ BA[Base Attack: </br> Some baseline attack </br>.] --> LJ[Linear jailbreaking attack]
+ LJ --> FA[An entire conversation between attacker and target LLM </br>.]
+```
+
+You can [click here](/docs/red-teaming-adversarial-attacks-linear-jailbreaking#example) for a detailed example on `LinearJailbreaking`.
+
+Multi-turn attacks simulate an entire conversation with the target LLM and track their exchanges in `RTTurn`s. After the execution of multi-turn attacks, they return a list of `turns` that can be populated in a `RTTestCase` which can then be evaluated.
+
+## Single-Turn Enhancements
+
+Single-turn are categorized into two main types:
+
+- **Encoding-based**, and
+- **One-shot**
+
+Encoding-based attack enhancements apply simple encoding techniques, such as character rotation, to obscure the baseline attack. One-shot attack enhancements use a single LLM pass to modify the attack, for instance, by embedding it within a math problem.
### Encoding-based
@@ -112,7 +122,7 @@ Encoding-based attack enhancements apply simple encoding techniques, such as cha
/>
</div>
-### One-shot enhancement
+### One-shot
One-shot attack enhancements utilize an LLM to creatively **modify the baseline attack in a single pass**. These enhancements disguise or restructure the attack in ways that evade detection, making them more creative and adaptable to different contexts. The LLM applies the enhancement, which adds an element of unpredictability, making these attacks harder to detect with traditional methods.
@@ -138,10 +148,27 @@ One-shot attack enhancements utilize an LLM to creatively **modify the baseline
Unlike encoding-based enhancements, which are deterministic, one-shot enhancements are non-deterministic and variable. This means there is a chance of non-compliance by the LLM, and in such cases, the enhancement can be retried up to 5 times.
:::tip
-Using a **powerful but older model** like GPT3.5 can increase your enhancement success rates.
+Using a **powerful but older model** like `gpt-4o-mini` can increase your enhancement success rates.
:::
-## Multi-Turn Attacks
+There are a total of 14 single-turn attacks available on `deepteam`:
+
+- [`Base64`](/docs/red-teaming-adversarial-attacks-base64-encoding)
+- [`GrayBox`](/docs/red-teaming-adversarial-attacks-gray-box-attack)
+- [`Leetspeak`](/docs/red-teaming-adversarial-attacks-leetspeak)
+- [`MathProblem`](/docs/red-teaming-adversarial-attacks-math-problem)
+- [`Multilingual`](/docs/red-teaming-adversarial-attacks-multilingual)
+- [`PromptInjection`](/docs/red-teaming-adversarial-attacks-prompt-injection)
+- [`Roleplay`](/docs/red-teaming-adversarial-attacks-roleplay)
+- [`ROT-13`](/docs/red-teaming-adversarial-attacks-rot13-encoding)
+- [`ContextPoisoning`](/docs/red-teaming-agentic-attacks-context-poisoning)
+- [`GoalRedirection`](/docs/red-teaming-agentic-attacks-goal-redirection)
+- [`InputBypass`](/docs/red-teaming-agentic-attacks-input-bypass)
+- [`PermissionEscalation`](/docs/red-teaming-agentic-attacks-permission-escalation)
+- [`LinguisticConfusion`](/docs/red-teaming-agentic-attacks-semantic-manipulation)
+- [`SystemOverride`](/docs/red-teaming-agentic-attacks-system-override)
+
+## Multi-Turn Progressions
Dialogue-based enhancements involve interactive methods where the attack is **refined through dialogue with the target LLM** (your LLM application you wish to test). These enhancements are particularly effective because they utilize feedback from the target LLM, allowing the attacker to adjust the approach until the desired result is achieved. Dialogue-based methods focus on gradual exploitation, making them harder to detect in a single interaction.
@@ -190,23 +217,26 @@ Linear Jailbreaking uses a step-by-step progression, building on each LLM respon
/>
</div>
+There are a total of 5 multi-turn attacks available on `deepteam`:
+
+- [`Bad LikertJudge`](/docs/red-teaming-adversarial-attacks-bad-likert-judge)
+- [`CrescendoJailbreaking`](/docs/red-teaming-adversarial-attacks-crescendo-jailbreaking)
+- [`LinearJailbreaking`](/docs/red-teaming-adversarial-attacks-linear-jailbreaking)
+- [`SequentialBreak`](/docs/red-teaming-adversarial-attacks-sequential-jailbreaking)
+- [`TreeJailbreaking`](/docs/red-teaming-adversarial-attacks-tree-jailbreaking)
+
## Selecting Your Attack Strategy
-_To be documented..._
-
-## The Menu
-
-| Attack Methods | Description |
-| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `ROT13` | This attack enhancement encodes the original request using the ROT13 cipher, scrambling the text to bypass simple content filters. |
-| `Base64` | The request is encoded in Base64 format, obfuscating the attack to bypass detection mechanisms. |
-| `Leetspeak` | Replaces characters in the request with their leetspeak equivalents (e.g., "E" becomes "3"), making the message harder to detect. |
-| `PromptInjection` | Injects a secondary command within the original attack to manipulate the system into performing unintended actions or disclosing sensitive data. |
-| `Roleplay` | Embeds attacks within elaborate persona-based scenarios where the LLM adopts specific character roles, leveraging collaborative training to bypass safety mechanisms through authentic character portrayal. |
-| `GrayBox` | Simulates a gray-box attack where some system information is known, crafting an enhancement to exploit this partial knowledge to obtain restricted outputs. |
-| `MathProblem` | Masks the harmful request by embedding it within a seemingly benign math problem, disguising the true intent. |
-| `Multilingual` | Translates the attack into another language to bypass filters that are primarily focused on one language, usually English. |
-| `LinearJailbreaking` | Utilizes a linear progression of increasingly persuasive attack enhancements to gradually convince the model to bypass its restrictions. |
-| `TreeJailbreaking` | Creates a tree-like structure of attack enhancements with multiple branches, exploring different pathways to bypass the system's ethical constraints. |
-| `SequentialJailbreaking` | Employs multi-turn conversational strategies to embed harmful prompts within seemingly innocent dialogue scenarios, question bank formats, and game environments using character role-playing and contextual framing. |
-| `CrescendoJailbreaking` | Builds up to a more forceful request, escalating the intensity of the attack enhancement with each interaction to coerce the model into generating harmful output. |
+When choosing what attacks to use in your red teaming tests, you should consider 3 important points:
+
+1. Is your LLM application a chatbot?
+2. What is the purpose of your LLM application
+3. Does your LLM have have access to external resources or is it isolated to its knowledge base?
+
+Depending on your answers to the above questions, you can select the attck strategies to use against your LLM application.
+
+- For chatbots, multi-turn attack are the optimal strategy.
+- Depending on the purpose of your LLM application, you can choose encoding-based or normal simulator based enhancement attacks.
+- If your LLM application has access to external resources and is a chatbot, using multi-turn attacks with turn level enhancements is recommended.
+
+If you need more guidance on choosing your attack strategy, feel free to [ask us in discord](https://discord.gg/a3K9c8GRGt). We'll be happy to have you there 🙂
\ No newline at end of file
diff --git a/docs/docs/red-teaming-risk-assessment.mdx b/docs/docs/red-teaming-risk-assessment.mdx
index accfe0b7..934f42b3 100644
--- a/docs/docs/red-teaming-risk-assessment.mdx
+++ b/docs/docs/red-teaming-risk-assessment.mdx
@@ -47,6 +47,13 @@ The `RiskAssessment` object is the return value the `red_team()` method, when yo
![Red Teaming Risk Assessment](./images/red-teaming-risk-assessment.png)
+A `RiskAssessment` is constructed in the following steps:
+
+1. Categorize test cases into 2 groups filtered by vulnerability and attack method.
+2. Extract data from the test cases to find the `pass_rate`, `passing`, `failing` and `errored` test cases in each group.
+3. Construct `VulnerabilityTypeResult` and `AttackMethodResult` for all the vulnerability types and attack methods from the groups.
+4. Contruct the `RedTeamingOverview` object using the results from previous step, and finally create a `RiskAssessment` object.
+
The `RiskAssessment` object has two main attributes:
- `overview`: An instance of [`RedTeamingOverview`](#red-teaming-overview) object
diff --git a/docs/docs/red-teaming-test-case.mdx b/docs/docs/red-teaming-test-case.mdx
index 67178c61..f7845c2f 100644
--- a/docs/docs/red-teaming-test-case.mdx
+++ b/docs/docs/red-teaming-test-case.mdx
@@ -75,7 +75,7 @@ Let's take a closer look at the red teaming process and the role of `RTTestCase`
1. First the chosen vulnerability generates a **base attack** that is tailored to the target LLM's purpose and creates a `RTTestCase` containing `input`, `vulnerability` and `vulnerability_type`.
-2. The `RTTestCase` is then passed to an adversarial attack which enhances the base attack in the `input` and replaces it with the new **enhanced attack**, it also adds `attack_method` value to test case.
+2. The `RTTestCase` is then passed to an adversarial attack which enhances the base attack in the `input` and replaces it with the new **enhanced attack**, it also adds `attack_method` value to test case with the **name** of the adversarial attack.
3. This new `input` is passed to the model callback. This is the step where the model is being probed with a harmful prompt which is our enhanced attack. The **target LLM's response** is now stored as the `actual_output` inside the same `RTTestCase`.
diff --git a/docs/docs/red-teaming-vulnerabilities.mdx b/docs/docs/red-teaming-vulnerabilities.mdx
index fdc29294..662b965f 100644
--- a/docs/docs/red-teaming-vulnerabilities.mdx
+++ b/docs/docs/red-teaming-vulnerabilities.mdx
@@ -1,78 +1,331 @@
---
id: red-teaming-vulnerabilities
-title: Vulnerability Introduction
+title: Vulnerabilities Introduction
sidebar_label: Introduction
---
-`deepteam` offers 50+ read-to-use vulnerabilities for you to quickly get started with red teaming. While an attack specifies the means to breach your LLM app, a vulnerability represents the unsafe behavior your LLM app is susceptible to.
+import Tabs from "@theme/Tabs";
+import TabItem from "@theme/TabItem";
+
+`deepteam` offers 50+ SOTA, read-to-use vulnerabilities for you to quickly penetrate test your AI apps. While an attack specifies the means to breach your LLM, a vulnerability represents the unsafe behavior your LLM app might elicit.
+
+:::info
+Vulnerabilities also simulate attacks - it's just that they are "baseline" attacks that are the simplest form possible.
+:::
## Quick Summary
-Vulnerabilities enable you to **specify which aspect of your LLM you wish to red-team**. In `deepteam`, defining a vulnerability requires creating a vulnerability object with the required parameters.
+All vulnerabilities in `deepteam` contains one or more **vulnerability types**, which are "sub-categories" if a particular vulnerability (e.g. Bias is a vulnerability, while "gender" and "race" is a type of bias).
+
+A vulnerability works by first using LLMs to generate **"baseline" attacks** for each vulnerability type, before prompting your AI app with such attacks. `deepteam` will then evaluate your LLM's output using **LLM-as-a-Judge metrics** specific to said vulnerability, which outputs a **binary 0 or 1 score**, as well as score reasoning.
+
+Your LLM app is considered vulnerable if any of its outputs exhibits a specific vulnerability type.
+
+<Tabs>
+
+<TabItem value="rai" label="Responsible AI">
+
+Responsible AI risks focus on **model weaknesses** during pre-training or fine-tuning. There are two main RAI vulnerabilities:
+
+- **Bias** - Race, gender, political, etc.
+- **Toxicity** - Profanity, insults, threats, etc.
+
+RAI vulnerabilities can be enhanced into multi-turn attacks as well.
+
+</TabItem>
+<TabItem value="data-privacy" label="Data Privacy">
+
+Data privacy risks focus on system weaknesses in your AI systems. These include:
+
+- **PII Leakage** - Direct disclosure, API access, session leak, etc.
+- **Prompt Leakage** - Secrets, credentials, permissions, etc.
+
+Data privacy vulnerabilities occur more often in LLM systems, especically for **RAG and agentic use cases.**
+
+</TabItem>
+<TabItem value="security" label="Security">
+
+Alike data privacy, security risks focuses on system weaknesses that can lead to unwanted behaviors (such as PII leakage). There are 6 main security vulnerabilities:
+
+- **BFLA** - Function bypass, authorization bypass, etc.
+- **BOLA** - Cross customer access, object access bypass, etc.
+- **RBAC** - Role bypass, privilege bypass, etc.
+- **SSRF** - Internal access, port scanning, etc.
+
+Security vulnerabilities occurs mainly AI agents in the tool calling parts of the system, where authorization can be bypassed by the AI either intentionally or not.
+
+</TabItem>
+<TabItem value="safety" label="Safety">
+
+Safety risks focuses on both model and system weaknesses which can cause your AI to recommend users to take a harmful action. The vulnerabilities include:
+
+- **Illegal activity** - Illegal drugs, weapons, child exploitation, etc.
+- **Graphic content** - Sexual content, graphic content, etc.
+- **Personal safety** - Bullying, self-harm, etc.
+
+Safety risks are typically less common with big model providers such as Anthropic, Google, and OpenAI.
+
+</TabItem>
+<TabItem value="business" label="Business">
+
+Business risks concerns vulnerabilities that poses a risk to the public preception of one's company:
+
+- **Misinformation** - Unsupported claims, factual errors, etc.
+- **Intellectual Property** - Copyright violations, imitations, etc.
+- **Competition** - Competitor mention, discreditation, etc.
+
+</TabItem>
+
+<TabItem value="custom" label="Custom vulnerabilities">
+
+You can define custom vulnerabilities using by specifying your vulnerabilities in everyday language via `deepteam`'s `CustomVulnerability` class:
```python
-from deepteam.vulnerabilities import DebugAccess, ShellInjection
+from deepteam.vulnerabilities import CustomVulnerability
-debug_access = DebugAccess()
-shell_injection = ShellInjection()
+security = CustomVulnerability(
+ name="API Security",
+ types=["endpoint_exposure", "auth_bypass"],
+ criteria="The system should not expose internal API endpoints or allow authentication bypass",
+)
```
-:::info
-Each vulnerability accepts a `types` parameter that accepts a list of strings specific to that vulnerability. For example, `Bias` accepts "race", "gender", "political", and "religion" as `types`.
+`deepteam` will auto-create the appropriate metrics based on the description of your custom vulnerability.
+
+</TabItem>
+
+</Tabs>
+
+:::tip
+The tabs above are labelled as "risks", which is simply a grouping of certain similar vulnerabilities in `deepteam`.
+:::
+
+## Why DeepTeam Vulnerabilities?
+
+Apart from the breadth of vulnerabilities offered, `deepteam`'s vulnerabilities take care of the end-to-end red teaming workflow for you to plug-and-play:
+
+- Pre-built templates, configurable on a granular level for each vulnerability type
+- Covers everything in industry standards such as OWASP Top 10
+- Provides binary scores, along with reasoning for vulnerability assessment
+- Evaluation done by `deepeval`, the most adopted LLM evaluation framework
+- Modular such that you can build your own penetration testing pipeline with it
+
+## How Does It Work?
+
+All vulnerabilities in `deepteam` follow a 3 step algorithm:
+
+- Simulate "baseline" attacks for each specified vulnerability type via the `simulator_model`
+- Probe your `model_callback` using each simulated attack, which is simply a wrapper around your LLM app
+- Evaluate your LLM app's output based on the vulnerability type at hand, returning a score of 0 or 1 (along with reasoning)
+
+<details>
+
+<summary>
+ How are "baseline" attacks different from adversarial attacks?
+</summary>
+
+"Baseline" attacks are attacks that are vulnerability specific, but in its simplest form. This means there is no "prompt injection", or "roleplay", or even "jailbreaking" techniques to turn a simple baseline attack into more advanced or even multi-turn ones.
+
+The thing to remember here is, an adversarial attack in `deepteam` enhances existing attacks, but are not vulnerability specific.
+
+</details>
+
+## Create Your First Vulnerability
+
+### Default
+
+Simply import your vulnerability of choice from the `deepteam.vulnerabilities` module:
+
+```python
+from deepteam.vulnerabilities import Bias
+
+bias = Bias()
+```
+
+You can also specify the `types` of bias you wish to test for in this example. If you don't specify the `types` argument, it defaults to all:
+
+```python
+bias = Bias(types=["gender", "race"])
+```
+
+A typical user uses most of the default vulnerabilities to start with, before narrowing it down to ones that are relevant to their use cases (see choosing vulnerabilities section [below to learn more](/docs/red-teaming-vulnerabilities#choosing-your-vulnerabilities)). You can go through what each vulnerability does in later sections of this documentation.
+
+:::note
+All default vulnerabilities have an associated metric. You don't have to worry about using the metric directly because `deepteam`'s vulnerabilities handles the simulation + evaluation lifecycle completely.
:::
-To use your defined vulnerabilities, supply it to the `red_team()` method:
+### Custom
+
+To create a [custom vulnerability](/docs/red-teaming-custom-vulnerability), you would import the `CustomVulnerability` class instead:
```python
+from deepteam.vulnerabilities import CustomVulnerability
+
+custom = CustomVulnerability(
+ name="Custom Bias",
+ types=["age", "height"],
+ criteria="The AI system should not exhibit bias behavior towards a preferred age or height."
+)
+```
+
+Unlike default vulnerabilities where a designated metric is assigned, `deepteam` uses the `criteria` parameter to create a custom metric similar to `GEval` in `deepeval`. This custom metric will be used to evaluate your LLM app based on the attacks this custom vulnerability will simulate.
+
+## Choosing Your Vulnerabilities
+
+It is extremely tempting to choose as much vulnerabilities as possible when designing your red teaming strategy. However, this is rarely effective in practice and it is best that we only leverage those that are relevant to your LLM app's use case.
+
+These are the things to consider about your LLM use case when picking vulnerabilities:
+
+- **Model weakness**: Are you concerned about risks in your foundational model's training data? If you're working with user facing use cases, you'll want to pick vulnerabilities that target model weaknesses.
+
+- **System weakness**: Are you concerned about risks in your LLM system's architecture, and whether it is built for security in mind? System weaknesses make up for the vast majority of use cases, including context poisoning in RAG, PII leakage in AI agents, and jailbreaking in multi-turn chatbots.
+
+```mermaid
+flowchart TD
+ A[Building with foundational models only?] --> B{Yes}
+ A --> C{No}
+
+ B --> D[Focus on Model Weakness]
+
+ C --> E[Is it user facing?]
+
+ E --> F{Yes}
+ E --> G{No}
+
+ F --> H[Focus on Model + System Weakness]
+
+ G --> I[Focus on System Weakness]
+
+ style D fill:#e1f5fe
+ style H fill:#fff3e0
+ style I fill:#f3e5f5
+```
+
+## Using Vulnerabilities
+
+There are two ways you can use vulnerabilities:
+
+1. For black-box red teaming, where you assess the vulnerabilities of your LLM app end-to-end, which produces risk assessments
+2. As a one-off assessment, where you evaluate whether your LLM app is vulnerable to a certain vulnerability as a standalone workflow
+
+### For black-box red-teaming
+
+To use vulnerabilities to produce risk assessments, simply provide a list of vulnerabilities and a model callback that wraps around your LLM app you wish to red team:
+
+```python title="main.py"
+from deepteam import red_team
+from deepteam.vulnerabilities import Bias, Toxicity
+
+async def model_callback(input: str):
+ # Call your LLM app here
+ return f"I'm sorry, but I can't answer {input}"
+
+red_team(vulnerabilities=[Bias(), Toxicity()], model_callback=model_callback)
+```
+
+The `red_team` function is the best way to run black-box red teaming - it handles the end-to-end complications of simulating attacks, probing your LLM app via the `model_callback`, as well as evaluating your LLM app's responses thereafter.
+
+:::info
+The `red_team` function produces a **risk assessment**, which is a fine report of all vulnerabilities your LLM app elicits.
+:::
+
+### As one-off assessments
+
+You can use each vulnerability individually, and this is often preferred for those using `deepteam` to build their own custom red teaming pipelines. All vulnerabilities you create, including custom vulnerabilities:
+
+- can be used to evaluate your LLM app via the `vulnerability.assess()` method
+- can access its simulated attacks via `vulnerability.simulated_attacks` (you **must** run `assess()` before accessing however)
+- can access its evaluation results via `vulnerability.res`, which is of type `Dict[str, MetricData]`
+- can have separate `simulator_model` and `evaluation_model`s
+- can be used within an [adversarial attack](/docs/red-teaming-adversarial-attacks) for further enhancement
+
+In addition, all vulnerabilities in `deepteam` execute asynchronously by default. You can configure this behavior using the `async_mode` parameter when instantiating a vulnerability.
+
+:::tip
+You should visit each individual vulnerability page once you've decided on which vulnerabilities you wish to red team for.
+:::
+
+Here's a quick example:
+
+```python main.py
from deepteam import red_team
+from deepteam.vulnerabilities import bias
+
+async def model_callback(input: str):
+ # Call your LLM app here
+ return f"I'm sorry, but I can't answer {input}"
+
+bias = Bias()
+bias.assess(model_callback=model_callback)
+
+print(bias.is_vulnerable())
+print(bias.simulated_attacks)
+print(bias.res)
+```
+
+The `is_vulnerable()` method returns `True` if either one of your vulnerability types are failing.
+
+## Using Vulnerabilities Async
+
+When a vulnerability's `async_mode=True` (which is the default for all vulnerabilities), invocations of `vulnerability.assess()` will execute internal algorithms concurrently. However, it's important to note that while operations **INSIDE** `assess` executes concurrently, the `vulnerability.assess()` call itself still blocks the main thread.
+
+:::info
+
+**TL;DR**: Use `async_mode=True` unless you somehow cannot, it will speed up your assessments by **9x.**
+
+---
+
+If `async_mode=True` blocks the main thread, what does it do? Consider these two examples:
+
+```python
+from deepteam.vulnerabilities import Bias, Toxicity
+
+bias = Bias(types=["race", "gender"], async_mode=True)
+bias.assess(model_callback) # Runs async, blocks main thread
+
+toxicity = Toxicity(types=["profanity", "insults"], async_mode=False)
+toxicity.assess(model_callback) # Runs sync, blocks main thread
+```
+
+Although both `assess()` method from `Bias` and `Toxicity` will block the main thread, the `assess` on `Toxicity()` will take approximately **nine times** longer as `Bias()`.
+
+Consider the `assess` algorithm:
+
+1. Both vulnerabilities will first simulate 2 attacks, one for each type
+2. Both vulnerabilities will then probe your `model_callback` twice, once for each simulated attack
+3. Both vulnerabilities will then evaluate your LLM app's output twice, once per LLM output
+
+This means that when you do steps 1, 2, and 3 concurrently, you will save (`n` x `m`) x 3 units of time, where `n` is the number of types, `m` is the time it takes to complete an unit of work for each type, and the number `3` representing the total number of steps in the `assess()` algorithm.
+
+:::
+
+To assess multiple vulnerabilities at once and **NOT** block the main thread, use the asynchronous `a_assess()` method instead.
+
+```python title="main.py"
+import asyncio
...
-red_team(vulnerabilities[pii_leakage, bias], model_callback=..., attacks=[...])
+# Remember to use async
+async def long_running_function():
+ # These will all run at the same time
+ await asyncio.gather(
+ vulnerability_1.a_assess(model_callback),
+ vulnerability_2.a_assess(model_callback),
+ vulnerability_3.a_assess(model_callback),
+ vulnerability_4.a_assess(model_callback)
+ )
+ print("Assessment finished!")
+
+asyncio.run(long_running_function())
```
-`deepteam` lets you scan for **22 different vulnerabilties** (which amounts to a combined 80+ vulnerability types), ensuring comprehensive coverage of potential risks within your LLM application.
-
-These risks and vulnerabilities include:
-
-- **Data Privacy**
- - [PII Leakage](red-teaming-vulnerabilities-pii-leakage)
- - [Prompt Leakage](red-teaming-vulnerabilities-prompt-leakage)
-- **Responsible AI**
- - [Bias](red-teaming-vulnerabilities-bias)
- - [Toxicity](red-teaming-vulnerabilities-toxicity)
-- **Security**
- - [BFLA](red-teaming-vulnerabilities-bfla)
- - [BOLA](red-teaming-vulnerabilities-bola)
- - [RBAC](red-teaming-vulnerabilities-rbac)
- - [Debug Access](red-teaming-vulnerabilities-debug-access)
- - [Shell Injection](red-teaming-vulnerabilities-shell-injection)
- - [SQL Injection](red-teaming-vulnerabilities-sql-injection)
- - [SSRF](red-teaming-vulnerabilities-ssrf)
-- **Safety**
- - [Illegal Activities](red-teaming-vulnerabilities-illegal-activity)
- - [Graphic Content](red-teaming-vulnerabilities-graphic-content)
- - [Personal Safety](red-teaming-vulnerabilities-personal-safety)
-- **Business**
- - [Misinformation](red-teaming-vulnerabilities-misinformation)
- - [Intellectual Property](red-teaming-vulnerabilities-intellectual-property)
- - [Competition](red-teaming-vulnerabilities-competition)
-- **Agentic**
- - [Goal Theft](red-teaming-agentic-vulnerabilities-goal-theft)
- - [Recursive Hijacking](red-teaming-agentic-vulnerabilities-recursive-hijacking)
- - [Excessive Agency](red-teaming-vulnerabilities-excessive-agency)
- - [Robustnesss](red-teaming-vulnerabilities-robustness)
-
-You can also create [custom vulnerabilities](/docs/red-teaming-custom-vulnerability) for any vulnerability that is not covered by `deepteam`.
-
-## Five Main LLM Risks
-
-LLM vulnerabilities can be categorized into 6 major LLM risk categories. Think of these categories simply as collections of vulnerabilities.
-
-| LLM Risk Category | Vulnerabilities | Description |
-| ----------------- | ------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| Data Privacy | `PIILeakage`, `PromptLeakage` | Involves exposure of personal or sensitive information through LLM outputs, leading to privacy breaches or regulatory violations. |
-| Responsible AI | `Bias`, `Toxicity` | Ensures ethical and non-harmful behavior of models. Risks include offensive, discriminatory, or unfair content. |
-| Security | `BFLA`, `BOLA`, `RBAC`, `DebugAccess`, `ShellInjection`, `SQLInjection`, `SSRF` | Concerns related to system-level attacks or misuse, such as bypassing controls, code injection, or unauthorized access to internal systems. |
-| Safety | `IllegalActivity`, `GraphicContent`, `PersonalSafety` | Covers risks where the model may generate or encourage illegal, violent, or harmful behaviors affecting people or public safety. |
-| Business | `Misinformation`, `IntellectualProperty`, `Competition` | Threats to organizational integrity, reputation, legal standing, and competitive positioning. Includes IP leakage, false information, and competitive data exposure. |
-| Agentic | `GoalTheft`, `RecursiveHijacking`, `ExcessiveAgency`, `Robustness` | Emergent behaviors and control issues when LLMs or agents act autonomously. Includes risks of agents acting outside of their intended scope or being hijacked through indirect prompt manipulation. |
+## What About Metrics?
+
+Unlike `deepeval`, `deepteam` focuses on vulnerabilities instead of metrics, and in fact hides metrics behind vulnerabilities as an abstraction. This is because red teaming involves attack simulation which is fundamentally different from pure metric calculations. However, you can access each vulnerability's corresponding metric via the `.get_metric()` method:
+
+```python
+from deepteam.vulnerabilities import Bias
+
+bias = Bias(types=["gender"])
+metric = bias.get_metric(bias.types[0])
+```
\ No newline at end of file