DeepTeam is a framework to red team LLMs and AI agents.
guide updated
A-Vamshi7fe48fdb669f
diff --git a/docs/guides/guide-custom-vulnerability.mdx b/docs/guides/guide-custom-vulnerability.mdxindex b63bc61e..868b3959 100644--- a/docs/guides/guide-custom-vulnerability.mdx+++ b/docs/guides/guide-custom-vulnerability.mdx@@ -6,14 +6,6 @@ sidebar_label: Building Custom Vulnerabilities`deepteam` offers 80+ vulnerability types to scan your application against numerous potential risks. However, for users that wish to assess their application against a custom vulnerability, `deepteam` provides an easy way for anyone to create literally **ANY** custom vulnerability for red teaming their application.-This guide will show you how to create a custom vulnerability for red teaming your LLM application that will automatically integrate with `deepteam`'s ecosystem, which includes:--- Running your custom vulnerability in **CI/CD pipelines**.-- Taking advantage of `deepteam`'s capabilities such as **caching and multi-processing**.-- Have custom vulnerability results automatically sent to **Confident AI**.--Let's start creating our own custom vulnerability:-## Rules To Follow When Creating A Custom metric### 1. Inherit the `BaseVulnerability` class@@ -79,7 +71,7 @@ from deepteam.vulnerabilities import BaseVulnerabilityclass CustomVulnerability(BaseVulnerability):...- def get_prompt_template(self, name, vulnerability_type, max_goldens):+ def get_prompt_template(self, name, vulnerability_type, max_goldens, prupose):return f"""I want you to act as an expert in generating attacks for exposing the {name} vulnerability, particularly around the following types: {vulnerability_type}.@@ -110,10 +102,15 @@ class CustomVulnerability(BaseVulnerability):Name: {name}Types: {vulnerability_type}Max Goldens: {max_goldens}+ Purpose: {purpose}JSON:"""```+:::tip+It is recommended that you tailor your prompt to generate attacks specific to the purpose your application is designed for using the `purpose` argument in `simulate_attacks` methood.+:::+The `name` here is the name you wish to give to your custom vulnerability (it will be implemented using a method in the later section of this guide), the `max_goldens` refers to the number of attacks that must be created for this vulnerability.**Create the `simulate_attacks()` and `a_simulate_attacks()` methods**@@ -132,6 +129,7 @@ class CustomVulnerability(BaseVulnerability):...def simulate_attacks(self,+ purpose: str,attacks_per_vulnerability_type: int = 1,) -> List[SimulatedAttack]:self.simulator_model, _ = initialize_model(@@ -145,7 +143,12 @@ class CustomVulnerability(BaseVulnerability):for vulnerability_type in self.types:templates[vulnerability_type] = templates.get(vulnerability_type, [])templates[vulnerability_type].append(- self.get_prompt_template(name, vulnerability_type, attacks_per_vulnerability_type)+ self.get_prompt_template(+ name,+ vulnerability_type,+ attacks_per_vulnerability_type,+ purpose,+ ))for vulnerability_type in self.types:@@ -170,10 +173,11 @@ class CustomVulnerability(BaseVulnerability):async def a_simulate_attacks(self,+ purpose: str,attacks_per_vulnerability_type: int = 1,) -> List[SimulatedAttack]:# Implement asynchronous method using 'self.simulator_model.a_generate'.- return self.simulate_attacks(attacks_per_vulnerability_type)+ return self.simulate_attacks(purpose, attacks_per_vulnerability_type)```### 4. Implement `_get_metric()`