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
|`options`|`string \| PromptCageOptions`| No | - |API key string or configuration object |
64
+
|`options`|`PromptCageOptions`| No | - |Configuration object |
42
65
|`options.apiKey`|`string`| No |`process.env.PROMPTCAGE_API_KEY`| Your PromptCage API key |
43
66
|`options.maxWaitTime`|`number`| No |`1000`| Maximum wait time in milliseconds before treating request as safe |
67
+
|`options.defaultCanaryLength`|`number`| No |`8`| Default canary word length in characters |
68
+
|`options.defaultCanaryFormat`|`string`| No |`'<!-- {canary_word} -->'`| Default format for embedding canary words (must contain `{canary_word}` placeholder) |
44
69
45
70
### detectInjection()
46
71
@@ -60,6 +85,35 @@ Detects potential prompt injection in the given text.
60
85
|`detectionId`|`string`| Unique identifier for this detection |
61
86
|`error`|`string \| undefined`| Error message if something went wrong (optional) |
62
87
88
+
### addCanaryWord()
89
+
90
+
Embeds a canary word into a prompt for injection testing.
91
+
92
+
| Parameter | Type | Required | Description |
93
+
|-----------|------|----------|-------------|
94
+
|`prompt`|`string`| Yes | The original prompt text |
95
+
|`canaryWord`|`string`| No | Specific canary word to use (auto-generated if not provided) |
96
+
|`canaryFormat`|`string`| No | Format string with `{canary_word}` placeholder (must contain `{canary_word}`) |
97
+
98
+
**Returns:**`[string, string]` - Tuple of [prompt with canary, canary word used]
99
+
100
+
### isCanaryWordLeaked()
101
+
102
+
Checks if a canary word has been leaked in an AI model's response.
103
+
104
+
| Parameter | Type | Required | Description |
105
+
|-----------|------|----------|-------------|
106
+
|`completion`|`string`| Yes | The AI model's response/completion to check |
107
+
|`canaryWord`|`string`| Yes | The canary word to look for |
108
+
109
+
**Returns:**`CanaryLeakageResult`
110
+
111
+
| Property | Type | Description |
112
+
|----------|------|-------------|
113
+
|`leaked`|`boolean`| Whether the canary word was leaked |
114
+
|`canaryWord`|`string`| The canary word that was checked |
115
+
|`error`|`string \| undefined`| Error message if the check failed (optional) |
116
+
63
117
## 🛡️ Fail-Safe Behavior
64
118
65
119
The package is designed to be **fail-safe** and will never block your application. The SDK **fails open** in all error scenarios (Network errors, Rate limit exceeded, Quota exceeded ...).
@@ -97,20 +151,22 @@ if (result.safe) {
97
151
}
98
152
```
99
153
154
+
155
+
100
156
## ⚡ Performance Considerations
101
157
102
158
The `maxWaitTime` option helps prevent performance impact on your application:
0 commit comments