{"record":{"id":"da20b7294c3014be","repo":"BerriAI/litellm","slug":"guardrail-self-guardrail-name-or-type-self-nam","errorCode":null,"errorMessage":"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]'","messagePattern":"Guardrail (.+?) implements apply_guardrail, which needs the litellm proxy dependencies to run at the deployment level\\. Install them with: pip install 'litellm\\[proxy\\]'","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"litellm/integrations/custom_guardrail.py","lineNumber":643,"sourceCode":"            return False\n        for meta_key in (\"metadata\", \"litellm_metadata\"):\n            meta = data.get(meta_key)\n            if isinstance(meta, dict):\n                executed = meta.get(PRE_CALL_EXECUTED_GUARDRAILS_KEY)\n                if isinstance(executed, list) and marker in executed:\n                    return True\n        return False\n\n    def uses_apply_guardrail_interface(self) -> bool:\n        return type(self).apply_guardrail is not CustomGuardrail.apply_guardrail\n\n    def _deployment_pre_call_target(self) -> \"CustomLogger\":\n        if not self.uses_apply_guardrail_interface() or self.use_native_lifecycle_hooks:\n            return self\n        try:\n            from litellm.proxy.utils import unified_guardrail\n        except ImportError as e:\n            raise ImportError(\n                f\"Guardrail {self.guardrail_name or type(self).__name__} implements apply_guardrail, which needs \"\n                \"the litellm proxy dependencies to run at the deployment level. \"\n                \"Install them with: pip install 'litellm[proxy]'\"\n            ) from e\n        return unified_guardrail\n\n    async def async_pre_call_deployment_hook(self, kwargs: dict[str, Any], call_type: CallTypes | None) -> dict | None:\n        from litellm.proxy._types import UserAPIKeyAuth\n\n        # should run guardrail\n        litellm_guardrails: Final = kwargs.get(\"guardrails\")\n        if litellm_guardrails is None or not isinstance(litellm_guardrails, list):\n            return kwargs\n\n        if self._pre_call_hook_already_ran(kwargs):\n            return kwargs\n\n        if self.should_run_guardrail(data=kwargs, event_type=GuardrailEventHooks.pre_call) is not True:","sourceCodeStart":625,"sourceCodeEnd":661,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/custom_guardrail.py#L625-L661","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\npip install litellm\n# ImportError: Guardrail X implements apply_guardrail, which needs the litellm proxy dependencies...\n\n# after\npip install 'litellm[proxy]'","handlingStrategy":"validation","validationCode":"try:\n    import litellm.proxy.utils  # noqa: F401\nexcept ImportError:\n    raise RuntimeError(\"apply_guardrail-style guardrails need: pip install 'litellm[proxy]'\")\n\n# safe to register the guardrail now","typeGuard":"def proxy_extras_available() -> bool:\n    try:\n        import litellm.proxy.utils  # noqa: F401\n        return True\n    except ImportError:\n        return False","tryCatchPattern":"except ImportError as e:\n    if \"pip install 'litellm[proxy]'\" in str(e):\n        install the extra or fall back to a deployment with proxy deps, then restart\n    raise","preventionTips":["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"],"tags":["importerror","optional-dependency","proxy","guardrail","installation","litellm"],"backgroundTag":"missing-optional-dependency","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}