BerriAI/litellm · error · GuardrailRaisedException

Content violates policy

Error message

Content violates policy

What it means

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.

Source

Thrown at litellm/proxy/guardrails/guardrail_hooks/deepkeep/deepkeep.py:355

        try:
            response: Final = await self.async_handler.post(
                url=self.api_base,
                json=guardrail_request,
                headers=headers,
            )

            response.raise_for_status()
            response_json: Final = response.json()

            verbose_proxy_logger.debug("DeepKeep guardrail response: %s", response_json)

            action: Final = response_json.get("action", "NONE")

            if action == "BLOCKED":
                error_message: Final = response_json.get("blocked_reason") or "Content violates policy"
                verbose_proxy_logger.warning("DeepKeep guardrail blocked request: %s", error_message)
                raise GuardrailRaisedException(
                    guardrail_name=GUARDRAIL_NAME,
                    message=error_message,
                    should_wrap_with_default_message=False,
                )

            return self._build_return_inputs(
                response_json=response_json,
                texts=texts,
                images=images,
                tools=tools,
                tool_calls=tool_calls,
                structured_messages=structured_messages,
            )

        except GuardrailRaisedException:
            raise
        except Timeout as e:
            return self._handle_guardrail_request_error(e, inputs, input_type, logging_obj)

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Check the proxy warning 'DeepKeep guardrail blocked request: <reason>' for the exact blocked_reason returned by DeepKeep.
  2. Adjust the firewall policy (categories/thresholds) in the DeepKeep console for firewall_id.
  3. 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.
  4. Handle the resulting 400 in the client and surface the reason to the end user.

Example fix

# before: client treats any failure identically
resp = client.chat.completions.create(model='gpt-4o', messages=msgs)

# after: distinguish policy blocks
from litellm.exceptions import BadRequestError
try:
    resp = client.chat.completions.create(model='gpt-4o', messages=msgs)
except BadRequestError as e:
    if 'Content violates policy' in str(e):
        return {'blocked': True, 'reason': str(e)}
    raise
Defensive patterns

Strategy: try-catch

Type guard

from litellm.proxy.guardrails.guardrails import GuardrailRaisedException

def is_guardrail_block(exc: BaseException) -> bool:
    return isinstance(exc, GuardrailRaisedException)

Try / catch

from litellm.exceptions import BadRequestError
try:
    resp = client.chat.completions.create(model=model, messages=msgs)
except BadRequestError as e:
    body = getattr(e, 'message', str(e))
    if 'Content violates policy' in body or 'blocked_reason' in body:
        return {'blocked': True, 'reason': body}
    raise

Prevention

When it happens

Trigger: 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", ...}.

Common situations: 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.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/7fded5a6de63381e. Report an issue: GitHub.