{"record":{"id":"d8aa367d94be766b","repo":"BerriAI/litellm","slug":"custom-llm-provider-capitalize-exception-conten","errorCode":null,"errorMessage":"{custom_llm_provider.capitalize()}Exception ContentPolicyViolationError - {error_str}","messagePattern":"(.+?)Exception ContentPolicyViolationError - (.+?)","errorType":"exception","errorClass":"ContentPolicyViolationError","httpStatus":400,"severity":"error","filePath":"litellm/litellm_core_utils/exception_mapping_utils.py","lineNumber":1148,"sourceCode":"    elif \"403\" in error_str:\n        raise BadRequestError(\n            message=f\"{custom_llm_provider.capitalize()}Exception BadRequestError - {error_str}\",\n            model=model,\n            llm_provider=custom_llm_provider,\n            response=httpx.Response(\n                status_code=403,\n                request=httpx.Request(\n                    method=\"POST\",\n                    url=\" https://cloud.google.com/vertex-ai/\",\n                ),\n            ),\n            litellm_debug_info=extra_information,\n        )\n    elif (\n        \"The response was blocked.\" in error_str\n        or \"Output blocked by content filtering policy\" in error_str  # anthropic on vertex ai\n    ):\n        raise ContentPolicyViolationError(\n            message=f\"{custom_llm_provider.capitalize()}Exception ContentPolicyViolationError - {error_str}\",\n            model=model,\n            llm_provider=custom_llm_provider,\n            litellm_debug_info=extra_information,\n            response=httpx.Response(\n                status_code=400,\n                request=httpx.Request(\n                    method=\"POST\",\n                    url=\" https://cloud.google.com/vertex-ai/\",\n                ),\n            ),\n        )\n    elif (\n        \"429 Quota exceeded\" in error_str\n        or \"Quota exceeded for\" in error_str\n        or \"Resource exhausted\" in error_str\n        or \"IndexError: list index out of range\" in error_str\n        or \"429 Unable to submit request because the service is temporarily out of capacity.\" in error_str","sourceCodeStart":1130,"sourceCodeEnd":1166,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/exception_mapping_utils.py#L1130-L1166","documentation":"LiteLLM raises ContentPolicyViolationError when the Vertex AI error contains 'The response was blocked.' or 'Output blocked by content filtering policy' (the latter is the phrasing Anthropic-on-Vertex uses). The provider's safety filters refused to generate (or accept) the content. This is not a transient failure — the same input will typically be blocked again, so callers should alter the prompt or route differently rather than retry.","triggerScenarios":"A vertex_ai (or Anthropic-on-Vertex) completion whose output trips the model's safety settings / content filters: the generation was stopped mid-response and Google reports it as blocked; also possible when input safety filters reject the prompt content.","commonSituations":"Prompts touching violence, medical, or security research topics that trip Gemini safety thresholds; Anthropic models served via Vertex hitting the provider's usage policy filter; default BLOCK_MEDIUM_AND_ABOVE safety settings being too strict for the workload; agentic workflows that feed model output back and get blocked mid-chain.","solutions":["Loosen safety settings where supported: pass safety_settings with BLOCK_ONLY_HIGH / BLOCK_NONE for the offending categories (Gemini models)","Rewrite the prompt to avoid the filtered topic or reframe clinical/security content in a clearly professional context","Add a fallback model in litellm.Router (content_policy_fallbacks) so blocked requests retry on a different provider","Catch ContentPolicyViolationError and degrade gracefully (return a refusal message) instead of retrying the same input"],"exampleFix":"# before\nresp = completion(model=\"vertex_ai/gemini-1.5-pro\", messages=[...])\n# ContentPolicyViolationError - The response was blocked.\n\n# after\nfrom litellm import completion\nresp = completion(\n    model=\"vertex_ai/gemini-1.5-pro\",\n    messages=[...],\n    safety_settings=[\n        {\"category\": \"HARM_CATEGORY_HARASSMENT\", \"threshold\": \"BLOCK_ONLY_HIGH\"},\n        {\"category\": \"HARM_CATEGORY_HATE_SPEECH\", \"threshold\": \"BLOCK_ONLY_HIGH\"},\n        {\"category\": \"HARM_CATEGORY_SEXUALLY_EXPLICIT\", \"threshold\": \"BLOCK_ONLY_HIGH\"},\n        {\"category\": \"HARM_CATEGORY_DANGEROUS_CONTENT\", \"threshold\": \"BLOCK_ONLY_HIGH\"},\n    ],\n)","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"import litellm\n\ntry:\n    resp = litellm.completion(model=\"vertex_ai/gemini-1.5-pro\", messages=msgs)\nexcept litellm.ContentPolicyViolationError as e:\n    # Do not retry the same input; alter prompt or route elsewhere\n    resp = litellm.completion(model=\"gpt-4o\", messages=msgs)  # fallback provider","preventionTips":["Set safety_settings thresholds explicitly per workload instead of defaults","Configure Router content_policy_fallbacks to alternate providers","Log blocked prompts to identify systematically-filtered phrasings and rewrite them"],"tags":["litellm","vertex-ai","content-filter","safety","policy"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}