BerriAI/litellm · error · ValueError

Microsoft Purview: guardrail_name is required

Error message

Microsoft Purview: guardrail_name is required

What it means

Config-time ValueError raised by the microsoft_purview initializer when the guardrail dict itself has no 'guardrail_name' key. Unlike the credential fields, guardrail_name lives at the top level of the guardrails list entry (sibling of litellm_params), because LiteLLM uses it to register, look up, and reference the guardrail (e.g. via the 'guardrails' parameter on a model or request).

Source

Thrown at litellm/proxy/guardrails/guardrail_hooks/microsoft_purview/__init__.py:30

    import litellm

    tenant_id: Final = getattr(litellm_params, "tenant_id", None)
    client_id: Final = getattr(litellm_params, "client_id", None)

    # client_secret can be passed via the standard api_key field or as
    # a dedicated client_secret parameter.
    client_secret: Final = litellm_params.api_key or getattr(litellm_params, "client_secret", None)

    if not tenant_id:
        raise ValueError("Microsoft Purview: tenant_id is required")
    if not client_id:
        raise ValueError("Microsoft Purview: client_id is required")
    if not client_secret:
        raise ValueError("Microsoft Purview: client_secret (or api_key) is required")

    guardrail_name: Final = guardrail.get("guardrail_name")
    if not guardrail_name:
        raise ValueError("Microsoft Purview: guardrail_name is required")

    purview_guardrail: Final = MicrosoftPurviewDLPGuardrail(
        guardrail_name=guardrail_name,
        tenant_id=str(tenant_id),
        client_id=str(client_id),
        client_secret=str(client_secret),
        purview_app_name=str(getattr(litellm_params, "purview_app_name", None) or "LiteLLM"),
        user_id_field=str(getattr(litellm_params, "user_id_field", None) or "user_id"),
        event_hook=litellm_params.mode,
        default_on=litellm_params.default_on,
    )

    litellm.logging_callback_manager.add_litellm_callback(purview_guardrail)
    return purview_guardrail


guardrail_initializer_registry: Final = {
    SupportedGuardrailIntegrations.MICROSOFT_PURVIEW.value: initialize_guardrail,

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Add 'guardrail_name' as a top-level key of the guardrail entry, next to litellm_params
  2. Give it a stable unique name — it is what deployments reference via guardrails: ["<name>"]
  3. Restart the proxy

Example fix

# before
guardrails:
  - litellm_params:
      guardrail: microsoft_purview
      tenant_id: "..."

# after
guardrails:
  - guardrail_name: purview-dlp
    litellm_params:
      guardrail: microsoft_purview
      tenant_id: "..."
Defensive patterns

Strategy: validation

Validate before calling

def guardrail_entry_valid(g: dict) -> bool:
    return (
        isinstance(g, dict)
        and isinstance(g.get("guardrail_name"), str)
        and bool(g["guardrail_name"].strip())
        and "litellm_params" in g
    )

invalid = [g for g in cfg.get("guardrails", []) if not guardrail_entry_valid(g)]

Type guard

from typing import TypedDict

class GuardrailEntry(TypedDict, total=False):
    guardrail_name: str      # required, top level
    litellm_params: dict

def is_guardrail_entry(x: object) -> bool:
    return (
        isinstance(x, dict)
        and isinstance(x.get("guardrail_name"), str)
        and x["guardrail_name"].strip() != ""
    )

Prevention

When it happens

Trigger: A guardrails list entry containing only litellm_params; misspelling the key (guardrail-name, name); nesting guardrail_name inside litellm_params where the initializer's guardrail.get() cannot see it

Common situations: Hand-writing the first Purview guardrail entry from memory; YAML indentation drift pushing guardrail_name under litellm_params; refactoring that accidentally dropped the naming key

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/b543667327f4ef8d. Report an issue: GitHub.