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.pyindex c225f3cb..91c4d920 100644--- a/deepteam/guardrails/base_guard.py+++ b/deepteam/guardrails/base_guard.py@@ -1,6 +1,7 @@from abc import ABC, abstractmethodfrom typing import Optional, Dict, Unionfrom deepeval.models.llms.utils import trim_and_load_json+from deepeval.models.base_model import DeepEvalBaseLLMimport jsonfrom deepteam.guardrails.types import GuardTypefrom deepteam.cli.model_callback import load_model@@ -13,8 +14,11 @@ class BaseGuard(ABC):latency: Optional[float] = Noneguard_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()@propertydiff --git a/deepteam/guardrails/guardrails.py b/deepteam/guardrails/guardrails.pyindex 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 DeepEvalBaseLLMimport timeimport asyncio@@ -13,7 +14,7 @@ class GuardResult:# Only 0.0 (unsafe) is considered breached# 0.5 (uncertain) and 1.0 (safe) are not breachedself.breached = any(- result.get("score", 1.0) == 0.0+ result.get("score", 0) < 1.0for 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 LLMoutput_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 modelssample_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.pyindex 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 BaseGuardfrom ..types import GuardTypefrom typing import Union, Dict+from deepeval.models.base_model import DeepEvalBaseLLMclass 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.OUTPUTdiff --git a/deepteam/guardrails/guards/prompt_injection_guard.py b/deepteam/guardrails/guards/prompt_injection_guard.pyindex 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 BaseGuardfrom ..types import GuardTypefrom typing import Union, Dict+from deepeval.models.base_model import DeepEvalBaseLLMclass 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.INPUTdiff --git a/deepteam/guardrails/guards/topical_guard.py b/deepteam/guardrails/guards/topical_guard.pyindex 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 BaseGuardfrom ..types import GuardTypefrom typing import Union, Dict, List+from deepeval.models.base_model import DeepEvalBaseLLMclass 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.pyindex 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 BaseGuardfrom ..types import GuardTypefrom typing import Union, Dict+from deepeval.models.base_model import DeepEvalBaseLLMclass 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