Spaces:
Running
Running
geekyrakshit
commited on
Commit
•
2633ee9
1
Parent(s):
021c1f9
update: docs
Browse files- docs/guardrails/secrets_detection.md +3 -0
- guardrails_genie/guardrails/__init__.py +2 -1
- guardrails_genie/guardrails/secrets_detection/__init__.py +2 -2
- guardrails_genie/guardrails/secrets_detection/secrets_detection.py +1 -1
- guardrails_genie/regex_model.py +5 -4
- mkdocs.yml +1 -0
- tests/guardrails_genie/guardrails/test_secrets_detection.py +8 -7
docs/guardrails/secrets_detection.md
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# Secrets Detection
|
2 |
+
|
3 |
+
::: guardrails_genie.guardrails.secrets_detection.secrets_detection
|
guardrails_genie/guardrails/__init__.py
CHANGED
@@ -1,14 +1,15 @@
|
|
1 |
from guardrails_genie.guardrails.entity_recognition import (
|
2 |
PresidioEntityRecognitionGuardrail,
|
3 |
RegexEntityRecognitionGuardrail,
|
4 |
-
TransformersEntityRecognitionGuardrail,
|
5 |
RestrictedTermsJudge,
|
|
|
6 |
)
|
7 |
from guardrails_genie.guardrails.injection import (
|
8 |
PromptInjectionClassifierGuardrail,
|
9 |
PromptInjectionSurveyGuardrail,
|
10 |
)
|
11 |
from guardrails_genie.guardrails.secrets_detection import SecretsDetectionGuardrail
|
|
|
12 |
from .manager import GuardrailManager
|
13 |
|
14 |
__all__ = [
|
|
|
1 |
from guardrails_genie.guardrails.entity_recognition import (
|
2 |
PresidioEntityRecognitionGuardrail,
|
3 |
RegexEntityRecognitionGuardrail,
|
|
|
4 |
RestrictedTermsJudge,
|
5 |
+
TransformersEntityRecognitionGuardrail,
|
6 |
)
|
7 |
from guardrails_genie.guardrails.injection import (
|
8 |
PromptInjectionClassifierGuardrail,
|
9 |
PromptInjectionSurveyGuardrail,
|
10 |
)
|
11 |
from guardrails_genie.guardrails.secrets_detection import SecretsDetectionGuardrail
|
12 |
+
|
13 |
from .manager import GuardrailManager
|
14 |
|
15 |
__all__ = [
|
guardrails_genie/guardrails/secrets_detection/__init__.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
from guardrails_genie.guardrails.secrets_detection.secrets_detection import (
|
2 |
DEFAULT_SECRETS_PATTERNS,
|
|
|
3 |
SecretsDetectionGuardrail,
|
4 |
-
SecretsDetectionSimpleResponse,
|
5 |
SecretsDetectionResponse,
|
6 |
-
|
7 |
redact,
|
8 |
)
|
9 |
|
|
|
1 |
from guardrails_genie.guardrails.secrets_detection.secrets_detection import (
|
2 |
DEFAULT_SECRETS_PATTERNS,
|
3 |
+
REDACTION,
|
4 |
SecretsDetectionGuardrail,
|
|
|
5 |
SecretsDetectionResponse,
|
6 |
+
SecretsDetectionSimpleResponse,
|
7 |
redact,
|
8 |
)
|
9 |
|
guardrails_genie/guardrails/secrets_detection/secrets_detection.py
CHANGED
@@ -2,7 +2,7 @@ import hashlib
|
|
2 |
import json
|
3 |
import pathlib
|
4 |
from enum import Enum
|
5 |
-
from typing import
|
6 |
|
7 |
import weave
|
8 |
from pydantic import BaseModel
|
|
|
2 |
import json
|
3 |
import pathlib
|
4 |
from enum import Enum
|
5 |
+
from typing import Optional, Union
|
6 |
|
7 |
import weave
|
8 |
from pydantic import BaseModel
|
guardrails_genie/regex_model.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from typing import
|
2 |
|
3 |
import regex as re
|
4 |
import weave
|
@@ -13,11 +13,12 @@ class RegexResult(BaseModel):
|
|
13 |
|
14 |
class RegexModel(weave.Model):
|
15 |
"""
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
"""
|
|
|
21 |
patterns: Optional[Union[dict[str, str], dict[str, list[str]]]] = None
|
22 |
|
23 |
def __init__(
|
|
|
1 |
+
from typing import Optional, Union
|
2 |
|
3 |
import regex as re
|
4 |
import weave
|
|
|
13 |
|
14 |
class RegexModel(weave.Model):
|
15 |
"""
|
16 |
+
Initialize RegexModel with a dictionary of patterns.
|
17 |
|
18 |
+
Args:
|
19 |
+
patterns (Dict[str, str]): Dictionary where key is pattern name and value is regex pattern.
|
20 |
"""
|
21 |
+
|
22 |
patterns: Optional[Union[dict[str, str], dict[str, list[str]]]] = None
|
23 |
|
24 |
def __init__(
|
mkdocs.yml
CHANGED
@@ -73,6 +73,7 @@ nav:
|
|
73 |
- Prompt Injection Guardrails:
|
74 |
- Classifier Guardrail: 'guardrails/prompt_injection/classifier.md'
|
75 |
- Survey Guardrail: 'guardrails/prompt_injection/llm_survey.md'
|
|
|
76 |
- LLM: 'llm.md'
|
77 |
- Metrics: 'metrics.md'
|
78 |
- RegexModel: 'regex_model.md'
|
|
|
73 |
- Prompt Injection Guardrails:
|
74 |
- Classifier Guardrail: 'guardrails/prompt_injection/classifier.md'
|
75 |
- Survey Guardrail: 'guardrails/prompt_injection/llm_survey.md'
|
76 |
+
- Secrets Detection Guardrail: "guardrails/secrets_detection.md"
|
77 |
- LLM: 'llm.md'
|
78 |
- Metrics: 'metrics.md'
|
79 |
- RegexModel: 'regex_model.md'
|
tests/guardrails_genie/guardrails/test_secrets_detection.py
CHANGED
@@ -2,14 +2,15 @@ import hashlib
|
|
2 |
import re
|
3 |
|
4 |
import pytest
|
5 |
-
from hypothesis import given,
|
|
|
6 |
|
7 |
from guardrails_genie.guardrails.secrets_detection import (
|
8 |
DEFAULT_SECRETS_PATTERNS,
|
9 |
-
SecretsDetectionSimpleResponse,
|
10 |
-
SecretsDetectionResponse,
|
11 |
-
SecretsDetectionGuardrail,
|
12 |
REDACTION,
|
|
|
|
|
|
|
13 |
redact,
|
14 |
)
|
15 |
|
@@ -86,8 +87,8 @@ def test_redact_no_match():
|
|
86 |
|
87 |
def test_secrets_detection_guardrail_detect_types(mock_secrets_guard):
|
88 |
from guardrails_genie.guardrails.secrets_detection import (
|
89 |
-
SecretsDetectionGuardrail,
|
90 |
REDACTION,
|
|
|
91 |
)
|
92 |
|
93 |
guardrail = SecretsDetectionGuardrail(redaction=REDACTION.REDACT_ALL)
|
@@ -103,8 +104,8 @@ def test_secrets_detection_guardrail_detect_types(mock_secrets_guard):
|
|
103 |
|
104 |
def test_secrets_detection_guardrail_simple_response(mock_secrets_guard):
|
105 |
from guardrails_genie.guardrails.secrets_detection import (
|
106 |
-
SecretsDetectionGuardrail,
|
107 |
REDACTION,
|
|
|
108 |
)
|
109 |
|
110 |
guardrail = SecretsDetectionGuardrail(redaction=REDACTION.REDACT_ALL)
|
@@ -119,8 +120,8 @@ def test_secrets_detection_guardrail_simple_response(mock_secrets_guard):
|
|
119 |
|
120 |
def test_secrets_detection_guardrail_no_secrets(mock_secrets_guard):
|
121 |
from guardrails_genie.guardrails.secrets_detection import (
|
122 |
-
SecretsDetectionGuardrail,
|
123 |
REDACTION,
|
|
|
124 |
)
|
125 |
|
126 |
guardrail = SecretsDetectionGuardrail(redaction=REDACTION.REDACT_ALL)
|
|
|
2 |
import re
|
3 |
|
4 |
import pytest
|
5 |
+
from hypothesis import given, settings
|
6 |
+
from hypothesis import strategies as st
|
7 |
|
8 |
from guardrails_genie.guardrails.secrets_detection import (
|
9 |
DEFAULT_SECRETS_PATTERNS,
|
|
|
|
|
|
|
10 |
REDACTION,
|
11 |
+
SecretsDetectionGuardrail,
|
12 |
+
SecretsDetectionResponse,
|
13 |
+
SecretsDetectionSimpleResponse,
|
14 |
redact,
|
15 |
)
|
16 |
|
|
|
87 |
|
88 |
def test_secrets_detection_guardrail_detect_types(mock_secrets_guard):
|
89 |
from guardrails_genie.guardrails.secrets_detection import (
|
|
|
90 |
REDACTION,
|
91 |
+
SecretsDetectionGuardrail,
|
92 |
)
|
93 |
|
94 |
guardrail = SecretsDetectionGuardrail(redaction=REDACTION.REDACT_ALL)
|
|
|
104 |
|
105 |
def test_secrets_detection_guardrail_simple_response(mock_secrets_guard):
|
106 |
from guardrails_genie.guardrails.secrets_detection import (
|
|
|
107 |
REDACTION,
|
108 |
+
SecretsDetectionGuardrail,
|
109 |
)
|
110 |
|
111 |
guardrail = SecretsDetectionGuardrail(redaction=REDACTION.REDACT_ALL)
|
|
|
120 |
|
121 |
def test_secrets_detection_guardrail_no_secrets(mock_secrets_guard):
|
122 |
from guardrails_genie.guardrails.secrets_detection import (
|
|
|
123 |
REDACTION,
|
124 |
+
SecretsDetectionGuardrail,
|
125 |
)
|
126 |
|
127 |
guardrail = SecretsDetectionGuardrail(redaction=REDACTION.REDACT_ALL)
|