Skip to content

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

.

sid-murali290b28bdcf2f
diff --git a/deepteam/guardrails/base_guard.py b/deepteam/guardrails/base_guard.py
index d3058779..c225f3cb 100644
--- a/deepteam/guardrails/base_guard.py
+++ b/deepteam/guardrails/base_guard.py
@@ -1,9 +1,9 @@
from abc import ABC, abstractmethod
-from typing import Optional, Dict
-from deepeval.models import GPTModel
+from typing import Optional, Dict, Union
from deepeval.models.llms.utils import trim_and_load_json
import json
from deepteam.guardrails.types import GuardType
+from deepteam.cli.model_callback import load_model
class BaseGuard(ABC):
score: Optional[float] = None
@@ -13,8 +13,8 @@ class BaseGuard(ABC):
latency: Optional[float] = None
guard_type: GuardType
- def __init__(self, evaluation_model: str = "gpt-4.1"):
- self.model = GPTModel(model=evaluation_model)
+ def __init__(self, evaluation_model: Union[str, Dict] = "gpt-4.1"):
+ self.model = load_model(evaluation_model)
self.evaluation_model = self.model.get_model_name()
@property
diff --git a/deepteam/guardrails/guardrails.py b/deepteam/guardrails/guardrails.py
index 42acab56..f2cb9774 100644
--- a/deepteam/guardrails/guardrails.py
+++ b/deepteam/guardrails/guardrails.py
@@ -1,4 +1,4 @@
-from typing import List, Dict, Any
+from typing import List, Dict, Any, Union
import time
import asyncio
@@ -28,7 +28,7 @@ class Guardrails:
self,
input_guards: List[BaseGuard],
output_guards: List[BaseGuard],
- evaluation_model: str = "gpt-4.1",
+ evaluation_model: Union[str, Dict] = "gpt-4.1",
sample_rate: float = 1.0
):
"""
@@ -37,7 +37,8 @@ class Guardrails:
Args:
input_guards: List of guards to check inputs before they reach your LLM
output_guards: List of guards to check outputs before they reach your users
- evaluation_model: OpenAI model to use for guard evaluation (default: gpt-4.1)
+ evaluation_model: Model specification (string or dict) for guard evaluation (default: "gpt-4.1")
+ Supports OpenAI, Azure, Anthropic, Gemini, Ollama, Custom models
sample_rate: Fraction of requests to actually guard (0.0 to 1.0, default: 1.0)
"""
# Validate sample_rate
@@ -52,7 +53,7 @@ class Guardrails:
self.input_guards = self._update_guards_model(input_guards, evaluation_model)
self.output_guards = self._update_guards_model(output_guards, evaluation_model)
- def _update_guards_model(self, guards: List[BaseGuard], evaluation_model: str) -> List[BaseGuard]:
+ def _update_guards_model(self, guards: List[BaseGuard], evaluation_model: Union[str, Dict]) -> List[BaseGuard]:
"""Update all guards to use the specified evaluation model"""
updated_guards = []
for guard in guards:
diff --git a/deepteam/guardrails/guards/illegal_guard.py b/deepteam/guardrails/guards/illegal_guard.py
index 6c53750e..2365e334 100644
--- a/deepteam/guardrails/guards/illegal_guard.py
+++ b/deepteam/guardrails/guards/illegal_guard.py
@@ -1,10 +1,10 @@
from ..base_guard import BaseGuard
from ..types import GuardType
-from typing import Optional
+from typing import Union, Dict
class IllegalGuard(BaseGuard):
- def __init__(self, evaluation_model: Optional[str] = None):
+ def __init__(self, evaluation_model: Union[str, Dict] = "gpt-4.1"):
super().__init__(evaluation_model=evaluation_model)
self.guard_type = GuardType.OUTPUT
diff --git a/deepteam/guardrails/guards/prompt_injection_guard.py b/deepteam/guardrails/guards/prompt_injection_guard.py
index 8155ad42..d8c783b1 100644
--- a/deepteam/guardrails/guards/prompt_injection_guard.py
+++ b/deepteam/guardrails/guards/prompt_injection_guard.py
@@ -1,9 +1,10 @@
from ..base_guard import BaseGuard
from ..types import GuardType
+from typing import Union, Dict
class PromptInjectionGuard(BaseGuard):
- def __init__(self, evaluation_model: str = "gpt-4.1"):
+ def __init__(self, evaluation_model: Union[str, Dict] = "gpt-4.1"):
super().__init__(evaluation_model=evaluation_model)
self.guard_type = GuardType.INPUT
diff --git a/deepteam/guardrails/guards/topical_guard.py b/deepteam/guardrails/guards/topical_guard.py
index f9c8c2cc..d2743810 100644
--- a/deepteam/guardrails/guards/topical_guard.py
+++ b/deepteam/guardrails/guards/topical_guard.py
@@ -1,13 +1,19 @@
from ..base_guard import BaseGuard
from ..types import GuardType
-from typing import Optional
+from typing import Union, Dict, List
class TopicalGuard(BaseGuard):
- def __init__(self, allowed_topics=None, evaluation_model: Optional[str] = None):
+ def __init__(
+ self,
+ evaluation_model: Union[str, Dict] = "gpt-4.1",
+ allowed_topics: List[str] = None,
+ description: str = None
+ ):
super().__init__(evaluation_model=evaluation_model)
self.guard_type = GuardType.INPUT
self.allowed_topics = allowed_topics or []
+ self.description = description or "General conversation topics"
@property
def __name__(self):
diff --git a/deepteam/guardrails/guards/toxicity_guard.py b/deepteam/guardrails/guards/toxicity_guard.py
index b3191748..e9227d3e 100644
--- a/deepteam/guardrails/guards/toxicity_guard.py
+++ b/deepteam/guardrails/guards/toxicity_guard.py
@@ -1,9 +1,10 @@
from ..base_guard import BaseGuard
from ..types import GuardType
+from typing import Union, Dict
class ToxicityGuard(BaseGuard):
- def __init__(self, evaluation_model: str = "gpt-4.1"):
+ def __init__(self, evaluation_model: Union[str, Dict] = "gpt-4.1"):
super().__init__(evaluation_model=evaluation_model)
self.guard_type = GuardType.OUTPUT