{"record":{"id":"560c2c2c2acda861","repo":"BerriAI/litellm","slug":"violated-content-safety-policy-560c2c","errorCode":null,"errorMessage":"Violated content safety policy","messagePattern":"Violated content safety policy","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"enterprise/litellm_enterprise/enterprise_callbacks/llm_guard.py","lineNumber":81,"sourceCode":"                analyze_url = f\"{self.llm_guard_api_base}analyze/prompt\"\n                verbose_proxy_logger.debug(\"Making request to: %s\", analyze_url)\n                async with aiohttp.ClientSession() as session:\n                    async with session.post(\n                        analyze_url, json={\"prompt\": text}\n                    ) as response:\n                        redacted_text = await response.json()\n            verbose_proxy_logger.debug(\n                f\"LLM Guard: Received response - {redacted_text}\"\n            )\n            if redacted_text is None:\n                raise HTTPException(\n                    status_code=500,\n                    detail={\n                        \"error\": f\"Invalid content moderation response: {redacted_text}\"\n                    },\n                )\n            if redacted_text.get(\"is_valid\", None) is False:\n                raise HTTPException(\n                    status_code=400,\n                    detail={\"error\": \"Violated content safety policy\"},\n                )\n            sanitized_prompt = redacted_text.get(\"sanitized_prompt\")\n            return sanitized_prompt if isinstance(sanitized_prompt, str) else text\n        except Exception as e:\n            verbose_proxy_logger.exception(\n                \"litellm.enterprise.enterprise_hooks.llm_guard::moderation_check - Exception occurred - {}\".format(\n                    str(e)\n                )\n            )\n            raise e\n\n    def should_proceed(self, user_api_key_dict: UserAPIKeyAuth, data: dict) -> bool:\n        if self.llm_guard_mode == \"key-specific\":\n            # check if llm guard enabled for specific keys only\n            self.print_verbose(\n                f\"user_api_key_dict.permissions: {user_api_key_dict.permissions}\"","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/enterprise/litellm_enterprise/enterprise_callbacks/llm_guard.py#L63-L99","documentation":"Raised as HTTPException 400 by LLM Guard's moderation_check when the service's JSON response has is_valid: false, meaning the input prompt failed LLM Guard's sanitization/validation checks (prompt injection detection, input scanners). This is an intentional content-policy rejection. Note the surrounding try/except re-raises after logging via verbose_proxy_logger.exception.","triggerScenarios":"A request whose prompt text triggers LLM Guard's input scanners (e.g. PromptInjection scanner, secrets/anonymizer scanners), causing the /analyze/prompt response JSON to contain is_valid=false.","commonSituations":"Users pasting text that looks like prompt injection ('ignore previous instructions...'); legitimate content containing API keys/secrets being caught by the secrets scanner; scanner sensitivity set high in the LLM Guard deployment.","solutions":["Remove the offending content (injection-like phrasing, embedded secrets/PII) from the prompt.","Admins: tune the LLM Guard deployment's scanners (thresholds, enabled scanners) rather than disabling the hook wholesale.","Check the LLM Guard service logs to see which scanner produced is_valid=false.","Client: treat the 400 as terminal for this payload — retrying unchanged will fail again."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    sanitized = await moderation_check(text)\nexcept HTTPException as e:\n    if e.status_code == 400 and \"content safety policy\" in str(e.detail):\n        raise PromptRejectedByLLMGuard(text_hint=\"possible injection/secrets\") from e\n    raise","preventionTips":["Strip obvious prompt-injection phrasing and secrets from user input before sending.","Tune LLM Guard scanner thresholds server-side to reduce false positives.","Log rejected prompts (safely) to identify which scanner fires most.","Treat the 400 as terminal — identical payloads will always be rejected."],"tags":["enterprise","llm-guard","content-filter","http-400","prompt-injection"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}