From 181c626d83a0b3cc75bbca0b6d443ec80f26eb2d Mon Sep 17 00:00:00 2001 From: Harshit Jain <48647625+Harshit28j@users.noreply.github.com> Date: Wed, 14 Jan 2026 03:23:54 +0530 Subject: [PATCH] fix: properly handle custom guardrails parameters (#18978) --- litellm/proxy/guardrails/guardrail_registry.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/litellm/proxy/guardrails/guardrail_registry.py b/litellm/proxy/guardrails/guardrail_registry.py index fe53fe3b32..c3da689220 100644 --- a/litellm/proxy/guardrails/guardrail_registry.py +++ b/litellm/proxy/guardrails/guardrail_registry.py @@ -526,10 +526,24 @@ class InMemoryGuardrailHandler: ) default_on = litellm_params.default_on + + # Extract additional params from litellm_params to pass to custom guardrail + # This matches the behavior of other guardrail initializers (e.g., initialize_lakera) + # and aligns with the documented behavior for custom guardrails + if hasattr(litellm_params, "model_dump"): + extra_params = litellm_params.model_dump(exclude_none=True) + else: + extra_params = dict(litellm_params) if litellm_params else {} + + # Remove params that are handled explicitly or are internal + for key in ["guardrail", "mode", "default_on"]: + extra_params.pop(key, None) + _guardrail_callback = _guardrail_class( guardrail_name=guardrail["guardrail_name"], event_hook=mode, default_on=default_on, + **extra_params, ) litellm.logging_callback_manager.add_litellm_callback(_guardrail_callback) # type: ignore