{"record":{"id":"d489cd6074b852d0","repo":"BerriAI/litellm","slug":"violated-content-safety-policy-category-category","errorCode":null,"errorMessage":"Violated content safety policy. Category={category}","messagePattern":"Violated content safety policy\\. Category=(.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"enterprise/enterprise_hooks/google_text_moderation.py","lineNumber":120,"sourceCode":"\n            request = self.moderate_text_request(\n                document=document,\n            )\n\n            # Make the request\n            response = self.client.moderate_text(request=request)\n            for category in response.moderation_categories:\n                category_name = category.name\n                category_name = category_name.lower()\n                category_name = category_name.replace(\"&\", \"and\")\n                category_name = category_name.replace(\",\", \"\")\n                category_name = category_name.replace(\n                    \" \", \"_\"\n                )  # e.g. go from 'Firearms & Weapons' to 'firearms_and_weapons'\n                if category.confidence > getattr(\n                    self, f\"{category_name}_confidence_threshold\"\n                ):\n                    raise HTTPException(\n                        status_code=400,\n                        detail={\n                            \"error\": f\"Violated content safety policy. Category={category}\"\n                        },\n                    )\n            # Handle the response\n            return data\n\n\n# google_text_moderation_obj = _ENTERPRISE_GoogleTextModeration()\n# asyncio.run(\n#     google_text_moderation_obj.async_moderation_hook(\n#         data={\"messages\": [{\"role\": \"user\", \"content\": \"Hey, how's it going?\"}]}\n#     )\n# )\n","sourceCodeStart":102,"sourceCodeEnd":136,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/enterprise/enterprise_hooks/google_text_moderation.py#L102-L136","documentation":"Raised as HTTPException 400 by the Google Text Moderation hook when Google's moderate_text response contains a category whose confidence exceeds that category's configured threshold (default 0.8, overridable per category via model_name_threshold-style settings or google_moderation_confidence_threshold). It is an intentional content-policy rejection; the full category object (name and confidence) is included in the detail.","triggerScenarios":"A /chat/completions (or similar) request whose text Google's Natural Language API scores above the threshold for any moderation category (e.g. firearms_and_weapons, illicit_drugs) after name normalization (lowercase, '&'→'and', spaces→'_').","commonSituations":"Legitimate requests discussing sensitive topics (news, security research, medical/legal content) tripping moderation; threshold set too low (e.g. 0.5) causing frequent false positives; prompt-injection traffic being correctly filtered.","solutions":["Rewrite or remove the flagged content from the request.","Admins: raise the confidence threshold, e.g. set litellm.google_moderation_confidence_threshold higher (default 0.8) or per-category thresholds, to reduce false positives.","Inspect the category name/confidence in the error detail to see which category and how confident the classifier was.","If the hook is not needed, remove it from the proxy config."],"exampleFix":"# before\nlitellm_settings:\n  google_moderation_confidence_threshold: 0.5  # too aggressive\n\n# after\nlitellm_settings:\n  google_moderation_confidence_threshold: 0.9","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 == 400 and \"content safety policy\" in str(e.detail):\n        category = e.detail  # includes category name + confidence\n        route_to_human_review(category)  # or sanitize and retry once\n    raise","preventionTips":["Set google_moderation_confidence_threshold to 0.8+ to cut false positives.","Pre-screen sensitive-topic traffic client-side before it reaches the proxy.","Log flagged category names to tune thresholds empirically.","Do not auto-retry flagged content unchanged — classifiers are deterministic per input."],"tags":["enterprise","google-moderation","content-filter","http-400","threshold"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}