{"record":{"id":"0f380fd0c51920fa","repo":"BerriAI/litellm","slug":"violated-azure-prompt-shield-guardrail-policy","errorCode":null,"errorMessage":"Violated Azure Prompt Shield guardrail policy","messagePattern":"Violated Azure Prompt Shield guardrail policy","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"litellm/proxy/guardrails/guardrail_hooks/azure/prompt_shield.py","lineNumber":97,"sourceCode":"\n        from .base import AZURE_CONTENT_SAFETY_MAX_TEXT_LENGTH\n\n        chunks: Final = self.split_text_by_words(user_prompt, AZURE_CONTENT_SAFETY_MAX_TEXT_LENGTH)\n\n        last_response: AzurePromptShieldGuardrailResponse | None = None\n\n        for chunk in chunks:\n            request_body = AzurePromptShieldGuardrailRequestBody(documents=[], userPrompt=chunk)\n            response_json = await self._post_to_content_safety(\"text:shieldPrompt\", cast(dict, request_body))\n\n            last_response = cast(AzurePromptShieldGuardrailResponse, response_json)\n\n            if last_response[\"userPromptAnalysis\"].get(\"attackDetected\"):\n                verbose_proxy_logger.warning(\n                    \"Azure Prompt Shield: Attack detected in chunk of length %d\",\n                    len(chunk),\n                )\n                raise HTTPException(\n                    status_code=400,\n                    detail={\n                        \"error\": \"Violated Azure Prompt Shield guardrail policy\",\n                        \"detection_message\": f\"Attack detected: {last_response['userPromptAnalysis']}\",\n                    },\n                )\n\n        # chunks is always non-empty (split_text_by_words guarantees ≥1 element)\n        assert last_response is not None\n        return last_response\n\n    @log_guardrail_information\n    async def apply_guardrail(\n        self,\n        inputs: GenericGuardrailAPIInputs,\n        request_data: dict,\n        input_type: Literal[\"request\", \"response\"],\n        logging_obj: \"LiteLLMLoggingObj | None\" = None,","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_hooks/azure/prompt_shield.py#L79-L115","documentation":"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.","triggerScenarios":"Thrown at litellm/proxy/guardrails/guardrail_hooks/azure/prompt_shield.py:97 when the library encounters an invalid state.","commonSituations":"Azure Prompt Shield detected a jailbreak or injection attempt.","solutions":["Remove prompt-injection content flagged by Azure Prompt Shield and retry.","Review Prompt Shield results in Azure if the flag seems incorrect."],"exampleFix":"Inspect the flagged document/user prompt in the Azure Content Safety response.","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}