BerriAI/litellm · warning · HTTPException

Violated content safety policy

Error message

Violated content safety policy

What it means

Raised as HTTPException 403 by the enterprise OpenAI Moderation hook when the moderation model (configured via model_name, run through the proxy's llm_router.amoderation) returns results[0].flagged = true. This is an intentional content-policy rejection using OpenAI's moderation endpoint through the proxy's own router.

Source

Thrown at enterprise/enterprise_hooks/openai_moderation.py:55

        data: dict,
        user_api_key_dict: UserAPIKeyAuth,
        call_type: CallTypesLiteral,
    ):
        # Covers multimodal list content + Responses-API input.
        text = "".join(iter_message_text(data))

        from litellm.proxy.proxy_server import llm_router

        if llm_router is None:
            return

        moderation_response = await llm_router.amoderation(
            model=self.model_name, input=text
        )

        verbose_proxy_logger.debug("Moderation response: %s", moderation_response)
        if moderation_response and moderation_response.results[0].flagged is True:
            raise HTTPException(
                status_code=403, detail={"error": "Violated content safety policy"}
            )
        pass

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Remove or rephrase the flagged content in the request.
  2. Admins: confirm the moderation model in model_name is configured in model_list (otherwise moderation silently no-ops or misroutes).
  3. Admins: if false positives dominate, switch moderation enforcement to a hook with tunable thresholds or disable the hook.
  4. Client: handle 403 as a terminal policy error — do not retry unchanged.
Defensive patterns

Strategy: try-catch

Try / catch

try:
    resp = client.chat.completions.create(model="gpt-4o", messages=msgs)
except HTTPException as e:
    if e.status_code == 403 and "content safety policy" in str(e.detail):
        raise ContentPolicyViolation(str(e.detail)) from e  # terminal
    raise

Prevention

When it happens

Trigger: A request passes the pre-call hook, llm_router is initialized (otherwise the hook silently passes), and amoderation(model=self.model_name, input=text) flags the input text. The 403 distinguishes policy violations from the 400s used elsewhere.

Common situations: moderation model name in the hook config points at a properly configured router model; users send content OpenAI's classifier flags; false positives on edgy-but-allowed content; forgetting the moderation model must exist in the router's model_list.

Related errors


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