diff --git a/litellm/proxy/guardrails/guardrail_endpoints.py b/litellm/proxy/guardrails/guardrail_endpoints.py index 9bf371253fd..51071b10263 100644 --- a/litellm/proxy/guardrails/guardrail_endpoints.py +++ b/litellm/proxy/guardrails/guardrail_endpoints.py @@ -36,7 +36,7 @@ from litellm.proxy.guardrails.guardrail_hooks.custom_code.sandbox import ( ) from litellm.proxy.guardrails.guardrail_registry import ( GuardrailRegistry, - _configured_event_hooks, + configured_event_hooks, contains_encrypted_marker, decrypt_guardrail_litellm_params, encrypt_guardrail_litellm_params, @@ -1280,7 +1280,7 @@ async def patch_guardrail( clear_stored_scope: Final = ( "logging_only_scope" not in requested_litellm_params and parsed_litellm_params.logging_only_scope is not None - and GuardrailEventHooks.logging_only.value not in _configured_event_hooks(parsed_litellm_params.mode) + and GuardrailEventHooks.logging_only.value not in configured_event_hooks(parsed_litellm_params.mode) ) litellm_params: Final = ( LitellmParams(**MappingProxyType({**merged_litellm_params, "logging_only_scope": None})) diff --git a/litellm/proxy/guardrails/guardrail_initializers.py b/litellm/proxy/guardrails/guardrail_initializers.py index b7f3726d017..094c164f475 100644 --- a/litellm/proxy/guardrails/guardrail_initializers.py +++ b/litellm/proxy/guardrails/guardrail_initializers.py @@ -100,7 +100,7 @@ _MCP_EVENT_HOOKS: Final = frozenset( ) -def _configured_event_hooks(mode: str | list[str] | Mode) -> tuple[str, ...]: +def configured_event_hooks(mode: str | list[str] | Mode) -> tuple[str, ...]: if isinstance(mode, str): return (mode,) if isinstance(mode, list): @@ -114,7 +114,7 @@ def _configured_event_hooks(mode: str | list[str] | Mode) -> tuple[str, ...]: def _is_mcp_only_mode(mode: str | list[str] | Mode) -> bool: - hooks: Final = _configured_event_hooks(mode) + hooks: Final = configured_event_hooks(mode) return bool(hooks) and all(hook in _MCP_EVENT_HOOKS for hook in hooks) diff --git a/litellm/proxy/guardrails/guardrail_registry.py b/litellm/proxy/guardrails/guardrail_registry.py index 2ae5dc65888..7b2ad86f3dc 100644 --- a/litellm/proxy/guardrails/guardrail_registry.py +++ b/litellm/proxy/guardrails/guardrail_registry.py @@ -59,7 +59,7 @@ from .guardrail_hooks.llm_as_a_judge import ( initialize_guardrail as initialize_llm_as_a_judge, ) from .guardrail_initializers import ( - _configured_event_hooks, + configured_event_hooks, initialize_bedrock, initialize_hide_secrets, initialize_lakera, @@ -578,7 +578,7 @@ def _logging_only_scope_error( custom_guardrail_callback: CustomGuardrail, guardrail_name: str, litellm_params: LitellmParams ) -> str | None: logging_only_scope: Final = litellm_params.logging_only_scope - if logging_only_scope is not None and GuardrailEventHooks.logging_only.value not in _configured_event_hooks( + if logging_only_scope is not None and GuardrailEventHooks.logging_only.value not in configured_event_hooks( litellm_params.mode ): return ( @@ -823,9 +823,9 @@ class InMemoryGuardrailHandler: litellm_params: Final = LitellmParams(**params) if isinstance(params, dict) else params guardrail_name: Final = guardrail.get("guardrail_name", "Unknown") for custom_guardrail_callback in self._tracked_callbacks(guardrail_id): - error: Final = _logging_only_scope_error(custom_guardrail_callback, guardrail_name, litellm_params) - if error is not None: - raise ValueError(error) + scope_error = _logging_only_scope_error(custom_guardrail_callback, guardrail_name, litellm_params) + if scope_error is not None: + raise ValueError(scope_error) def initialize_custom_guardrail( self,