Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions litellm/types/guardrails.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
from pydantic import BaseModel, ConfigDict, Field, field_validator
from typing_extensions import Required, TypedDict

from litellm.types.llms.openai import (
AllMessageValues,
ChatCompletionToolCallChunk,
ChatCompletionToolParam,
)
from litellm.types.proxy.guardrails.guardrail_hooks.enkryptai import (
EnkryptAIGuardrailConfigs,
)
Expand Down Expand Up @@ -673,20 +668,20 @@ class LitellmParams(
description="When to apply the guardrail (pre_call, post_call, during_call, logging_only)"
)

@field_validator("default_action", mode="before", check_fields=False)
@classmethod
def normalize_default_action_litellm_params(cls, v):
"""Normalize default_action to lowercase for ALL guardrail types."""
if isinstance(v, str):
return v.lower()
return v

@field_validator("on_disallowed_action", mode="before", check_fields=False)
@field_validator(
"mode",
"default_action",
"on_disallowed_action",
mode="before",
check_fields=False,
)
@classmethod
def normalize_on_disallowed_action_litellm_params(cls, v):
"""Normalize on_disallowed_action to lowercase for ALL guardrail types."""
def normalize_lowercase(cls, v):
"""Normalize string and list fields to lowercase for ALL guardrail types."""
if isinstance(v, str):
return v.lower()
if isinstance(v, list):
return [x.lower() if isinstance(x, str) else x for x in v]
return v

def __init__(self, **kwargs):
Expand All @@ -695,7 +690,7 @@ def __init__(self, **kwargs):
kwargs["default_on"] = default_on
else:
kwargs["default_on"] = False

super().__init__(**kwargs)

def __contains__(self, key):
Expand Down
12 changes: 10 additions & 2 deletions tests/litellm-proxy-extras/test_litellm_proxy_extras_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import sys

sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
0,
os.path.abspath(
os.path.join(os.path.dirname(__file__), "../../litellm-proxy-extras")
),
)

from litellm_proxy_extras.utils import ProxyExtrasDBManager

Expand Down Expand Up @@ -99,6 +102,11 @@ def test_is_idempotent_error_case_insensitive(self):
error_message = "COLUMN 'ID' ALREADY EXISTS"
assert ProxyExtrasDBManager._is_idempotent_error(error_message) is True

def test_is_idempotent_error_does_not_exist(self):
"""Test detection of 'does not exist' error"""
error_message = "ERROR: index 'idx' does not exist"
assert ProxyExtrasDBManager._is_idempotent_error(error_message) is True

def test_is_idempotent_error_negative(self):
"""Test that non-idempotent errors are not detected as idempotent errors"""
error_message = "Database error code: 42501 - permission denied"
Expand Down
Loading