File tree Expand file tree Collapse file tree 5 files changed +89
-1
lines changed
examples/configs/sensitive_data_detection_v2
nemoguardrails/library/sensitive_data_detection Expand file tree Collapse file tree 5 files changed +89
-1
lines changed Original file line number Diff line number Diff line change 1+ # Presidio-based Sensitive Data Detection Example
2+
3+ This example demonstrates how to detect and redact sensitive data using [ Presidio] ( https://github.com/Microsoft/presidio ) .
4+
5+ ## Prerequisites
6+
7+ - ` Presidio `
8+
9+ You can install it with:
10+
11+ ``` bash
12+ poetry run pip install presidio-analyzer presidio-anonymizer
13+ ```
14+
15+ > ** Note**
16+ >
17+ > Presidio may come with an unsupported version of ` numpy ` . To reinstall the supported version, run:
18+ > ``` bash
19+ > poetry install
20+ > ` ` `
21+
22+ - ` en_core_web_lg` spaCy model
23+
24+ You can download it with:
25+
26+ ` ` ` bash
27+ poetry run python -m spacy download en_core_web_lg
28+ ```
29+
30+ ## Running example
31+
32+ To test this configuration, run the CLI chat from the ` examples/configs/sensitive_data_detection_v2 ` directory:
33+
34+ ``` bash
35+ poetry run nemoguardrails chat --config=.
36+ ```
37+
38+ ## Documentation
39+
40+ - [ Presidio-based Sensitive Data Detection configuration] ( ../../../docs/user-guides/guardrails-library.md#presidio-based-sensitive-data-detection )
41+ - [ Presidio Integration guide] ( ../../../docs/user-guides/community/presidio.md )
Original file line number Diff line number Diff line change 1+ colang_version : " 2.x"
2+
3+ models :
4+ - type : main
5+ engine : openai
6+ model : gpt-4o-mini
7+
8+ rails :
9+ config :
10+ sensitive_data_detection :
11+ input :
12+ score_threshold : 0.4
13+ entities :
14+ - PERSON
15+ - EMAIL_ADDRESS
16+ - PHONE_NUMBER
17+ - CREDIT_CARD
18+ - US_SSN
19+ - LOCATION
20+
21+ output :
22+ score_threshold : 0.4
23+ entities :
24+ - PERSON
25+ - EMAIL_ADDRESS
26+ - PHONE_NUMBER
27+ - CREDIT_CARD
28+ - US_SSN
29+ - LOCATION
Original file line number Diff line number Diff line change 1+ import guardrails
2+ import nemoguardrails.library.sensitive_data_detection
3+
4+ flow input rails $input_text
5+ """Check user utterances before they get further processed."""
6+ await mask sensitive data on input
7+
8+ flow output rails $output_text
9+ """Check response before sending it to user."""
10+ await mask sensitive data on output
Original file line number Diff line number Diff line change 1+ import core
2+ import llm
3+
4+ flow main
5+ activate llm continuation
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ flow detect sensitive data on input
1111
1212flow mask sensitive data on input
1313 """Mask any sensitive data found in the user input."""
14+ global $user_message
1415 $user_message = await MaskSensitiveDataAction(source="input", text=$user_message)
1516
1617
@@ -28,10 +29,11 @@ flow detect sensitive data on output
2829
2930flow mask sensitive data on output
3031 """Mask any sensitive data found in the bot output."""
32+ global $bot_message
3133 $bot_message = await MaskSensitiveDataAction(source="output", text=$bot_message)
3234
3335
34- # RETRIVAL RAILS
36+ # RETRIEVAL RAILS
3537
3638
3739flow detect sensitive data on retrieval
@@ -45,4 +47,5 @@ flow detect sensitive data on retrieval
4547
4648flow mask sensitive data on retrieval
4749 """Mask any sensitive data found in the relevant chunks from the knowledge base."""
50+ global $relevant_chunks
4851 $relevant_chunks = await MaskSensitiveDataAction(source="retrieval", text=$relevant_chunks)
You can’t perform that action at this time.
0 commit comments