mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-05 10:24:03 +00:00
fix: properly handle custom guardrails parameters (#18978)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user