BerriAI/litellm · error · ModifyResponseException
{refusal}
Error message
{refusal} What it means
Before the LLM call, the Rubrik guardrail moderates the prompt: it builds a prompt payload from the incoming messages, POSTs it to the prompt-moderation webhook, and if the service returns a refusal, _extract_prompt_refusal's result is raised as ModifyResponseException(message=refusal, model, request_data, guardrail_name='rubrik'). The proxy turns it into an HTTP 400-style error with the refusal text; nothing is sent to the model.
Source
Thrown at litellm/integrations/rubrik.py:378
# supplies the prompt as ``texts`` with no structured_messages.
# Synthesise a user-message so the webhook can evaluate the prompt.
texts: Final = inputs.get("texts")
if texts:
joined: Final = "\n".join(t for t in texts if t)
if joined:
messages = [{"role": "user", "content": joined}]
if not messages:
return inputs
payload: Final = self._build_prompt_moderation_payload(inputs, request_data)
service_response: Final = await self._post_to_prompt_moderation_endpoint(payload)
refusal: Final = self._extract_prompt_refusal(service_response)
if refusal is None:
return inputs
model: Final = inputs.get("model") or request_data.get("model") or "unknown"
self._stash_block_context(logging_obj, request_data)
raise ModifyResponseException(
message=refusal,
model=model,
request_data=request_data,
guardrail_name=self.guardrail_name,
)
@staticmethod
def _stash_block_context(
logging_obj: Optional["LiteLLMLoggingObj"],
request_data: dict,
) -> None:
"""Stash signals so the deferred success-event skips this request and
``async_post_call_failure_hook`` can build the failure payload.
- Sets a flag on ``logging_obj.model_call_details`` so the deferred
success-event handler short-circuits.
- Stashes a reference to ``logging_obj`` on ``request_data`` under a
custom key. ``ProxyLogging.post_call_failure_hook`` pops onlyView on GitHub (pinned to 77b7c6c40c)
Solutions
- Read the refusal message in the exception/proxy 400 body to identify the triggering policy
- Tune the Rubrik policy or allowlist terms if the prompt was legitimate
- Handle the block client-side: catch ModifyResponseException (SDK) or consume the proxy's structured guardrail error
- Use the stashed block context/logs to audit exactly which input text was flagged
Example fix
# before
resp = litellm.completion(model='gpt-4o', messages=[{'role': 'user', 'content': user_q}])
# ModifyResponseException: <refusal from rubrik>
# after
from litellm.exceptions import ModifyResponseException
try:
resp = litellm.completion(model='gpt-4o', messages=[{'role': 'user', 'content': user_q}])
except ModifyResponseException as e:
return {'blocked': True, 'reason': e.message, 'guardrail': 'rubrik'} Defensive patterns
Strategy: try-catch
Type guard
from litellm.exceptions import ModifyResponseException
def is_guardrail_block(exc: BaseException) -> bool:
return isinstance(exc, ModifyResponseException) Try / catch
from litellm.exceptions import ModifyResponseException
try:
resp = litellm.completion(model=model, messages=messages)
except ModifyResponseException as e:
return {'blocked': True, 'guardrail': 'rubrik', 'reason': e.message} Prevention
- Surface prompt-moderation refusals as user-facing 400 responses with the explanation, never as stack traces
- Track block rates per policy to spot over-broad rules
- Keep Rubrik policy tuning in the loop when legitimate prompts get rejected
When it happens
Trigger: A user prompt (or joined message content) matching a Rubrik policy in pre_call/prompt-moderation mode: the webhook answers with a refusal and litellm blocks the request before dispatch.
Common situations: Sensitive-topic policies rejecting legitimate prompts (false positives); red-team testing hitting the guardrail on purpose; prompt-injection detection rules firing on crafted inputs.
Related errors
- {blocked.explanation}
- Rubrik webhook URL not configured. Set RUBRIK_WEBHOOK_URL or
- Cannot normalize tool_call of type {type(tc).__name__}: {tc!
- {service_name} returned non-dict JSON ({type(result).__name_
- Content blocked: execution request detected
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/bd30a2d0fd3bed12.
Report an issue: GitHub.