Secret Keys
Identifies potential API keys, secrets, and credentials in text using entropy analysis and pattern matching. Scans text for high-entropy strings that look like secrets, uses pattern matching to identify common secret formats, applies entropy analysis to detect random-looking strings, and helps prevent accidental exposure of sensitive credentials.
Supported stages
| Stage | Supported | Notes |
|---|---|---|
pre_flight |
✅ | Catch secrets accidentally pasted into user messages |
input |
✅ | Runs concurrently with the LLM call |
output |
✅ | Recommended. Prevents the LLM from leaking secrets it was given in the system prompt or context |
Configuration
{
"name": "Secret Keys",
"config": {
"threshold": "balanced",
"custom_regex": ["my-custom-[a-zA-Z0-9]{32}", "internal-[a-zA-Z0-9]{16}-key"]
}
}
Parameters
threshold(optional): Detection sensitivity level (default: "balanced")"strict"- Most sensitive, may have more false positives (commonly flag high entropy filenames or code)"balanced"- Default setting, balanced between sensitivity and specificity"permissive"- Least sensitive, may have more false negatives
custom_regex(optional): List of custom regex patterns to check for secrets
Mend Platform configuration
When a policy is loaded from the Mend Platform API the secrets guardrail is identified by "id": "secrets". The API currently carries no per-row config object for this guardrail, so it is always loaded with the SDK defaults (threshold="balanced", custom_regex=null).
Example API response row:
{
"id": "secrets",
"action": "Alert",
"status": true,
"direction": "Input",
"guardrail": "Secrets"
}
To use a non-default threshold or custom patterns, configure the guardrail through an explicit SDK policy (see Configuration above) rather than relying on the platform policy row.
Supported secrets
Detection uses two complementary approaches applied to every whitespace-separated token in the text.
Known-prefix matching
Any token whose prefix matches a well-known credential format is flagged immediately, regardless of entropy. The recognised prefixes are:
| Prefix | Credential type |
|---|---|
sk- |
OpenAI secret keys |
sk_ |
Stripe secret keys |
pk_ |
Stripe publishable keys |
pk- |
Generic private/public API keys |
ghp_ |
GitHub Personal Access Tokens |
AKIA |
AWS Access Key IDs |
xox |
Slack tokens (xoxb-, xoxp-, xoxa-, …) |
SG. |
SendGrid API keys |
hf_ |
Hugging Face access tokens |
key- |
Generic API keys |
api- |
Generic API keys |
apikey- |
Generic API keys |
token- |
Generic tokens |
secret- |
Generic secrets |
SHA: |
SHA digests used as secrets |
Bearer |
HTTP Bearer auth tokens |
Entropy-based heuristics
Tokens that do not match any known prefix are still flagged if they meet all of the threshold criteria simultaneously:
| Criterion | strict |
balanced (default) |
permissive |
|---|---|---|---|
| Minimum length (chars) | 10 | 15 | 20 |
| Minimum Shannon entropy (bits) | 3.5 | 3.8 | 4.0 |
| Minimum character-type diversity¹ | 2 | 3 | 3 |
| Ignore file extensions / URLs | No | Yes | Yes |
¹ Character-type diversity counts how many of the four character classes are present in the token: lowercase, uppercase, digits, and special characters. A value of 3 means the token must use at least three of these classes.
False-positive suppression
In balanced and permissive modes the guardrail skips tokens that look like file paths (e.g. report.pdf, config.yaml) or HTTP/HTTPS URLs, since those rarely contain actual secrets.
Custom patterns
Use custom_regex to flag credentials that follow a project-specific format. Custom patterns are checked first and bypass the entropy heuristics:
{
"name": "Secret Keys",
"config": {
"custom_regex": ["int-[a-zA-Z0-9]{32}", "corp_[A-Z0-9]{16}"]
}
}
Implementation Notes
- Pre-configured Sensitivity: Threshold values automatically set appropriate entropy, length, and diversity requirements
- Pattern Matching: Looks for common secret prefixes and formats
What It Returns
Returns a GuardrailResult with the following info dictionary:
{
"guardrail_name": "Secret Keys",
"detected_secrets": ["sk-abc123...", "Bearer xyz789..."]
}
detected_secrets: List of potential secrets detected in the text