Skip to content

Commit f63d7d5

Browse files
committed
update secrets
1 parent 6efb32f commit f63d7d5

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

docs/guardrails/copyright.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ raise "found copyrighted code" if:
5050
}
5151
]
5252
```
53-
<div class="code-caption">{little text bit}</div>
53+
<div class="code-caption">Simple example of detecting copyright in text.</div>

docs/guardrails/secrets.md

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,32 @@ title: Secret Tokens and Credentials
44

55
# Secret Tokens and Credentials
66
<div class='subtitle'>
7-
{subheading}
7+
Prevent agents from leaking sensitive keys, tokens, and credentials.
88
</div>
99

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+
1114
<div class='risks'/>
1215
> **Secret Tokens and Credentials Risks**<br/>
1316
> Without safeguards, agents may:
1417
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.
1623
17-
{bridge}
24+
Guardrails provide the `secrets` function that allows for detection of tokens and credentials in text, allowing you to mitigate these risks.
1825

1926
## secrets <span class="detector-badge"></span>
2027
```python
2128
def secrets(
2229
data: Union[str, List[str]]
2330
) -> List[str]
2431
```
25-
Detects potentially copyrighted material in the given `data`.
32+
This detector will detect secrets, tokens, and credentials in text and return a list of the types of secrets found.
2633

2734
**Parameters**
2835

@@ -34,16 +41,32 @@ Detects potentially copyrighted material in the given `data`.
3441

3542
| Type | Description |
3643
|--------|----------------------------------------|
37-
| `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"]`. |
3845

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.
4048

41-
**Example:** Detecting Copyrighted content
49+
**Example:** Detecting secrets in any message
4250
```python
4351
from invariant.detectors import secrets
4452

4553
raise "Found Secrets" if:
4654
(msg: Message)
4755
any(secrets(msg))
4856
```
49-
<div class="code-caption">{little text bit}</div>
57+
<div class="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+
<div class="code-caption">Specifically check for github tokens in any message.</div>

0 commit comments

Comments
 (0)