BerriAI/litellm · error · GuardrailRaisedException
Sensitive data detected by
Error message
Sensitive data detected by {self.guardrail_name} What it means
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.
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
Example fix
# before
resp = litellm.completion(model='gpt-4o', messages=[{'role': 'user', 'content': 'my key is sk-...'}])
# GuardrailRaisedException: Sensitive data detected by my_pii_guard
# after
try:
resp = litellm.completion(model='gpt-4o', messages=msgs)
except GuardrailRaisedException as e:
return JSONResponse(status_code=400, content={'error': str(e)}) # policy violation to client Defensive patterns
Strategy: try-catch
Try / catch
try:
resp = await litellm.acompletion(...)
except GuardrailRaisedException as e:
return JSONResponse(status_code=400, content={'error': 'request blocked by policy', 'detail': str(e)}) Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Sensitive data detected by
- Cannot route sensitive data without a session_id. Ensure…
- {violation_message}
- CodeInterpreterInterception: no sandbox available. Provide…
- Content blocked: competitor comparison or ranking intent…
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/566a33f675460387.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/integrations/custom_guardrail.py:434
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.
"""
return None
@classmethod
def get_supported_event_hooks(cls) -> list[GuardrailEventHooks] | None:
"""
Returns the event hooks this guardrail supports, for the UI to render.
View on GitHub (pinned to 77b7c6c40c)