diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yaml index 5347d4a791..a85c2b75e2 100644 --- a/litellm/proxy/_new_secret_config.yaml +++ b/litellm/proxy/_new_secret_config.yaml @@ -49,4 +49,12 @@ general_settings: router_settings: redis_host: os.environ/REDIS_HOST redis_password: os.environ/REDIS_PASSWORD - redis_port: os.environ/REDIS_PORT \ No newline at end of file + redis_port: os.environ/REDIS_PORT + +guardrails: + - guardrail_name: "aporia-pre-guard" + litellm_params: + guardrail: aporia # supported values: "aporia", "lakera" + mode: "during_call" + api_key: os.environ/APORIO_API_KEY + api_base: os.environ/APORIO_API_BASE \ No newline at end of file diff --git a/litellm/proxy/guardrails/guardrail_endpoints.py b/litellm/proxy/guardrails/guardrail_endpoints.py index 3b31c31a97..390599dc0e 100644 --- a/litellm/proxy/guardrails/guardrail_endpoints.py +++ b/litellm/proxy/guardrails/guardrail_endpoints.py @@ -25,6 +25,7 @@ def _get_guardrails_list_response( guardrail_configs.append( GuardrailInfoResponse( guardrail_name=guardrail.get("guardrail_name"), + litellm_params=guardrail.get("litellm_params"), guardrail_info=guardrail.get("guardrail_info"), ) ) diff --git a/litellm/types/guardrails.py b/litellm/types/guardrails.py index 4f72a39b92..724b0eefcf 100644 --- a/litellm/types/guardrails.py +++ b/litellm/types/guardrails.py @@ -1,7 +1,7 @@ from enum import Enum -from typing import Any, Dict, List, Literal, Optional, TypedDict +from typing import Any, Dict, List, Literal, Optional, TypedDict, Union -from pydantic import BaseModel, ConfigDict +from pydantic import BaseModel, ConfigDict, Field, SecretStr from typing_extensions import Required, TypedDict """ @@ -83,7 +83,7 @@ class LakeraCategoryThresholds(TypedDict, total=False): class LitellmParams(TypedDict): guardrail: str mode: str - api_key: str + api_key: Optional[str] api_base: Optional[str] # Lakera specific params @@ -140,9 +140,28 @@ class DynamicGuardrailParams(TypedDict): extra_body: Dict[str, Any] +class GuardrailLiteLLMParamsResponse(BaseModel): + """The returned LiteLLM Params object for /guardrails/list""" + + guardrail: str + mode: Union[str, List[str]] + default_on: bool = Field(default=False) + + def __init__(self, **kwargs): + default_on = kwargs.get("default_on") + if default_on is None: + default_on = False + + super().__init__(**kwargs) + + class GuardrailInfoResponse(BaseModel): guardrail_name: Optional[str] - guardrail_info: Optional[Dict] # This will contain all other fields + litellm_params: GuardrailLiteLLMParamsResponse + guardrail_info: Optional[Dict] + + def __init__(self, **kwargs): + super().__init__(**kwargs) class ListGuardrailsResponse(BaseModel): diff --git a/tests/local_testing/test_guardrails_config.py b/tests/local_testing/test_guardrails_config.py index 5ef585dbb9..66406ac5f4 100644 --- a/tests/local_testing/test_guardrails_config.py +++ b/tests/local_testing/test_guardrails_config.py @@ -90,3 +90,24 @@ def test_guardrail_list_of_event_hooks(): assert not cg.should_run_guardrail( data=data, event_type=GuardrailEventHooks.during_call ) + + +def test_guardrail_info_response(): + from litellm.types.guardrails import GuardrailInfoResponse, LitellmParams + + guardrail_info = GuardrailInfoResponse( + guardrail_name="aporia-pre-guard", + litellm_params=LitellmParams( + guardrail="aporia", + mode="pre_call", + ), + guardrail_info={ + "guardrail_name": "aporia-pre-guard", + "litellm_params": { + "guardrail": "aporia", + "mode": "always_on", + }, + }, + ) + + assert guardrail_info.litellm_params.default_on == False