SecretPatterns
Library of credential-detection patterns used by SecretLeakGuardrail.
All matching is performed via SecretType instances. Each type knows its own pattern, human-readable name, and the placeholder text to use when redacting. The built-in types share their patterns with the redaction llm4s applies to its own logs and error messages, and each takes time linear in the text.
Attributes
- Source
- SecretPatterns.scala
- Graph
-
- Supertypes
- Self type
-
SecretPatterns.type
Members list
Type members
Classlikes
A single match of a secret inside a larger string.
A single match of a secret inside a larger string.
Value parameters
- endIndex
-
Exclusive end position in the original string.
- secretType
-
The SecretType that produced this match.
- startIndex
-
Inclusive start position in the original string.
- value
-
The matched secret text (un-redacted).
Attributes
- Companion
- object
- Source
- SecretPatterns.scala
- Supertypes
Attributes
- Companion
- class
- Source
- SecretPatterns.scala
- Supertypes
- Self type
-
SecretMatch.type
A single category of secret credential.
A single category of secret credential.
The built-in types are in the companion. The class is open: an application adds its own credential format with new SecretType("Acme token", """acme_[A-Za-z0-9]{32}""".r, "[REDACTED_ACME_TOKEN]") and passes it to SecretLeakGuardrail beside the built-in ones. A pattern runs on text a model or a user supplies, so write one that takes linear time: no nested quantifiers, and no scan to the end of a run from every position in it.
Value parameters
- name
-
human-readable label used in error messages
- pattern
-
the regex that recognises this credential. When it has a capturing group, group 1 is the secret and the rest of the match is context that is kept; otherwise the whole match is
- placeholder
-
what to write in place of the secret when masking
Attributes
- Companion
- object
- Source
- SecretPatterns.scala
- Supertypes
- Known subtypes
-
object AnthropicKeyobject AwsAccessKeyobject GoogleApiKeyobject JwtTokenobject LangfuseKeyobject OpenAIKeyobject PrivateKeyPemobject VoyageKeyShow all
Attributes
- Companion
- class
- Source
- SecretPatterns.scala
- Supertypes
- Self type
-
SecretType.type
Value members
Concrete methods
Returns true if text contains at least one secret from types.
Returns true if text contains at least one secret from types.
Attributes
- Source
- SecretPatterns.scala
Find every secret in text using the supplied types (defaults to SecretType.default).
Find every secret in text using the supplied types (defaults to SecretType.default).
Attributes
- Source
- SecretPatterns.scala
Replace each matched secret with its type-specific placeholder (e.g. sk-abc... → [REDACTED_OPENAI_KEY]).
Replace each matched secret with its type-specific placeholder (e.g. sk-abc... → [REDACTED_OPENAI_KEY]).
The types are applied left to right, each to the text the ones before it left, so where two types would match the same text the earlier one in types redacts it.
Attributes
- Source
- SecretPatterns.scala
Count occurrences of each credential type in text.
Count occurrences of each credential type in text.
Attributes
- Returns
-
A map from SecretType.name to the number of matches found. Types with zero matches are omitted.
- Source
- SecretPatterns.scala
