{"record":{"id":"80a28b2cf44870fd","repo":"BerriAI/litellm","slug":"violated-content-safety-policy","errorCode":null,"errorMessage":"Violated content safety policy","messagePattern":"Violated content safety policy","errorType":"http","errorClass":"HTTPException","httpStatus":403,"severity":"warning","filePath":"enterprise/enterprise_hooks/openai_moderation.py","lineNumber":55,"sourceCode":"        data: dict,\n        user_api_key_dict: UserAPIKeyAuth,\n        call_type: CallTypesLiteral,\n    ):\n        # Covers multimodal list content + Responses-API input.\n        text = \"\".join(iter_message_text(data))\n\n        from litellm.proxy.proxy_server import llm_router\n\n        if llm_router is None:\n            return\n\n        moderation_response = await llm_router.amoderation(\n            model=self.model_name, input=text\n        )\n\n        verbose_proxy_logger.debug(\"Moderation response: %s\", moderation_response)\n        if moderation_response and moderation_response.results[0].flagged is True:\n            raise HTTPException(\n                status_code=403, detail={\"error\": \"Violated content safety policy\"}\n            )\n        pass\n","sourceCodeStart":37,"sourceCodeEnd":59,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/enterprise/enterprise_hooks/openai_moderation.py#L37-L59","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = client.chat.completions.create(model=\"gpt-4o\", messages=msgs)\nexcept HTTPException as e:\n    if e.status_code == 403 and \"content safety policy\" in str(e.detail):\n        raise ContentPolicyViolation(str(e.detail)) from e  # terminal\n    raise","preventionTips":["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."],"tags":["enterprise","openai-moderation","content-filter","http-403"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}