Secrets Detection
REDACTION
Bases: str
, Enum
Enum for different types of redaction methods.
Source code in guardrails_genie/guardrails/secrets_detection/secrets_detection.py
SecretsDetectionGuardrail
Bases: Guardrail
A guardrail for detecting secrets in text using regex patterns. reference: SecretBench: A Dataset of Software Secrets https://arxiv.org/abs/2303.06729
Attributes:
Name | Type | Description |
---|---|---|
regex_model |
RegexModel
|
The regex model used for detection. |
patterns |
Union[dict[str, str], dict[str, list[str]]]
|
The patterns used for detection. |
redaction |
REDACTION
|
The type of redaction to apply. |
Source code in guardrails_genie/guardrails/secrets_detection/secrets_detection.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
__init__(use_defaults=True, redaction=REDACTION.REDACT_ALL, **kwargs)
Initialize the SecretsDetectionGuardrail.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
use_defaults
|
bool
|
Whether to use default patterns. |
True
|
redaction
|
REDACTION
|
The type of redaction to apply. |
REDACT_ALL
|
**kwargs
|
Additional keyword arguments. |
{}
|
Source code in guardrails_genie/guardrails/secrets_detection/secrets_detection.py
guard(prompt, return_detected_secrets=True, **kwargs)
Check if the input prompt contains any secrets based on the regex patterns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
str
|
Input text to check for secrets. |
required |
return_detected_secrets
|
bool
|
If True, returns detailed secrets type information. |
True
|
Returns:
Type | Description |
---|---|
SecretsDetectionResponse | SecretsDetectionResponse
|
SecretsDetectionResponse or SecretsDetectionResponse: Detection results. |
Source code in guardrails_genie/guardrails/secrets_detection/secrets_detection.py
SecretsDetectionResponse
Bases: SecretsDetectionSimpleResponse
A detailed response model for secrets detection.
Attributes:
Name | Type | Description |
---|---|---|
detected_secrets |
dict[str, list[str]]
|
Dictionary of detected secrets. |
Source code in guardrails_genie/guardrails/secrets_detection/secrets_detection.py
SecretsDetectionSimpleResponse
Bases: BaseModel
A simple response model for secrets detection.
Attributes:
Name | Type | Description |
---|---|---|
contains_secrets |
bool
|
Indicates if secrets were detected. |
explanation |
str
|
Explanation of the detection result. |
redacted_text |
Optional[str]
|
The redacted text if secrets were found. |
Source code in guardrails_genie/guardrails/secrets_detection/secrets_detection.py
safe: bool
property
Property to check if the text is safe (no secrets detected).
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if no secrets were detected, False otherwise. |
load_secrets_patterns()
Load secret patterns from a JSONL file and return them as a dictionary.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict[str, list[str]]
|
A dictionary where keys are pattern names and values are lists of regex patterns. |
Source code in guardrails_genie/guardrails/secrets_detection/secrets_detection.py
redact(text, matches, redaction_type)
Redact the given matches in the text based on the redaction type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
The input text to redact. |
required |
matches
|
list[str]
|
List of strings to be redacted. |
required |
redaction_type
|
REDACTION
|
The type of redaction to apply. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The redacted text. |