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
fix: properly handle custom guardrails parameters (#18978)
Harshit Jain181c626d83a0
diff --git a/litellm/proxy/guardrails/guardrail_registry.py b/litellm/proxy/guardrails/guardrail_registry.pyindex fe53fe3b32b..c3da6892209 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