BerriAI/litellm · error · ImportError

Setting tag-based guardrails is only available in litellm-en

Error message

Setting tag-based guardrails is only available in litellm-enterprise. You must be a premium user to use this feature.

What it means

When a guardrail is default_on and its event_hook is a Mode object (tag-based routing of guardrails), litellm must delegate to litellm_enterprise's EnterpriseCustomGuardrailHelper to evaluate tags. On OSS litellm that import fails and an ImportError is raised stating tag-based guardrails are a litellm-enterprise premium feature. The error is a license/edition gate, thrown at request-evaluation time in _should_run_for_event.

Source

Thrown at litellm/integrations/custom_guardrail.py:779

            self.event_hook,
            requested_guardrails,
            self.default_on,
        )
        if self.default_on is True and self.guardrail_name in opted_out_global_guardrails:
            return False

        if self.default_on is True and disable_global_guardrail is True:
            return False

        if self.default_on is True and disable_global_guardrail is not True:
            if self._event_hook_is_event_type(event_type):
                if isinstance(self.event_hook, Mode):
                    try:
                        from litellm_enterprise.integrations.custom_guardrail import (
                            EnterpriseCustomGuardrailHelper,
                        )
                    except ImportError:
                        raise ImportError(
                            "Setting tag-based guardrails is only available in litellm-enterprise. You must be a premium user to use this feature."
                        )
                    result = EnterpriseCustomGuardrailHelper._should_run_if_mode_by_tag(
                        data, self.event_hook, event_type
                    )
                    if result is not None:
                        return result
                return True
            return False

        if (
            self.event_hook
            and not self._guardrail_is_in_requested_guardrails(requested_guardrails)
            and event_type.value != "logging_only"
        ):
            return False

        if not self._event_hook_is_event_type(event_type):

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Remove the tags section from the guardrail's mode config and use plain hooks (pre_call/during_call/...) supported on OSS
  2. Install and license litellm-enterprise if tag-based guardrail selection is required
  3. Disable default_on for that guardrail and attach it explicitly per-request/per-model instead of via tags

Example fix

# before (proxy_config.yaml)
guardrails:
  - guardrail_name: my-guard
    litellm_params:
      guardrail: my-guard
      default_on: true
      mode:
        tags:
          team: ["finance"]

# after
guardrails:
  - guardrail_name: my-guard
    litellm_params:
      guardrail: my-guard
      default_on: true
      mode: during_call
Defensive patterns

Strategy: validation

Validate before calling

def enterprise_available() -> bool:
    try:
        import litellm_enterprise  # noqa: F401
        return True
    except ImportError:
        return False

uses_tags = isinstance(guardrail.event_hook, Mode)
if uses_tags and not enterprise_available():
    strip_tags_from_config()  # or refuse to start

Try / catch

try:
    guardrail._should_run_for_event(event_type, data)
except ImportError as e:
    if "litellm-enterprise" in str(e):
        remove_tag_mode_config(guardrail_name=guardrail.guardrail_name)
    raise

Prevention

When it happens

Trigger: Configuring a guardrail with default_on: true and mode specified with tags (a Mode object), then sending a request that reaches _should_run_for_event without litellm_enterprise installed and licensed.

Common situations: Copying enterprise example configs (mode with tags: {...}) into an OSS proxy deployment; previewing tag-based guardrail behavior locally without a premium key.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/21065a86135bd15e. Report an issue: GitHub.