{"record":{"id":"566a33f675460387","repo":"BerriAI/litellm","slug":"sensitive-data-detected-by-self-guardrail-name-566a33","errorCode":null,"errorMessage":"Sensitive data detected by {self.guardrail_name}","messagePattern":"Sensitive data detected by (.+?)","errorType":"exception","errorClass":"GuardrailRaisedException","httpStatus":400,"severity":"error","filePath":"litellm/integrations/custom_guardrail.py","lineNumber":434,"sourceCode":"            GuardrailRaisedException: When configured to block, or when routing is\n                configured but no session_id is available\n        \"\"\"\n        if self.should_route_on_sensitive_data():\n            try:\n                self.raise_sensitive_data_route_exception(\n                    route_to_model=self.sensitive_data_route_to_model,\n                    request_data=request_data,\n                    detection_info=detection_info,\n                )\n            except ValueError:\n                raise GuardrailRaisedException(\n                    message=(\n                        f\"Sensitive data detected by {self.guardrail_name} (routing skipped: request has no session_id)\"\n                    ),\n                    guardrail_name=self.guardrail_name,\n                )\n        else:\n            raise GuardrailRaisedException(\n                message=f\"Sensitive data detected by {self.guardrail_name}\",\n                guardrail_name=self.guardrail_name,\n            )\n\n    @staticmethod\n    def get_config_model() -> type[\"GuardrailConfigModel\"] | None:\n        \"\"\"\n        Returns the config model for the guardrail\n\n        This is used to render the config model in the UI.\n        \"\"\"\n        return None\n\n    @classmethod\n    def get_supported_event_hooks(cls) -> list[GuardrailEventHooks] | None:\n        \"\"\"\n        Returns the event hooks this guardrail supports, for the UI to render.\n","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/custom_guardrail.py#L416-L452","documentation":"Default block path for sensitive data: when detection fires and the guardrail is NOT configured to reroute, _raise... raises GuardrailRaisedException('Sensitive data detected by <guardrail_name>'), aborting the call. The name in the message identifies which configured guardrail tripped.","triggerScenarios":"A masking/detection guardrail (e.g. PII, secrets, prompt-injection detector) matching content in the request while no sensitive_data_route_to_model is set; during-call hooks flagging user prompts containing credentials.","commonSituations":"Users pasting API keys or PII into prompts after a guardrail was enabled; overly broad regex/keyword rules matching benign text; enabling a strict guardrail in front of existing traffic without a tuning period.","solutions":["Remove the sensitive content from the request, or route that workload to a model/policy that permits it","Tune the guardrail's detection rules/thresholds (e.g. the regexes or entity list) to stop false positives","Catch GuardrailRaisedException at the client and return a clear policy-violation error to the end user"],"exampleFix":"# before\nresp = litellm.completion(model='gpt-4o', messages=[{'role': 'user', 'content': 'my key is sk-...'}])\n# GuardrailRaisedException: Sensitive data detected by my_pii_guard\n\n# after\ntry:\n    resp = litellm.completion(model='gpt-4o', messages=msgs)\nexcept GuardrailRaisedException as e:\n    return JSONResponse(status_code=400, content={'error': str(e)})  # policy violation to client","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = await litellm.acompletion(...)\nexcept GuardrailRaisedException as e:\n    return JSONResponse(status_code=400, content={'error': 'request blocked by policy', 'detail': str(e)})","preventionTips":["Return policy-violation responses instead of surfacing raw exceptions to users","Run guardrails in monitor/log-only mode first to tune rules","Track block rates per guardrail to catch over-broad rules"],"tags":["guardrail","sensitive-data","moderation","litellm"],"backgroundTag":"content-moderation-blocked","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}