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
Copy file name to clipboardExpand all lines: docs/guardrails/secrets.md
+32-9Lines changed: 32 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,25 +4,32 @@ title: Secret Tokens and Credentials
4
4
5
5
# Secret Tokens and Credentials
6
6
<divclass='subtitle'>
7
-
{subheading}
7
+
Prevent agents from leaking sensitive keys, tokens, and credentials.
8
8
</div>
9
9
10
-
{introduction}
10
+
Agentic systems often operate on user data, call APIs, or interface with tools and environments that require access credentials. If not properly guarded, these credentials — such as API keys, access tokens, or database secrets — can be accidentally exposed through system outputs, logs, or responses to user prompts.
11
+
12
+
This section describes how to detect and prevent the unintentional disclosure of secret tokens and credentials during agent execution.
13
+
11
14
<divclass='risks'/>
12
15
> **Secret Tokens and Credentials Risks**<br/>
13
16
> Without safeguards, agents may:
14
17
15
-
> * {reasons}
18
+
> * Leak **API keys**, **access tokens**, or **environment secrets** in responses.
19
+
20
+
> * Use user tokens in unintended ways, such as invoking third-party APIs.
21
+
22
+
> * Enable **unauthorized access** to protected systems or data sources.
16
23
17
-
{bridge}
24
+
Guardrails provide the `secrets` function that allows for detection of tokens and credentials in text, allowing you to mitigate these risks.
18
25
19
26
## secrets <spanclass="detector-badge"></span>
20
27
```python
21
28
defsecrets(
22
29
data: Union[str, List[str]]
23
30
) -> List[str]
24
31
```
25
-
Detects potentially copyrighted material in the given `data`.
32
+
This detector will detect secrets, tokens, and credentials intext andreturn a list of the types of secrets found.
26
33
27
34
**Parameters**
28
35
@@ -34,16 +41,32 @@ Detects potentially copyrighted material in the given `data`.
|`List[str]`| List of detected copyright types. For example, `["GNU_AGPL_V3", "MIT_LICENSE", ...]`|
44
+
|`List[str]`| List of detected secret types: `["GITHUB_TOKEN", "AWS_ACCESS_KEY", "AZURE_STORAGE_KEY", "SLACK_TOKEN"]`. |
38
45
39
-
### Detecting Copyrighted content
46
+
### Detecting secrets
47
+
A straightforward application of the `secrets` detector is to apply it to the content of any message, as seen here.
40
48
41
-
**Example:** Detecting Copyrighted content
49
+
**Example:** Detecting secrets inany message
42
50
```python
43
51
from invariant.detectors import secrets
44
52
45
53
raise"Found Secrets"if:
46
54
(msg: Message)
47
55
any(secrets(msg))
48
56
```
49
-
<divclass="code-caption">{little text bit}</div>
57
+
<divclass="code-caption">Raises an error if any secret token or credential is detected in the message content.</div>
58
+
59
+
60
+
61
+
### Detecting specific secret types
62
+
In some cases, you may want to detect only certain types of secrets—such as API keys for a particular service. Since the `secrets` detector returns a list of all matched secret types, you can check whether a specific type is present in the trace and handle it accordingly.
63
+
64
+
**Example:** Detecting a github token in messages
65
+
```python
66
+
from invariant.detectors import secrets
67
+
68
+
raise"Found Secrets"if:
69
+
(msg: Message)
70
+
"GITHUB_TOKEN"in secrets(msg)
71
+
```
72
+
<divclass="code-caption">Specifically check for github tokens in any message.</div>
0 commit comments