{"record":{"id":"bb7165589c297bb5","repo":"BerriAI/litellm","slug":"contentpolicyviolationerror-exception-provider","errorCode":null,"errorMessage":"ContentPolicyViolationError: {exception_provider} - {message}","messagePattern":"ContentPolicyViolationError: (.+?) - (.+?)","errorType":"exception","errorClass":"ContentPolicyViolationError","httpStatus":400,"severity":"error","filePath":"litellm/litellm_core_utils/exception_mapping_utils.py","lineNumber":325,"sourceCode":"            message=f\"{exception_provider} - {message}\",\n            llm_provider=custom_llm_provider,\n            model=model,\n            response=getattr(original_exception, \"response\", None),\n            litellm_debug_info=extra_information,\n        )\n    elif \"A timeout occurred\" in error_str:\n        raise Timeout(\n            message=f\"{exception_provider} - {message}\",\n            model=model,\n            llm_provider=custom_llm_provider,\n            litellm_debug_info=extra_information,\n        )\n    elif (\n        (\"invalid_request_error\" in error_str and \"content_policy_violation\" in error_str)\n        or (\"Invalid prompt\" in error_str and \"violating our usage policy\" in error_str)\n        or (\"request was rejected as a result of the safety system\" in error_str.lower())\n    ):\n        raise ContentPolicyViolationError(\n            message=f\"ContentPolicyViolationError: {exception_provider} - {message}\",\n            llm_provider=custom_llm_provider,\n            model=model,\n            response=getattr(original_exception, \"response\", None),\n            litellm_debug_info=extra_information,\n        )\n    elif \"invalid_encrypted_content\" in error_str or \"could not be verified\" in error_str:\n        helpful_message: Final = (\n            f\"{exception_provider} - {message}\\n\\n\"\n            \" This error occurs when load balancing Responses API across deployments with different API keys.\\n\"\n            \"   Encrypted content is tied to the organization that created it and cannot be decrypted by other organizations.\\n\\n\"\n            \"   Solution: Enable 'encrypted_content_affinity' to route follow-up requests to the correct deployment:\\n\\n\"\n            \"   router_settings:\\n\"\n            \"     enable_pre_call_checks: true\\n\"\n            \"     optional_pre_call_checks:\\n\"\n            \"       - encrypted_content_affinity\\n\\n\"\n            \"   Learn more: https://docs.litellm.ai/docs/response_api#encrypted-content-affinity-multi-region-load-balancing\"\n        )","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/exception_mapping_utils.py#L307-L343","documentation":"Normalized ContentPolicyViolationError: the provider rejected the content under its safety system. The mapping triggers on 'invalid_request_error'+'content_policy_violation', 'Invalid prompt ... violating our usage policy', or 'request was rejected as a result of the safety system' (case-insensitive). The message keeps the provider exception name and original provider text.","triggerScenarios":"Prompts or completions touching content the provider blocks: flagged keywords, certain medical/violence/adult topics, embedded URLs/domains with bad reputation, or images tripping moderation. The provider returns the matching error string and litellm re-raises this normalized type.","commonSituations":"Legitimate-but-sensitive domains (security research, healthcare, fiction) tripping filters; user-generated content forwarded unfiltered into prompts; prompt-injection or poisoned data causing systematic refusals; stricter new provider policy rolling out and previously-working prompts suddenly failing.","solutions":["Inspect the provider's message (kept in the exception) to see which part triggered it; sanitize or rephrase the offending prompt segments and avoid embedding untrusted user text verbatim.","Add pre-call moderation/filtering of user input, and post-failure handling that surfaces a friendly message instead of retrying — retrying the identical request always fails.","If the use case is policy-compliant, consider a provider/deployment with an appropriate content filter configuration (e.g. Azure content filters) and route those requests there."],"exampleFix":"# before\nlitellm.completion(model=\"gpt-4o\", messages=[{\"role\":\"user\",\"content\":raw_user_text}])\n# -> ContentPolicyViolationError\n\n# after\nfrom litellm import ContentPolicyViolationError\ntry:\n    resp = litellm.completion(model=\"gpt-4o\", messages=safe_messages(raw_user_text))\nexcept ContentPolicyViolationError:\n    return graceful_refusal()  # do NOT retry identical input","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"from litellm import ContentPolicyViolationError\n\ndef is_content_policy_error(exc: BaseException) -> bool:\n    return isinstance(exc, ContentPolicyViolationError)","tryCatchPattern":"from litellm import ContentPolicyViolationError\n\ntry:\n    resp = litellm.completion(model=m, messages=msgs)\nexcept ContentPolicyViolationError as e:\n    log_rejected_prompt(msgs, str(e))     # audit which segment triggered it\n    return polite_refusal()               # do NOT retry identical input","preventionTips":["Sanitize/rephrase untrusted user text before embedding it in prompts.","Never auto-retry this error; handle it as a permanent rejection.","Route policy-sensitive but legitimate workloads to appropriately configured filter levels."],"tags":["content-policy","moderation","exception-mapping","provider-error"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}