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 only

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Read the refusal message in the exception/proxy 400 body to identify the triggering policy
  2. Tune the Rubrik policy or allowlist terms if the prompt was legitimate
  3. Handle the block client-side: catch ModifyResponseException (SDK) or consume the proxy's structured guardrail error
  4. 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

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


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