BerriAI/litellm · error · ImportError
Guardrail implements apply_guardrail, which needs the…
Error message
Guardrail {self.guardrail_name or type(self).__name__} implements apply_guardrail, which needs the litellm proxy dependencies to run at the deployment level. Install them with: pip install 'litellm[proxy]' What it means
When a guardrail overrides apply_guardrail (the deployment-level entry point) and does not set use_native_lifecycle_hooks, _deployment_pre_call_target() must route through litellm.proxy.utils.unified_guardrail. On a base 'litellm' install lacking the proxy extra dependencies that import fails, and the chained ImportError tells you exactly which extra to install.
Solutions
- pip install 'litellm[proxy]' in the environment running the guardrail, then restart
- Or use an official litellm proxy image which already bundles the extra
- Or set use_native_lifecycle_hooks=True on the guardrail if it also implements the classic async hooks, avoiding the unified_guardrail import
Example fix
# before pip install litellm # ImportError: Guardrail X implements apply_guardrail, which needs the litellm proxy dependencies... # after pip install 'litellm[proxy]'
Defensive patterns
Strategy: validation
Validate before calling
try:
import litellm.proxy.utils # noqa: F401
except ImportError:
raise RuntimeError("apply_guardrail-style guardrails need: pip install 'litellm[proxy]'")
# safe to register the guardrail now Type guard
def proxy_extras_available() -> bool:
try:
import litellm.proxy.utils # noqa: F401
return True
except ImportError:
return False Try / catch
except ImportError as e:
if "pip install 'litellm[proxy]'" in str(e):
install the extra or fall back to a deployment with proxy deps, then restart
raise Prevention
- Deploy guardrails on images built from litellm[proxy], not the bare wheel
- Assert proxy extras import successfully in your startup healthcheck
- Set use_native_lifecycle_hooks=True only when classic hooks are genuinely implemented
When it happens
Trigger: pip install litellm (without extras) then registering an apply_guardrail-based guardrail at deployment level; SDK-only installations reused to smoke-test proxy guardrail configs; slim Docker images that strip optional deps.
Common situations: CI images built from the plain wheel; upgrading litellm via a minimal requirements.txt that drops the [proxy] extra; local dev on the SDK then deploying the same venv as a proxy.
Understand the failure class
Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.
Related errors
- MissingTrying to use Llama GuardMissing litellm-enterprise…
- Setting tag-based guardrails is only available in…
- Trying to use Google Text Moderation,This uses the…
- Trying to use OpenAI Moderations Check,This uses the…
- Trying to use Secret DetectionMissing litellm-enterprise…
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/da20b7294c3014be.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/integrations/custom_guardrail.py:643
return False
for meta_key in ("metadata", "litellm_metadata"):
meta = data.get(meta_key)
if isinstance(meta, dict):
executed = meta.get(PRE_CALL_EXECUTED_GUARDRAILS_KEY)
if isinstance(executed, list) and marker in executed:
return True
return False
def uses_apply_guardrail_interface(self) -> bool:
return type(self).apply_guardrail is not CustomGuardrail.apply_guardrail
def _deployment_pre_call_target(self) -> "CustomLogger":
if not self.uses_apply_guardrail_interface() or self.use_native_lifecycle_hooks:
return self
try:
from litellm.proxy.utils import unified_guardrail
except ImportError as e:
raise ImportError(
f"Guardrail {self.guardrail_name or type(self).__name__} implements apply_guardrail, which needs "
"the litellm proxy dependencies to run at the deployment level. "
"Install them with: pip install 'litellm[proxy]'"
) from e
return unified_guardrail
async def async_pre_call_deployment_hook(self, kwargs: dict[str, Any], call_type: CallTypes | None) -> dict | None:
from litellm.proxy._types import UserAPIKeyAuth
# should run guardrail
litellm_guardrails: Final = kwargs.get("guardrails")
if litellm_guardrails is None or not isinstance(litellm_guardrails, list):
return kwargs
if self._pre_call_hook_already_ran(kwargs):
return kwargs
if self.should_run_guardrail(data=kwargs, event_type=GuardrailEventHooks.pre_call) is not True:View on GitHub (pinned to 77b7c6c40c)