BerriAI/litellm · error · GuardrailRaisedException

Content violates policy

Error message

Content violates policy

What it means

GuardrailRaisedException raised when the generic guardrail service response parses to action == 'BLOCKED' (via GenericGuardrailAPIResponse.from_dict). The message is blocked_reason from the response, or the fallback 'Content violates policy' when the service blocks without a reason. should_wrap_with_default_message=False forwards the message verbatim; the proxy returns it as a 400 to the caller.

Source

Thrown at litellm/proxy/guardrails/guardrail_hooks/generic_guardrail_api/generic_guardrail_api.py:463

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

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

            verbose_proxy_logger.debug("Generic Guardrail API response: %s", response_json)

            guardrail_response: Final = GenericGuardrailAPIResponse.from_dict(response_json)

            # Handle the response
            if guardrail_response.action == "BLOCKED":
                # Block the request
                error_message: Final = guardrail_response.blocked_reason or "Content violates policy"
                verbose_proxy_logger.warning("Generic Guardrail API blocked request: %s", error_message)
                raise GuardrailRaisedException(
                    guardrail_name=GUARDRAIL_NAME,
                    message=error_message,
                    should_wrap_with_default_message=False,
                )

            return self._build_guardrail_return_inputs(
                texts=texts,
                images=images,
                tools=tools,
                guardrail_response=guardrail_response,
            )

        except GuardrailRaisedException:
            raise
        except Timeout as e:
            return self._handle_guardrail_request_error(e, inputs, input_type, logging_obj)
        except httpx.HTTPStatusError as e:
            status_code: Final = getattr(getattr(e, "response", None), "status_code", None)

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Check the proxy warning 'Generic Guardrail API blocked request: <reason>' for the service-supplied reason.
  2. Update the block rules/thresholds in your guardrail service so the flagged content passes.
  3. Ensure the service always returns blocked_reason — the fallback message carries no diagnostics.
  4. Scope the guardrail by mode or model attachment if only some traffic should be moderated.

Example fix

# before: server response omits reason
{"action": "BLOCKED"}

# after: always include a reason
{"action": "BLOCKED", "blocked_reason": "PII detected: email address"}
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:
    if 'Content violates policy' in str(e):
        return {'blocked': True, 'reason': str(e)}
    raise

Prevention

When it happens

Trigger: Any configured hook (pre_call/during_call/post_call) where the generic guardrail service evaluates the texts/images/tools/tool_calls payload and responds with action BLOCKED.

Common situations: Custom moderation service flagging legitimate traffic after a policy update; a new deployment whose block rules are stricter than the legacy ones it replaced; users probing the guardrail to see what is rejected.

Related errors


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