@sandrobuilds/tracerney 0.9.20 → 0.9.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +103 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -81,6 +81,109 @@ if (result.suspicious) {
81
81
  - **Structured threat metadata** — detailed fingerprints for audit trails and tracking
82
82
  - **Advanced rate limiting** — prevents cost spikes with intelligent throttling
83
83
 
84
+ ## Layer 2: LLM Sentinel Deep Dive
85
+
86
+ Layer 2 adds advanced security with LLM Sentinel, an AI-powered verification system that analyzes LLM responses for injection patterns and validates output safety. Combines local pattern detection (Layer 1) with server-side verification for defense-in-depth protection.
87
+
88
+ ### How Layer 1 & Layer 2 Work Together
89
+
90
+ | **Layer 1: Pattern Detection (Free SDK)** | **Layer 2: LLM Sentinel (Pro)** |
91
+ |---|---|
92
+ | Local pattern matching | Server-side verification |
93
+ | 258 attack patterns | Output validation |
94
+ | <5ms latency | JSON safety checks |
95
+ | No data leaves device | Delimiter salting |
96
+ | Zero network calls | Context-aware analysis |
97
+
98
+ ### Enabling Layer 2
99
+
100
+ Initialize Tracerney with Layer 2 LLM Sentinel (Pro plan required):
101
+
102
+ ```typescript
103
+ const tracer = new Tracerney({
104
+ apiKey: process.env.TRACERNEY_API_KEY,
105
+ sentinelEnabled: true,
106
+ });
107
+ ```
108
+
109
+ That's it! Layer 2 is automatically configured to use the hosted LLM Sentinel service. Your API key authenticates requests and verifies your Pro subscription.
110
+
111
+ ### Custom Layer 2 Configuration (Advanced)
112
+
113
+ Want to self-host Layer 2 or use a custom implementation? Override the sentinel endpoint:
114
+
115
+ ```typescript
116
+ const tracer = new Tracerney({
117
+ apiKey: process.env.TRACERNEY_API_KEY,
118
+ sentinelEnabled: true,
119
+ baseUrl: process.env.TRACERNEY_BASE_URL, // e.g., http://localhost:3000 or https://myapp.com
120
+ sentinelEndpoint: process.env.TRACERNEY_SENTINEL_ENDPOINT, // e.g., /api/v1/verify-prompt
121
+ });
122
+ ```
123
+
124
+ **Self-hosting Layer 2?** You can build your own verification endpoint using the same pattern as our hosted service. Contact support for self-hosting guidance.
125
+
126
+ ### Scanning with Layer 2
127
+
128
+ With Layer 2 enabled, `scanPrompt` validates both input and LLM responses. Handle errors appropriately:
129
+
130
+ ```typescript
131
+ try {
132
+ // Scan input (Layer 1 + Layer 2)
133
+ const result = await tracer.scanPrompt(userInput);
134
+ // If we get here, input is safe. Call LLM
135
+ const llmResponse = await llm.chat(userInput);
136
+ // Verify LLM output wasn't compromised
137
+ const outputCheck = await tracer.verifyOutput(llmResponse);
138
+ return llmResponse;
139
+ } catch (err) {
140
+ if (err instanceof ShieldBlockError) {
141
+ return NextResponse.json(
142
+ { error: "Input content is flagged as suspicious" },
143
+ { status: 400 }
144
+ );
145
+ }
146
+ throw err;
147
+ }
148
+ ```
149
+
150
+ ### API Response Format
151
+
152
+ The verify-prompt endpoint returns structured responses. Success (HTTP 200) includes classification, confidence, and fingerprint. Errors include specific error codes and messages.
153
+
154
+ #### ✅ Content is Safe (HTTP 200)
155
+ ```json
156
+ {
157
+ "action": "ALLOW",
158
+ "confidence": 0.15,
159
+ "class": "safe_content",
160
+ "fingerprint": "a3f7k2"
161
+ }
162
+ ```
163
+
164
+ #### 🔴 Content is Blocked (HTTP 200)
165
+ ```json
166
+ {
167
+ "action": "BLOCK",
168
+ "confidence": 0.99,
169
+ "class": "jailbreak_semantic_pattern",
170
+ "fingerprint": "c1p5n3"
171
+ }
172
+ ```
173
+
174
+ #### ⚠️ Quota Exceeded (HTTP 402)
175
+ ```json
176
+ {
177
+ "blocked": true,
178
+ "reason": "scan_limit_exceeded",
179
+ "scansUsed": 50,
180
+ "limit": 50,
181
+ "message": "Free plan limit reached (50/month)..."
182
+ }
183
+ ```
184
+
185
+ ---
186
+
84
187
  ## Pricing & Usage
85
188
 
86
189
  - **Free Tier:** 50 scans/month with Layer 1 pattern detection
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sandrobuilds/tracerney",
3
- "version": "0.9.20",
3
+ "version": "0.9.21",
4
4
  "description": "Lightweight prompt injection detection with Layer 1 (258 patterns) + Layer 2 (AI verification). Runs locally with zero data storage. Upgrade to Pro for context-aware threat analysis at tracerney.com",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",