Skip to content

Commit ae9c0bb

Browse files
committed
add initial pii doc
1 parent 503e3a5 commit ae9c0bb

File tree

2 files changed

+188
-0
lines changed

2 files changed

+188
-0
lines changed

docs/assets/invariant.css

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
}
1111

1212

13+
/* define primary blue */
14+
:root {
15+
--primary-blue: #3d3affac;
16+
}
17+
18+
1319
body {
1420
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
1521
margin: 0;
@@ -371,6 +377,57 @@ span.llm::before {
371377
border-radius: 4pt;
372378
}
373379

380+
span.llm-badge::before {
381+
content: "LLM-based";
382+
color: white;
383+
font-size: 8pt;
384+
position: relative;
385+
top: -3pt;
386+
margin-left: 3pt;
387+
background-color: rgb(199, 130, 199);
388+
display: inline-block;
389+
height: 16pt;
390+
391+
padding: 2pt 4pt;
392+
border-radius: 4pt;
393+
}
394+
395+
span.detector-badge::before {
396+
content: "Detector";
397+
color: #eef2ff;
398+
font-size: 10pt;
399+
position: relative;
400+
top: -3pt;
401+
margin-left: 3pt;
402+
background-color: var(--primary-blue);
403+
display: inline-block;
404+
height: 18pt;
405+
406+
padding: 2pt 4pt;
407+
border-radius: 4pt;
408+
}
409+
410+
.detector-badge {
411+
position: relative;
412+
}
413+
414+
.detector-badge:hover::after {
415+
content: 'DETECTOR DESCRIPTION';
416+
position: absolute;
417+
left: 50%;
418+
transform: translateX(-50%);
419+
bottom: 100%;
420+
margin-bottom: 5px;
421+
background: rgba(0, 0, 0, 0.215);
422+
color: white;
423+
padding: 5px 10px;
424+
border-radius: 4px;
425+
font-size: 14px;
426+
white-space: nowrap;
427+
z-index: 99;
428+
pointer-events: none;
429+
}
430+
374431
.jupyter-wrapper {
375432
margin-top: -20pt;
376433
}
@@ -704,6 +761,57 @@ ul.md-nav__list {
704761
margin-top: -5pt;
705762
}
706763

764+
.md-typeset__table {
765+
width: 100%;
766+
}
767+
768+
.md-typeset__table table {
769+
width: 100%;
770+
table-layout: auto;
771+
}
772+
773+
/* Set minimum widths for the first two columns */
774+
.md-typeset__table th:nth-child(1),
775+
.md-typeset__table td:nth-child(1) {
776+
width: 15%;
777+
min-width: 100px;
778+
}
779+
780+
.md-typeset__table th:nth-child(2),
781+
.md-typeset__table td:nth-child(2) {
782+
width: 25%;
783+
min-width: 250px;
784+
}
785+
786+
/* Let the description column take up remaining space */
787+
.md-typeset__table th:nth-child(3),
788+
.md-typeset__table td:nth-child(3) {
789+
width: 60%;
790+
}
791+
792+
.function-type {
793+
display: inline-block;
794+
background: #eef2ff;
795+
color: var(--primary-blue);
796+
padding-left: 6px;
797+
padding-right: 6px;
798+
border-radius: 4px;
799+
font-size: 0.85em;
800+
margin-left: 8px;
801+
font-weight: 500;
802+
font-family: monospace;
803+
}
804+
805+
806+
.code-caption {
807+
font-size: 0.65rem;
808+
color: #666;
809+
margin-top: -0.9rem;
810+
padding-left: 4px;
811+
font-style: italic;
812+
}
813+
814+
707815
.box.secondary {
708816
position: relative;
709817
}

docs/guardrails/pii.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# PII Detection
2+
<div class='subtitle'>
3+
Detect and manage PII in traces.
4+
</div>
5+
6+
Personally Identifiable Information (PII) refers to sensitive information — like names, emails, or credit card numbers — whether intentionally or not. If not properly handled, this data can be exposed in logs, traces, or external communications, leading to privacy violations, regulatory risks, or user harm.
7+
8+
<div class='risks'/>
9+
> **PII Risks**<br/>
10+
> Without safeguards, agents may:
11+
12+
> * Log PII in traces or internal tools
13+
> * Share PII in responses or external tool calls
14+
15+
The `pii` function helps prevent these issues by scanning messages for PII, thus acting as a safeguard that lets you detect and block sensitive data before it’s stored, surfaced, or shared.
16+
17+
## pii <span class="detector-badge"/>
18+
```python
19+
def pii(
20+
data: Union[str, List[str]],
21+
entities: Optional[List[str]] = None
22+
) -> List[str]
23+
```
24+
Detector to find personally indentifaible information in text.
25+
26+
**Parameters**
27+
28+
| Name | Type | Description |
29+
|-------------|--------|----------------------------------------|
30+
| `data` | `Union[str, List[str]]` | A single message or a list of messages to detect PII in |
31+
| `entities` | `Optional[List[str]]` | A list of [PII entity types](https://microsoft.github.io/presidio/supported_entities/) to detect. Defaults to detecting all types. |
32+
33+
**Returns**
34+
35+
| Type | Description |
36+
|--------|----------------------------------------|
37+
| `List[str]` | A list of all the detected PII in `data` |
38+
39+
### Detecting PII
40+
The simplest usage of the `pii` function is to check against any message. The following example will raise an error if any message in the trace contains PII.
41+
42+
**Example:** Detecting any PII in any message.
43+
``` py
44+
from invariant.detectors import pii
45+
46+
raise "Found PII in message" if:
47+
(msg: Message)
48+
any(pii(msg))
49+
```
50+
<div class="code-caption"> Any PII in the text of the trace will raise an error. </div>
51+
52+
53+
### Detecting Specific PII Types
54+
You can also specify specific types of PII that you would like to detect, such as phone numbers, emails, or credit card information. The example below demonstrates how to detect credit card numbers in Messages.
55+
56+
**Example:** Detecting Credit Card Numbers.
57+
```guardrail
58+
from invariant.detectors import pii
59+
60+
raise "Found PII in message" if:
61+
(msg: Message)
62+
any(pii(msg, ["CREDIT_CARD"]))
63+
```
64+
<div class="code-caption"> Only messages containing credit card numbers will raise an error. </div>
65+
66+
67+
### Preventing PII leakage
68+
It is also possible to use the `pii` function in combination with other filters to get more complex behaviour. The example below shows how you can detect when an agent attempts to send emails outside of your organisation.
69+
70+
**Example:** Detecting PII Leakage in External Communications.
71+
```python
72+
from invariant.detectors import pii
73+
74+
raise "Attempted to send PII in an email" if:
75+
(out: ToolOutput) -> (call: ToolCall)
76+
any(pii(out.content))
77+
call is tool:send_email({ to: "^(?!.*@ourcompany.com$).*$" })
78+
```
79+
<div class="code-caption"> Explicitly prevent sending emails with PII to non-company email domains. </div>
80+

0 commit comments

Comments
 (0)