{"record":{"id":"9f4e27790c3a8de8","repo":"BerriAI/litellm","slug":"sensitive-data-detected-by-self-guardrail-name","errorCode":null,"errorMessage":"Sensitive data detected by {self.guardrail_name} (routing skipped: request has no session_id)","messagePattern":"Sensitive data detected by (.+?) \\(routing skipped: request has no session_id\\)","errorType":"exception","errorClass":"GuardrailRaisedException","httpStatus":400,"severity":"error","filePath":"litellm/integrations/custom_guardrail.py","lineNumber":427,"sourceCode":"            request_data: The request data dictionary\n            detection_info: Optional non-sensitive detection metadata. When routing,\n                this is surfaced in request metadata and logs, so it must not contain\n                the raw detected sensitive values.\n\n        Raises:\n            SensitiveDataRouteException: When configured to route and a session_id is present\n            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        \"\"\"","sourceCodeStart":409,"sourceCodeEnd":445,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/custom_guardrail.py#L409-L445","documentation":"In the sensitive-data handling flow, when the guardrail is configured to reroute (should_route_on_sensitive_data() true) it calls raise_sensitive_data_route_exception; the ValueError raised for a missing session_id is caught here and converted into GuardrailRaisedException with this message, so the request is blocked outright rather than rerouted without a sticky session.","triggerScenarios":"sensitive_data_route_to_model configured, sensitive data detected, and the request lacks a session_id in metadata or headers — the inner ValueError from raise_sensitive_data_route_exception triggers this wrapper raise.","commonSituations":"Rolling out sensitive-data routing before clients send session ids; webhooks/one-shot jobs that have no conversation to bind; session id dropped by an intermediate proxy.","solutions":["Include metadata={'session_id': ...} or the session header on requests that may contain sensitive data","Catch GuardrailRaisedException client-side and retry once with a generated session_id","If sessionless traffic must pass, disable routing mode and rely on masking/blocking guardrail behavior"],"exampleFix":"# before\nresp = await litellm.acompletion(...)  # GuardrailRaisedException: routing skipped: request has no session_id\n\n# after\ntry:\n    resp = await litellm.acompletion(..., metadata={'session_id': sid})\nexcept GuardrailRaisedException:\n    sid = str(uuid4())  # mint a session and retry\n    resp = await litellm.acompletion(..., metadata={'session_id': sid})","handlingStrategy":"retry","validationCode":"meta = data.get('metadata') or {}\nif should_route and not meta.get('session_id'):\n    data['metadata'] = {**meta, 'session_id': str(uuid4())}  # mint a session before the guardrail runs","typeGuard":null,"tryCatchPattern":"try:\n    resp = await litellm.acompletion(...)\nexcept GuardrailRaisedException as e:\n    if 'no session_id' in str(e):\n        resp = await litellm.acompletion(..., metadata={'session_id': str(uuid4())})  # one retry with a session\n    else:\n        raise","preventionTips":["Always send session_id when sensitive-data routing is configured","Differentiate routing-skipped blocks from hard blocks by message content","Limit the retry to one attempt to avoid loops"],"tags":["guardrail","sensitive-data","moderation","session","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"}