Skip to content

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

use list instead of dict

A-Vamshid363db92d9ae
diff --git a/deepteam/frameworks/mitre/mitre.py b/deepteam/frameworks/mitre/mitre.py
index de2c0b0d..7ecd3c98 100644
--- a/deepteam/frameworks/mitre/mitre.py
+++ b/deepteam/frameworks/mitre/mitre.py
@@ -1,6 +1,6 @@
from typing import List, Literal
from deepteam.frameworks import AISafetyFramework
-from deepteam.frameworks.mitre.risk_categories import MITRE_MAPPING
+from deepteam.frameworks.mitre.risk_categories import MITRE_CATEGORIES
class MITRE(AISafetyFramework):
@@ -35,17 +35,19 @@ class MITRE(AISafetyFramework):
def _get_vulnerabilities_by_categories(self, categories):
vulnerabilities = []
for category in categories:
- risk_category = MITRE_MAPPING.get(category)
- new_vulnerabilities = risk_category.vulnerabilities
- vulnerabilities.extend(new_vulnerabilities)
+ for risk_category in MITRE_CATEGORIES:
+ if category == risk_category.name:
+ new_vulnerabilities = risk_category.vulnerabilities
+ vulnerabilities.extend(new_vulnerabilities)
return vulnerabilities
def _get_attacks_by_categories(self, categories):
attacks = []
for category in categories:
- risk_category = MITRE_MAPPING.get(category)
- new_attacks = risk_category.attacks
- attacks.extend(new_attacks)
+ for risk_category in MITRE_CATEGORIES:
+ if category == risk_category.name:
+ new_attacks = risk_category.attacks
+ attacks.extend(new_attacks)
return attacks
def get_name(self):
diff --git a/deepteam/frameworks/mitre/risk_categories.py b/deepteam/frameworks/mitre/risk_categories.py
index 24a3accf..dc173f3e 100644
--- a/deepteam/frameworks/mitre/risk_categories.py
+++ b/deepteam/frameworks/mitre/risk_categories.py
@@ -31,8 +31,8 @@ from deepteam.attacks.multi_turn import (
SequentialJailbreak,
)
-MITRE_MAPPING = {
- "reconnaissance": RiskCategory(
+MITRE_CATEGORIES = [
+ RiskCategory(
name="reconnaissance",
attacks=[
Roleplay(
@@ -77,7 +77,7 @@ MITRE_MAPPING = {
),
],
),
- "resource_development": RiskCategory(
+ RiskCategory(
name="resource_development",
attacks=[
Roleplay(
@@ -122,7 +122,7 @@ MITRE_MAPPING = {
),
],
),
- "initial_access": RiskCategory(
+ RiskCategory(
name="initial_access",
attacks=[
Roleplay(
@@ -167,7 +167,7 @@ MITRE_MAPPING = {
),
],
),
- "ml_attack_staging": RiskCategory(
+ RiskCategory(
name="ml_attack_staging",
attacks=[
PromptInjection(weight=2),
@@ -199,7 +199,7 @@ MITRE_MAPPING = {
),
],
),
- "exfiltration": RiskCategory(
+ RiskCategory(
name="exfiltration",
attacks=[
Roleplay(
@@ -270,7 +270,7 @@ MITRE_MAPPING = {
),
],
),
- "impact": RiskCategory(
+ RiskCategory(
name="impact",
attacks=[
Roleplay(
@@ -311,4 +311,4 @@ MITRE_MAPPING = {
),
],
),
-}
+]
diff --git a/tests/test_frameworks/test_mitre.py b/tests/test_frameworks/test_mitre.py
index 1b84ed36..7d9875b0 100644
--- a/tests/test_frameworks/test_mitre.py
+++ b/tests/test_frameworks/test_mitre.py
@@ -2,8 +2,8 @@ import pytest
from deepteam.frameworks import MITRE
from deepteam.vulnerabilities import BaseVulnerability
from deepteam.attacks import BaseAttack
-from deepteam.frameworks.mitre.risk_categories import MITRE_MAPPING
from deepteam.frameworks.risk_category import RiskCategory
+from deepteam.frameworks.mitre.risk_categories import MITRE_CATEGORIES
from deepteam import red_team
@@ -70,8 +70,8 @@ class TestMITRE:
def test_mitre_category_vulnerability_mapping(self):
"""Test that all categories map to vulnerabilities properly."""
- mapping = MITRE_MAPPING
- assert set(mapping.keys()) == {
+ categories = MITRE_CATEGORIES
+ assert set([category.name for category in categories]) == {
"reconnaissance",
"resource_development",
"initial_access",
@@ -79,7 +79,7 @@ class TestMITRE:
"exfiltration",
"impact",
}
- for risk_category in mapping.values():
+ for risk_category in categories:
assert isinstance(risk_category, RiskCategory)
assert all(
isinstance(v, BaseVulnerability)
@@ -88,8 +88,8 @@ class TestMITRE:
def test_mitre_category_attack_mapping(self):
"""Test that all categories map to attacks properly."""
- mapping = MITRE_MAPPING
- assert set(mapping.keys()) == {
+ categories = MITRE_CATEGORIES
+ assert set([category.name for category in categories]) == {
"reconnaissance",
"resource_development",
"initial_access",
@@ -97,7 +97,7 @@ class TestMITRE:
"exfiltration",
"impact",
}
- for risk_category in mapping.values():
+ for risk_category in categories:
assert isinstance(risk_category, RiskCategory)
assert all(isinstance(v, BaseAttack) for v in risk_category.attacks)