BerriAI/litellm · error · HTTPException

Violated Azure Prompt Shield guardrail policy

Error message

Violated Azure Prompt Shield guardrail policy

What it means

Raised when Azure Prompt Shield flags the (chunked) user prompt as a prompt-attack/document attack: the guardrail blocks the call because the input matches injection patterns per Azure policy.

Source

Thrown at litellm/proxy/guardrails/guardrail_hooks/azure/prompt_shield.py:97

        from .base import AZURE_CONTENT_SAFETY_MAX_TEXT_LENGTH

        chunks: Final = self.split_text_by_words(user_prompt, AZURE_CONTENT_SAFETY_MAX_TEXT_LENGTH)

        last_response: AzurePromptShieldGuardrailResponse | None = None

        for chunk in chunks:
            request_body = AzurePromptShieldGuardrailRequestBody(documents=[], userPrompt=chunk)
            response_json = await self._post_to_content_safety("text:shieldPrompt", cast(dict, request_body))

            last_response = cast(AzurePromptShieldGuardrailResponse, response_json)

            if last_response["userPromptAnalysis"].get("attackDetected"):
                verbose_proxy_logger.warning(
                    "Azure Prompt Shield: Attack detected in chunk of length %d",
                    len(chunk),
                )
                raise HTTPException(
                    status_code=400,
                    detail={
                        "error": "Violated Azure Prompt Shield guardrail policy",
                        "detection_message": f"Attack detected: {last_response['userPromptAnalysis']}",
                    },
                )

        # chunks is always non-empty (split_text_by_words guarantees ≥1 element)
        assert last_response is not None
        return last_response

    @log_guardrail_information
    async def apply_guardrail(
        self,
        inputs: GenericGuardrailAPIInputs,
        request_data: dict,
        input_type: Literal["request", "response"],
        logging_obj: "LiteLLMLoggingObj | None" = None,

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Remove prompt-injection content flagged by Azure Prompt Shield and retry.
  2. Review Prompt Shield results in Azure if the flag seems incorrect.

Example fix

Inspect the flagged document/user prompt in the Azure Content Safety response.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/proxy/guardrails/guardrail_hooks/azure/prompt_shield.py:97 when the library encounters an invalid state.

Common situations: Azure Prompt Shield detected a jailbreak or injection attempt.


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