{"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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/exception_mapping_utils.py#L1130-L1166","documentation":"The Vertex response was blocked by safety filtering — error text 'The response was blocked.' or, for Anthropic models on Vertex, 'Output blocked by content filtering policy' — and litellm maps it to ContentPolicyViolationError with a synthetic 400 response. The model refused to generate because input or candidate output tripped the provider's safety filters.","triggerScenarios":"Prompts touching violence, self-harm, sexual or other protected categories; benign prompts that pattern-match unsafe topics (medical advice, exploit research); safety thresholds left at restrictive defaults like BLOCK_MEDIUM_AND_ABOVE; Anthropic-on-Vertex deployments with a content filtering policy attached.","commonSituations":"Legitimate domains (cybersecurity research, medicine, fiction) tripping filters; batch pipelines failing on a few flagged items with no handler for them.","solutions":["Loosen safety settings per request where the provider allows it: safety_settings=[{'category': 'HARM_CATEGORY_DANGEROUS_CONTENT', 'threshold': 'BLOCK_ONLY_HIGH'}]","Rephrase the prompt, remove flagged material, or add explicit professional/educational context","Catch ContentPolicyViolationError and route blocked items to manual review or an alternate model","For Anthropic-on-Vertex, review or adjust the content filtering policy attached to the model deployment"],"exampleFix":"# before\nlitellm.completion(\n    model='vertex_ai/gemini-1.5-pro',\n    messages=messages,  # default safety thresholds block the output\n)\n\n# after\nlitellm.completion(\n    model='vertex_ai/gemini-1.5-pro',\n    messages=messages,\n    safety_settings=[\n        {'category': 'HARM_CATEGORY_HARASSMENT', 'threshold': 'BLOCK_ONLY_HIGH'},\n        {'category': 'HARM_CATEGORY_DANGEROUS_CONTENT', 'threshold': 'BLOCK_ONLY_HIGH'},\n    ],\n)","handlingStrategy":"try-catch","validationCode":"BLOCKED_CATEGORIES = {'harm_category_harassment', 'harm_category_hate_speech',\n                     'harm_category_sexually_explicit', 'harm_category_dangerous_content'}\n\ndef soften_safety_settings(safety_settings: list[dict] | None) -> list[dict]:\n    return [\n        {'category': cat, 'threshold': 'BLOCK_ONLY_HIGH'}\n        for cat in BLOCKED_CATEGORIES\n    ]  # permissive defaults for legitimate content domains","typeGuard":"import litellm\n\ndef is_content_policy_violation(exc: BaseException) -> bool:\n    msg = str(exc)\n    return isinstance(exc, litellm.exceptions.ContentPolicyViolationError) or (\n        'The response was blocked' in msg or 'Output blocked by content filtering policy' in msg\n    )","tryCatchPattern":"import litellm\nfrom litellm.exceptions import ContentPolicyViolationError\n\ntry:\n    resp = litellm.completion(model='vertex_ai/gemini-1.5-pro', messages=messages)\nexcept ContentPolicyViolationError:\n    # never retry the same payload: route to review or an alternate model\n    flag_for_human_review(messages)\n    raise","preventionTips":["Set permissive-but-safe thresholds (BLOCK_ONLY_HIGH) for legitimate sensitive domains","Never auto-retry content-policy blocks — the same payload will block again","Design pipelines to quarantine blocked items instead of failing the whole batch"],"tags":["vertex-ai","gcp","content-filter","safety","moderation","litellm"],"backgroundTag":"content-filter-blocked","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}