BerriAI/litellm · error · ValueError

Azure Content Safety: api_base is required

Error message

Azure Content Safety: api_base is required

What it means

Init guard for Azure Content Safety guardrails: litellm_params.api_base is empty, so the regional Content Safety endpoint URL is unknown.

Source

Thrown at litellm/proxy/guardrails/guardrail_hooks/azure/__init__.py:18

from typing import TYPE_CHECKING, Final

from litellm.types.guardrails import SupportedGuardrailIntegrations

from .prompt_shield import AzureContentSafetyPromptShieldGuardrail
from .text_moderation import AzureContentSafetyTextModerationGuardrail

if TYPE_CHECKING:
    from litellm.types.guardrails import Guardrail, LitellmParams


def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail"):
    import litellm

    if not litellm_params.api_key:
        raise ValueError("Azure Content Safety: api_key is required")
    if not litellm_params.api_base:
        raise ValueError("Azure Content Safety: api_base is required")

    azure_guardrail: Final = litellm_params.guardrail.split("/")[1]

    guardrail_name: Final = guardrail.get("guardrail_name")
    if not guardrail_name:
        raise ValueError("Azure Content Safety: guardrail_name is required")

    if azure_guardrail == "prompt_shield":
        azure_content_safety_guardrail: (
            AzureContentSafetyPromptShieldGuardrail | AzureContentSafetyTextModerationGuardrail
        ) = AzureContentSafetyPromptShieldGuardrail(
            guardrail_name=guardrail_name,
            **{
                **litellm_params.model_dump(exclude_none=True),
                "api_key": litellm_params.api_key,
                "api_base": litellm_params.api_base,
                "default_on": litellm_params.default_on,
                "event_hook": litellm_params.mode,

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Provide the Azure Content Safety endpoint as api_base in the guardrail config.

Example fix

api_base: https://<resource>.cognitiveservices.azure.com
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/proxy/guardrails/guardrail_hooks/azure/__init__.py:18 when the library encounters an invalid state.

Common situations: Azure Content Safety guardrail configured without api_base.


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