BerriAI/litellm · error · GuardrailRaisedException

Sensitive data detected by {self.guardrail_name} (routing sk

Error message

Sensitive data detected by {self.guardrail_name} (routing skipped: request has no session_id)

What it means

The guardrail is configured to reroute requests containing sensitive data (sensitive_data_route_to_model), detection fired, but the request has no session_id, so raise_sensitive_data_route_exception raised ValueError. The guardrail then downgrades routing to blocking: it raises GuardrailRaisedException with '(routing skipped: request has no session_id)', which aborts the LLM call instead of rerouting it. This is the failure mode you actually see at the proxy boundary when route-mode PII handling cannot stick the session.

Source

Thrown at litellm/integrations/custom_guardrail.py:424

            request_data: The request data dictionary
            detection_info: Optional non-sensitive detection metadata. When routing,
                this is surfaced in request metadata and logs, so it must not contain
                the raw detected sensitive values.

        Raises:
            SensitiveDataRouteException: When configured to route and a session_id is present
            GuardrailRaisedException: When configured to block, or when routing is
                configured but no session_id is available
        """
        if self.should_route_on_sensitive_data():
            try:
                self.raise_sensitive_data_route_exception(
                    route_to_model=self.sensitive_data_route_to_model,
                    request_data=request_data,
                    detection_info=detection_info,
                )
            except ValueError:
                raise GuardrailRaisedException(
                    message=(
                        f"Sensitive data detected by {self.guardrail_name} (routing skipped: request has no session_id)"
                    ),
                    guardrail_name=self.guardrail_name,
                )
        else:
            raise GuardrailRaisedException(
                message=f"Sensitive data detected by {self.guardrail_name}",
                guardrail_name=self.guardrail_name,
            )

    @staticmethod
    def get_config_model() -> type["GuardrailConfigModel"] | None:
        """
        Returns the config model for the guardrail

        This is used to render the config model in the UI.
        """

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Send a session_id with every request through this guardrail (metadata={'session_id': ...} or the matching header) so routing can proceed instead of blocking
  2. Verify the guardrail's _get_session_id_from_request_data lookup keys match what your client actually sends
  3. If blocking on missing session is too strict, disable route mode (drop sensitive_data_route_to_model) and use mask mode, or catch GuardrailRaisedException upstream and retry with a session_id

Example fix

# before (client)
curl -X POST http://proxy:4000/v1/chat/completions \
  -H 'Authorization: Bearer sk-...' \
  -d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "..."}]}'

# after (client)
curl -X POST http://proxy:4000/v1/chat/completions \
  -H 'Authorization: Bearer sk-...' \
  -d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "..."}], "metadata": {"session_id": "sess-42"}}'
Defensive patterns

Strategy: try-catch

Validate before calling

from litellm.proxy.guardrails.guardrail_hooks import _get_session_id_from_request_data  # or replicate lookup

if not _get_session_id_from_request_data(request_data):
    request_data.setdefault("metadata", {})["session_id"] = str(uuid.uuid4())

Try / catch

from litellm.integrations.custom_guardrail import GuardrailRaisedException

try:
    resp = client.chat.completions.create(...)
except (Exception,) as e:
    if "routing skipped: request has no session_id" in str(e):
        retry_with_session_id(request, str(uuid.uuid4()))
    else:
        raise

Prevention

When it happens

Trigger: Guardrail config with mode/should_route_on_sensitive_data plus sensitive_data_route_to_model; sensitive data is detected; _get_session_id_from_request_data returns None (no session_id in metadata or headers). Typical with proxy /v1/chat/completions calls that omit session_id while the guardrail yaml has litellm_params.sensitive_data_route_to_model set.

Common situations: Enabling PII rerouting in proxy_config.yaml but clients (curl, LangChain, openai SDK) send no session identifier; sticky-session routing expectations after upgrading guardrail configs; testing route mode with minimal payloads.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/9f4e27790c3a8de8. Report an issue: GitHub.