Package com.tnsai.quality.security
Class SecretFilter
java.lang.Object
com.tnsai.quality.security.SecretFilter
Pre-LLM secret scrubbing filter.
Scans text for secret patterns (API keys, tokens, credentials, private keys, etc.)
and replaces matches with [REDACTED:type] placeholders. Secrets never reach
the LLM context.
Usage
// Default filter with 50+ built-in patterns
SecretFilter filter = SecretFilter.standard();
String safe = filter.scrub("My key is sk-proj-abc123xyz");
// safe == "My key is [REDACTED:openai_api_key]"
// Custom filter
SecretFilter custom = SecretFilter.builder()
.addPattern(SecretPattern.of("my-secret", "MY_SECRET_\\w+", "custom"))
.disablePattern("aws_secret_key")
.build();
- Since:
- 0.2.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for configuring a SecretFilter.static final recordResult of a scrub operation with metadata. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of active patterns.static SecretFilter.Builderbuilder()Creates a builder for configuring a SecretFilter.booleancontainsSecrets(String text) Checks if the text contains any detectable secrets.Returns all patterns (enabled and disabled).Scrubs secrets from the given text.scrubWithDetails(String text) Scrubs secrets and returns a result with metadata.static SecretFilterstandard()Creates a standard filter with all built-in patterns enabled.
-
Method Details
-
standard
Creates a standard filter with all built-in patterns enabled.- Returns:
- standard SecretFilter
-
builder
Creates a builder for configuring a SecretFilter.- Returns:
- new builder
-
scrub
Scrubs secrets from the given text.- Parameters:
text- input text (may contain secrets)- Returns:
- text with secrets replaced by placeholders
-
scrubWithDetails
Scrubs secrets and returns a result with metadata.- Parameters:
text- input text- Returns:
- scrub result with redacted text and detection info
-
containsSecrets
Checks if the text contains any detectable secrets.- Parameters:
text- text to check- Returns:
- true if secrets were detected
-
activePatternCount
public int activePatternCount()Returns the number of active patterns.- Returns:
- count of enabled patterns
-
getPatterns
Returns all patterns (enabled and disabled).- Returns:
- unmodifiable list of patterns
-