-
Notifications
You must be signed in to change notification settings - Fork 525
docs(examples): add Colang 2.0 example for sensitive data detection #1301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Pouyanpi
merged 2 commits into
NVIDIA:develop
from
pangeacyber:feature/sensitive_data_detection-v2-example
Aug 18, 2025
+89
−1
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Presidio-based Sensitive Data Detection Example | ||
|
||
This example demonstrates how to detect and redact sensitive data using [Presidio](https://github.com/Microsoft/presidio). | ||
|
||
## Prerequisites | ||
|
||
- `Presidio` | ||
|
||
You can install it with: | ||
|
||
```bash | ||
poetry run pip install presidio-analyzer presidio-anonymizer | ||
``` | ||
|
||
> **Note** | ||
> | ||
> Presidio may come with an unsupported version of `numpy`. To reinstall the supported version, run: | ||
> ```bash | ||
> poetry install | ||
> ``` | ||
|
||
- `en_core_web_lg` spaCy model | ||
|
||
You can download it with: | ||
|
||
```bash | ||
poetry run python -m spacy download en_core_web_lg | ||
``` | ||
|
||
## Running example | ||
|
||
To test this configuration, run the CLI chat from the `examples/configs/sensitive_data_detection_v2` directory: | ||
|
||
```bash | ||
poetry run nemoguardrails chat --config=. | ||
``` | ||
|
||
## Documentation | ||
|
||
- [Presidio-based Sensitive Data Detection configuration](../../../docs/user-guides/guardrails-library.md#presidio-based-sensitive-data-detection) | ||
- [Presidio Integration guide](../../../docs/user-guides/community/presidio.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
colang_version: "2.x" | ||
|
||
models: | ||
- type: main | ||
engine: openai | ||
model: gpt-4o-mini | ||
|
||
rails: | ||
config: | ||
sensitive_data_detection: | ||
input: | ||
score_threshold: 0.4 | ||
entities: | ||
- PERSON | ||
- EMAIL_ADDRESS | ||
- PHONE_NUMBER | ||
- CREDIT_CARD | ||
- US_SSN | ||
- LOCATION | ||
|
||
output: | ||
score_threshold: 0.4 | ||
entities: | ||
- PERSON | ||
- EMAIL_ADDRESS | ||
- PHONE_NUMBER | ||
- CREDIT_CARD | ||
- US_SSN | ||
- LOCATION |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import guardrails | ||
import nemoguardrails.library.sensitive_data_detection | ||
|
||
flow input rails $input_text | ||
"""Check user utterances before they get further processed.""" | ||
await mask sensitive data on input | ||
|
||
flow output rails $output_text | ||
"""Check response before sending it to user.""" | ||
await mask sensitive data on output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import core | ||
import llm | ||
|
||
flow main | ||
activate llm continuation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.