mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-05 18:24:49 +00:00
[Bug Fix] Content Filter Guard (#16414)
* fix add_guardrail_to_db * bump commit
This commit is contained in:
+1
-1
@@ -34,7 +34,7 @@ from litellm.types.utils import (
|
||||
all_litellm_params as _litellm_completion_params,
|
||||
CredentialItem,
|
||||
PriorityReservationDict,
|
||||
) # maintain backwards compatibility for root param
|
||||
) # maintain backwards compatibility for root param.
|
||||
from litellm._logging import (
|
||||
set_verbose,
|
||||
_turn_on_debug,
|
||||
|
||||
@@ -232,7 +232,13 @@ class GuardrailRegistry:
|
||||
"""
|
||||
try:
|
||||
guardrail_name = guardrail.get("guardrail_name")
|
||||
litellm_params: str = safe_dumps(dict(guardrail.get("litellm_params", {})))
|
||||
# Properly serialize LitellmParams Pydantic model to dict
|
||||
litellm_params_obj = guardrail.get("litellm_params", {})
|
||||
if hasattr(litellm_params_obj, 'model_dump'):
|
||||
litellm_params_dict = litellm_params_obj.model_dump()
|
||||
else:
|
||||
litellm_params_dict = dict(litellm_params_obj) if litellm_params_obj else {}
|
||||
litellm_params: str = safe_dumps(litellm_params_dict)
|
||||
guardrail_info: str = safe_dumps(guardrail.get("guardrail_info", {}))
|
||||
|
||||
# Create guardrail in DB
|
||||
@@ -278,7 +284,13 @@ class GuardrailRegistry:
|
||||
"""
|
||||
try:
|
||||
guardrail_name = guardrail.get("guardrail_name")
|
||||
litellm_params: str = safe_dumps(dict(guardrail.get("litellm_params", {})))
|
||||
# Properly serialize LitellmParams Pydantic model to dict
|
||||
litellm_params_obj = guardrail.get("litellm_params", {})
|
||||
if hasattr(litellm_params_obj, 'model_dump'):
|
||||
litellm_params_dict = litellm_params_obj.model_dump()
|
||||
else:
|
||||
litellm_params_dict = dict(litellm_params_obj) if litellm_params_obj else {}
|
||||
litellm_params: str = safe_dumps(litellm_params_dict)
|
||||
guardrail_info: str = safe_dumps(guardrail.get("guardrail_info", {}))
|
||||
|
||||
# Update in DB
|
||||
|
||||
Reference in New Issue
Block a user