{"record":{"id":"7fded5a6de63381e","repo":"BerriAI/litellm","slug":"content-violates-policy","errorCode":null,"errorMessage":"Content violates policy","messagePattern":"Content violates policy","errorType":"exception","errorClass":"GuardrailRaisedException","httpStatus":null,"severity":"error","filePath":"litellm/proxy/guardrails/guardrail_hooks/deepkeep/deepkeep.py","lineNumber":355,"sourceCode":"\n        try:\n            response: Final = await self.async_handler.post(\n                url=self.api_base,\n                json=guardrail_request,\n                headers=headers,\n            )\n\n            response.raise_for_status()\n            response_json: Final = response.json()\n\n            verbose_proxy_logger.debug(\"DeepKeep guardrail response: %s\", response_json)\n\n            action: Final = response_json.get(\"action\", \"NONE\")\n\n            if action == \"BLOCKED\":\n                error_message: Final = response_json.get(\"blocked_reason\") or \"Content violates policy\"\n                verbose_proxy_logger.warning(\"DeepKeep guardrail blocked request: %s\", error_message)\n                raise GuardrailRaisedException(\n                    guardrail_name=GUARDRAIL_NAME,\n                    message=error_message,\n                    should_wrap_with_default_message=False,\n                )\n\n            return self._build_return_inputs(\n                response_json=response_json,\n                texts=texts,\n                images=images,\n                tools=tools,\n                tool_calls=tool_calls,\n                structured_messages=structured_messages,\n            )\n\n        except GuardrailRaisedException:\n            raise\n        except Timeout as e:\n            return self._handle_guardrail_request_error(e, inputs, input_type, logging_obj)","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_hooks/deepkeep/deepkeep.py#L337-L373","documentation":"Raised as GuardrailRaisedException when the DeepKeep firewall response contains action == \"BLOCKED\". The message is taken from the response's blocked_reason field, falling back to the generic 'Content violates policy' when the API returns a block with no reason. should_wrap_with_default_message=False means the raw message is what surfaces to the caller, typically as an HTTP 400 from the proxy.","triggerScenarios":"Any pre_call, during_call, or post_call hook invocation where the DeepKeep API scores the request/response texts, images, tools, or tool_calls as violating the firewall policy and returns {\"action\": \"BLOCKED\", ...}.","commonSituations":"Legitimate prompts tripping an over-tight firewall policy; a policy updated server-side in the DeepKeep console to block categories your users legitimately send; test prompts (jailbreak attempts, PII) run against a proxy with the guardrail attached via guardrail_name in the model's litellm_params.","solutions":["Check the proxy warning 'DeepKeep guardrail blocked request: <reason>' for the exact blocked_reason returned by DeepKeep.","Adjust the firewall policy (categories/thresholds) in the DeepKeep console for firewall_id.","If only specific traffic should be scanned, scope the guardrail with mode (pre_call/during_call/post_call) or remove guardrail_name from the litellm_params of models that should not be moderated.","Handle the resulting 400 in the client and surface the reason to the end user."],"exampleFix":"# before: client treats any failure identically\nresp = client.chat.completions.create(model='gpt-4o', messages=msgs)\n\n# after: distinguish policy blocks\nfrom litellm.exceptions import BadRequestError\ntry:\n    resp = client.chat.completions.create(model='gpt-4o', messages=msgs)\nexcept BadRequestError as e:\n    if 'Content violates policy' in str(e):\n        return {'blocked': True, 'reason': str(e)}\n    raise","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"from litellm.proxy.guardrails.guardrails import GuardrailRaisedException\n\ndef is_guardrail_block(exc: BaseException) -> bool:\n    return isinstance(exc, GuardrailRaisedException)","tryCatchPattern":"from litellm.exceptions import BadRequestError\ntry:\n    resp = client.chat.completions.create(model=model, messages=msgs)\nexcept BadRequestError as e:\n    body = getattr(e, 'message', str(e))\n    if 'Content violates policy' in body or 'blocked_reason' in body:\n        return {'blocked': True, 'reason': body}\n    raise","preventionTips":["Tune the DeepKeep firewall policy in a staging project before applying to production firewall_id.","Log blocked_reason from the 400 body to identify over-blocking patterns.","Return a user-friendly moderation message instead of forwarding the raw proxy error."],"tags":["deepkeep","guardrail","content-moderation","blocked"],"backgroundTag":"guardrail-content-blocked","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}