Implementation:BerriAI Litellm Secret Detection
| Attribute | Value |
|---|---|
| Sources | enterprise/litellm_enterprise/enterprise_callbacks/secret_detection.py |
| Domains | Security, Guardrails, Enterprise Callbacks |
| Last Updated | 2026-02-15 16:00 GMT |
Overview
_ENTERPRISE_SecretDetection is a guardrail that scans LLM request messages, prompts, and inputs for secrets and API keys, automatically redacting detected secrets with [REDACTED] before the request reaches the LLM provider.
Description
This class extends CustomGuardrail and leverages the detect-secrets library to scan user content for over 90 types of secrets and API keys. It operates as a pre-call hook in the LiteLLM proxy pipeline, intercepting requests before they are forwarded to LLM providers.
The detection engine uses a comprehensive configuration of built-in and custom secret plugins covering providers such as AWS, Azure, GitHub, GitLab, Slack, Stripe, Twilio, OpenAI, Datadog, and many more. Custom plugins are loaded from a secrets_plugins directory adjacent to the module.
The guardrail processes three types of request data:
- messages -- Chat completion message content strings
- prompt -- Direct prompt strings or lists of prompt strings
- input -- Embedding/moderation input strings or lists
The guardrail name is hide_secrets and can be disabled per-key via the permissions field on the API key.
Usage
Import and register _ENTERPRISE_SecretDetection as a callback/guardrail when you need to prevent accidental leakage of secrets in LLM request payloads.
Code Reference
Source Location
enterprise/litellm_enterprise/enterprise_callbacks/secret_detection.py
Signature
class _ENTERPRISE_SecretDetection(CustomGuardrail):
def __init__(self, detect_secrets_config: Optional[dict] = None, **kwargs): ...
def scan_message_for_secrets(self, message_content: str) -> list: ...
async def should_run_check(self, user_api_key_dict: UserAPIKeyAuth) -> bool: ...
async def async_pre_call_hook(
self,
user_api_key_dict: UserAPIKeyAuth,
cache: DualCache,
data: dict,
call_type: str,
): ...
Import
from litellm_enterprise.enterprise_callbacks.secret_detection import _ENTERPRISE_SecretDetection
I/O Contract
Inputs
| Parameter | Type | Description |
|---|---|---|
detect_secrets_config |
Optional[dict] |
Custom detect-secrets configuration. Falls back to built-in config with 90+ detectors.
|
data |
dict |
Request data containing messages, prompt, or input fields.
|
user_api_key_dict |
UserAPIKeyAuth |
API key metadata; used to check per-key guardrail permissions. |
call_type |
str |
One of "completion", "embeddings", "image_generation", "moderation".
|
Outputs
| Output | Type | Description |
|---|---|---|
| Modified data | None (in-place mutation) |
Secret values in messages, prompt, and input fields are replaced with [REDACTED].
|
| Detected secrets | list[dict] |
Each secret has type (detector name) and value (the secret string).
|
Usage Examples
# Register as a callback in LiteLLM proxy config
litellm_settings:
callbacks:
- hide_secrets
# Programmatic usage
from litellm_enterprise.enterprise_callbacks.secret_detection import _ENTERPRISE_SecretDetection
detector = _ENTERPRISE_SecretDetection()
secrets = detector.scan_message_for_secrets("My API key is sk-abc123xyz")
# Returns: [{"type": "OpenAIApiKeyDetector", "value": "sk-abc123xyz"}]
Related Pages
- BerriAI_Litellm_LLM_Guard -- LLM Guard content moderation integration
- BerriAI_Litellm_Aporia_AI_Guardrail -- Aporia AI guardrail integration
- BerriAI_Litellm_Enterprise_Custom_Guardrail -- Tag-based guardrail mode control