The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
feat(guardrails.py): return specific litellm params in `/guardrails/list` endpoint
Krrish Dholakiae9a861ec32ce
diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yamlindex 5347d4a791b..a85c2b75e21 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_HOSTredis_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 filediff --git a/litellm/proxy/guardrails/guardrail_endpoints.py b/litellm/proxy/guardrails/guardrail_endpoints.pyindex 3b31c31a974..390599dc0e1 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.pyindex 4f72a39b92b..724b0eefcf9 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, SecretStrfrom typing_extensions import Required, TypedDict"""@@ -83,7 +83,7 @@ class LakeraCategoryThresholds(TypedDict, total=False):class LitellmParams(TypedDict):guardrail: strmode: 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.pyindex 5ef585dbb9d..66406ac5f4b 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