SecretPatterns

org.llm4s.util.SecretPatterns

Library of credential-detection patterns used by org.llm4s.agent.guardrails.builtin.SecretLeakGuardrail and Redaction.

All regex matching is performed via SecretType instances. Each type knows its own pattern, human-readable name, and the placeholder text to use when redacting.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

final case class SecretMatch(secretType: SecretType, value: String, startIndex: Int, endIndex: Int)

A single regex match of a secret inside a larger string.

A single regex 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

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
sealed abstract class SecretType(val name: String, val pattern: Regex, val placeholder: String)

A single category of secret credential.

A single category of secret credential.

Each instance carries:

  • name – human-readable label used in error messages
  • pattern – the scala.util.matching.Regex that recognises this credential
  • placeholder – what to write in place of the secret when masking

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object AnthropicKey
object AwsAccessKey
object GoogleApiKey
object JwtToken
object LangfuseKey
object OpenAIKey
object PrivateKeyPem
object VoyageKey
Show all
object SecretType

Attributes

Companion
class
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
SecretType.type

Value members

Concrete methods

def containsSecret(text: String, types: Seq[SecretType]): Boolean

Returns true if text contains at least one secret from types.

Returns true if text contains at least one secret from types.

Attributes

def detect(text: String, types: Seq[SecretType]): Seq[SecretMatch]

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

def redactAll(text: String, types: Seq[SecretType]): String

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]).

When multiple secrets of different types overlap, earlier matches in the type list take precedence (leftmost-longest wins within a type; types are applied left-to-right).

Attributes

def redactAllWithPlaceholder(text: String, placeholder: String, types: Seq[SecretType]): String

Replace every matched secret with the supplied uniform placeholder string (e.g. "[REDACTED]").

Replace every matched secret with the supplied uniform placeholder string (e.g. "[REDACTED]").

Useful when callers want a single marker regardless of credential type.

Attributes

def summarize(text: String, types: Seq[SecretType]): Map[String, Int]

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.