Skip to content

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

.

sid-murali3bf880396907
diff --git a/deepteam/guardrails/base_guard.py b/deepteam/guardrails/base_guard.py
index c225f3cb..91c4d920 100644
--- a/deepteam/guardrails/base_guard.py
+++ b/deepteam/guardrails/base_guard.py
@@ -1,6 +1,7 @@
from abc import ABC, abstractmethod
from typing import Optional, Dict, Union
from deepeval.models.llms.utils import trim_and_load_json
+from deepeval.models.base_model import DeepEvalBaseLLM
import json
from deepteam.guardrails.types import GuardType
from deepteam.cli.model_callback import load_model
@@ -13,8 +14,11 @@ class BaseGuard(ABC):
latency: Optional[float] = None
guard_type: GuardType
- def __init__(self, evaluation_model: Union[str, Dict] = "gpt-4.1"):
- self.model = load_model(evaluation_model)
+ def __init__(self, evaluation_model: Union[str, Dict, DeepEvalBaseLLM] = "gpt-4.1"):
+ if isinstance(evaluation_model, DeepEvalBaseLLM):
+ self.model = evaluation_model
+ else:
+ 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 f2cb9774..c77770df 100644
--- a/deepteam/guardrails/guardrails.py
+++ b/deepteam/guardrails/guardrails.py
@@ -1,4 +1,5 @@
from typing import List, Dict, Any, Union
+from deepeval.models.base_model import DeepEvalBaseLLM
import time
import asyncio
@@ -13,7 +14,7 @@ class GuardResult:
# Only 0.0 (unsafe) is considered breached
# 0.5 (uncertain) and 1.0 (safe) are not breached
self.breached = any(
- result.get("score", 1.0) == 0.0
+ result.get("score", 0) < 1.0
for result in guard_results.values()
)
@@ -28,7 +29,7 @@ class Guardrails:
self,
input_guards: List[BaseGuard],
output_guards: List[BaseGuard],
- evaluation_model: Union[str, Dict] = "gpt-4.1",
+ evaluation_model: Union[str, Dict, DeepEvalBaseLLM] = "gpt-4.1",
sample_rate: float = 1.0
):
"""
@@ -37,7 +38,7 @@ 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: Model specification (string or dict) for guard evaluation (default: "gpt-4.1")
+ evaluation_model: Model specification (string, dict, or DeepEvalBaseLLM instance) 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)
"""
@@ -53,7 +54,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: Union[str, Dict]) -> List[BaseGuard]:
+ def _update_guards_model(self, guards: List[BaseGuard], evaluation_model: Union[str, Dict, DeepEvalBaseLLM]) -> 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 2365e334..0dd61ab2 100644
--- a/deepteam/guardrails/guards/illegal_guard.py
+++ b/deepteam/guardrails/guards/illegal_guard.py
@@ -1,10 +1,11 @@
from ..base_guard import BaseGuard
from ..types import GuardType
from typing import Union, Dict
+from deepeval.models.base_model import DeepEvalBaseLLM
class IllegalGuard(BaseGuard):
- def __init__(self, evaluation_model: Union[str, Dict] = "gpt-4.1"):
+ def __init__(self, evaluation_model: Union[str, Dict, DeepEvalBaseLLM] = "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 d8c783b1..8ca53ab2 100644
--- a/deepteam/guardrails/guards/prompt_injection_guard.py
+++ b/deepteam/guardrails/guards/prompt_injection_guard.py
@@ -1,10 +1,11 @@
from ..base_guard import BaseGuard
from ..types import GuardType
from typing import Union, Dict
+from deepeval.models.base_model import DeepEvalBaseLLM
class PromptInjectionGuard(BaseGuard):
- def __init__(self, evaluation_model: Union[str, Dict] = "gpt-4.1"):
+ def __init__(self, evaluation_model: Union[str, Dict, DeepEvalBaseLLM] = "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 d2743810..971eafcb 100644
--- a/deepteam/guardrails/guards/topical_guard.py
+++ b/deepteam/guardrails/guards/topical_guard.py
@@ -1,12 +1,13 @@
from ..base_guard import BaseGuard
from ..types import GuardType
from typing import Union, Dict, List
+from deepeval.models.base_model import DeepEvalBaseLLM
class TopicalGuard(BaseGuard):
def __init__(
self,
- evaluation_model: Union[str, Dict] = "gpt-4.1",
+ evaluation_model: Union[str, Dict, DeepEvalBaseLLM] = "gpt-4.1",
allowed_topics: List[str] = None,
description: str = None
):
diff --git a/deepteam/guardrails/guards/toxicity_guard.py b/deepteam/guardrails/guards/toxicity_guard.py
index e9227d3e..dcde3c00 100644
--- a/deepteam/guardrails/guards/toxicity_guard.py
+++ b/deepteam/guardrails/guards/toxicity_guard.py
@@ -1,10 +1,11 @@
from ..base_guard import BaseGuard
from ..types import GuardType
from typing import Union, Dict
+from deepeval.models.base_model import DeepEvalBaseLLM
class ToxicityGuard(BaseGuard):
- def __init__(self, evaluation_model: Union[str, Dict] = "gpt-4.1"):
+ def __init__(self, evaluation_model: Union[str, Dict, DeepEvalBaseLLM] = "gpt-4.1"):
super().__init__(evaluation_model=evaluation_model)
self.guard_type = GuardType.OUTPUT