You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add pii masking capability to private ai integration (#901)
* Add tests for private ai pii masking
* Add pii masking action and flow for private ai
* Update private ai docs to add pii masking
* Add private ai pii masking example config
* Add private ai pii masking example in notebook
* Apply suggestions from code review
Co-authored-by: Pouyan <13303554+Pouyanpi@users.noreply.github.com>
Signed-off-by: Girish Sharma <girishsharma001@gmail.com>
* Test private ai with live api instead of mocked detector
* Improve error handling for private ai
---------
Signed-off-by: Girish Sharma <girishsharma001@gmail.com>
Co-authored-by: Pouyan <13303554+Pouyanpi@users.noreply.github.com>
Copy file name to clipboardExpand all lines: docs/user-guides/community/privateai.md
+38-7Lines changed: 38 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,15 @@
1
1
# Private AI Integration
2
2
3
-
[Private AI](https://docs.private-ai.com/?utm_medium=github&utm_campaign=nemo-guardrails) allows you to detect and mask Personally Identifiable Information (PII) in your data. This integration enables NeMo Guardrails to use Private AI for PII detection in input, output and retrieval flows.
3
+
[Private AI](https://docs.private-ai.com/?utm_medium=github&utm_campaign=nemo-guardrails) allows you to detect and mask Personally Identifiable Information (PII) in your data. This integration enables NeMo Guardrails to use Private AI for PII detection and masking in input, output, and retrieval flows.
4
4
5
5
## Setup
6
6
7
7
1. Ensure that you have access to Private AI API server running locally or in the cloud. To get started with the cloud version, you can use the [Private AI Portal](https://portal.private-ai.com/?utm_medium=github&utm_campaign=nemo-guardrails). For containerized deployments, check out this [Quickstart Guide](https://docs.private-ai.com/quickstart/?utm_medium=github&utm_campaign=nemo-guardrails).
8
8
9
9
2. Update your `config.yml` file to include the Private AI settings:
10
10
11
+
**PII detection config**
12
+
11
13
```yaml
12
14
rails:
13
15
config:
@@ -31,19 +33,48 @@ rails:
31
33
- detect pii on output
32
34
```
33
35
36
+
The detection flow will not let the input/output/retrieval text pass if PII is detected.
37
+
38
+
**PII masking config**
39
+
40
+
```yaml
41
+
rails:
42
+
config:
43
+
privateai:
44
+
server_endpoint: http://your-privateai-api-endpoint/process/text # Replace this with your Private AI process text endpoint
45
+
input:
46
+
entities: # If no entity is specified here, all supported entities will be detected by default.
47
+
- NAME_FAMILY
48
+
- LOCATION_ADDRESS_STREET
49
+
- EMAIL_ADDRESS
50
+
output:
51
+
entities:
52
+
- NAME_FAMILY
53
+
- LOCATION_ADDRESS_STREET
54
+
- EMAIL_ADDRESS
55
+
input:
56
+
flows:
57
+
- mask pii on input
58
+
output:
59
+
flows:
60
+
- mask pii on output
61
+
```
62
+
63
+
The masking flow will mask the PII in the input/output/retrieval text before they are sent to the LLM/user. For example, `Hi John Doe, my email is john.doe@example.com` will be converted to `Hi [NAME], my email is [EMAIL_ADDRESS]`.
64
+
34
65
Replace `http://your-privateai-api-endpoint/process/text` with your actual Private AI process text endpoint and set the `PAI_API_KEY` environment variable if you're using the Private AI cloud API.
35
66
36
67
3. You can customize the `entities` list under both `input` and `output` to include the PII types you want to detect. A full list of supported entities can be found [here](https://docs.private-ai.com/entities/?utm_medium=github&utm_campaign=nemo-guardrails).
37
68
38
69
## Usage
39
70
40
-
Once configured, the Private AI integration will automatically:
71
+
Once configured, the Private AI integration can automatically:
41
72
42
-
1. Detect PII in user inputs before they are processed by the LLM.
43
-
2. Detect PII in LLM outputs before they are sent back to the user.
44
-
3. Detect PII in retrieved chunks before they are sent to the LLM.
73
+
1. Detect or mask PII in user inputs before they are processed by the LLM.
74
+
2. Detect or mask PII in LLM outputs before they are sent back to the user.
75
+
3. Detect or mask PII in retrieved chunks before they are sent to the LLM.
45
76
46
-
The `detect_pii` action in `nemoguardrails/library/privateai/actions.py` handles the PII detection process.
77
+
The `detect_pii` and `mask_pii` actions in `nemoguardrails/library/privateai/actions.py` handle the PII detection and masking processes, respectively.
47
78
48
79
## Customization
49
80
@@ -56,6 +87,6 @@ If the Private AI detection API request fails, the system will assume PII is pre
56
87
## Notes
57
88
58
89
- Ensure that your Private AI process text endpoint is properly set up and accessible from your NeMo Guardrails environment.
59
-
- The integration currently supports PII detection only.
90
+
- The integration currently supports PII detection and masking.
60
91
61
92
For more information on Private AI and its capabilities, please refer to the [Private AI documentation](https://docs.private-ai.com/?utm_medium=github&utm_campaign=nemo-guardrails).
Copy file name to clipboardExpand all lines: docs/user-guides/guardrails-library.md
+8-31Lines changed: 8 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -750,9 +750,9 @@ For more details, check out the [GCP Text Moderation](https://github.com/NVIDIA/
750
750
751
751
### Private AI PII Detection
752
752
753
-
NeMo Guardrails supports using [Private AI API](https://docs.private-ai.com/?utm_medium=github&utm_campaign=nemo-guardrails) for PII detection in input, output and retrieval flows.
753
+
NeMo Guardrails supports using [Private AI API](https://docs.private-ai.com/?utm_medium=github&utm_campaign=nemo-guardrails) for PII detection and masking input, output and retrieval flows.
754
754
755
-
To activate the PII detection, you need specify `server_endpoint`, and the entities that you want to detect. You'll also need to set the `PAI_API_KEY` environment variable if you're using the Private AI cloud API.
755
+
To activate the PII detection or masking, you need specify `server_endpoint`, and the entities that you want to detect or mask. You'll also need to set the `PAI_API_KEY` environment variable if you're using the Private AI cloud API.
756
756
757
757
```yaml
758
758
rails:
@@ -773,6 +773,8 @@ rails:
773
773
774
774
#### Example usage
775
775
776
+
**PII detection**
777
+
776
778
```yaml
777
779
rails:
778
780
input:
@@ -786,44 +788,19 @@ rails:
786
788
- detect pii on retrieval
787
789
```
788
790
789
-
For more details, check out the [Private AI Integration](https://github.com/NVIDIA/NeMo-Guardrails/blob/develop/docs/user-guides/community/privateai.md) page.
790
-
791
-
### Private AI PII Detection
792
-
793
-
NeMo Guardrails supports using [Private AI API](https://docs.private-ai.com/?utm_medium=github&utm_campaign=nemo-guardrails) for PII detection in input, output and retrieval flows.
794
-
795
-
To activate the PII detection, you need specify `server_endpoint`, and the entities that you want to detect. You'll also need to set the `PAI_API_KEY` environment variable if you're using the Private AI cloud API.
796
-
797
-
```yaml
798
-
rails:
799
-
config:
800
-
privateai:
801
-
server_endpoint: http://your-privateai-api-endpoint/process/text # Replace this with your Private AI process text endpoint
802
-
input:
803
-
entities: # If no entity is specified here, all supported entities will be detected by default.
804
-
- NAME_FAMILY
805
-
- EMAIL_ADDRESS
806
-
...
807
-
output:
808
-
entities:
809
-
- NAME_FAMILY
810
-
- EMAIL_ADDRESS
811
-
...
812
-
```
813
-
814
-
#### Example usage
791
+
**PII masking**
815
792
816
793
```yaml
817
794
rails:
818
795
input:
819
796
flows:
820
-
- detect pii on input
797
+
- mask pii on input
821
798
output:
822
799
flows:
823
-
- detect pii on output
800
+
- mask pii on output
824
801
retrieval:
825
802
flows:
826
-
- detect pii on retrieval
803
+
- mask pii on retrieval
827
804
```
828
805
829
806
For more details, check out the [Private AI Integration](./community/privateai.md) page.
0 commit comments