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
- Remove or rephrase the flagged content in the request.
- Admins: confirm the moderation model in model_name is configured in model_list (otherwise moderation silently no-ops or misroutes).
- Admins: if false positives dominate, switch moderation enforcement to a hook with tunable thresholds or disable the hook.
- 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
- Ensure the moderation model name in the hook exists in model_list.
- Handle 403 distinctly from 5xx: it is a policy verdict, never retryable as-is.
- Surface the violation to the end user with guidance instead of a generic failure.
- Track per-user violation rates to find accounts sending flagged content.
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
- Keyword banned. Keyword={word}
- Violated content safety policy. Category={category}
- Violated content safety policy
- Violated content safety policy
- Only premium users can add tags to projects. You must be a L
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/80a28b2cf44870fd.
Report an issue: GitHub.