gateia 0.2.0 → 0.2.1
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.
- package/README.md +24 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,40 +39,48 @@ npm install gateia zod
|
|
|
39
39
|
|
|
40
40
|
## ⚡️ Quick Start
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
**Scenario:** You have an AI Customer Support Agent. You need to ensure it **never** promises refunds it can't deliver, and **never** leaks customer PII.
|
|
43
43
|
|
|
44
44
|
```typescript
|
|
45
45
|
import { verify } from 'gateia';
|
|
46
46
|
import { z } from 'zod';
|
|
47
47
|
|
|
48
|
-
// 1. Define the
|
|
49
|
-
// The AI
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
// 1. Define the "Safe Reply" Contract
|
|
49
|
+
// The AI must generate a Draft Reply that fits this structure.
|
|
50
|
+
const CustomerSupportContract = z.object({
|
|
51
|
+
sentiment: z.enum(['happy', 'neutral', 'angry']),
|
|
52
|
+
reply_text: z.string(),
|
|
53
|
+
ticket_status: z.enum(['open', 'resolved', 'escalated']),
|
|
54
|
+
requires_human_review: z.boolean()
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
// 2. The Verification Step
|
|
58
|
-
//
|
|
58
|
+
// Call this *after* obtaining the LLM response, but *before* sending it to the user.
|
|
59
59
|
const result = await verify({
|
|
60
60
|
output: llmResponse,
|
|
61
|
-
contract:
|
|
62
|
-
policies: [
|
|
61
|
+
contract: CustomerSupportContract,
|
|
62
|
+
policies: [
|
|
63
|
+
'finance-safe', // Block any unauthorized refund promises
|
|
64
|
+
'pii-safe', // Redact any leaked phone numbers/emails
|
|
65
|
+
],
|
|
63
66
|
mode: 'enforce'
|
|
64
67
|
});
|
|
65
68
|
|
|
66
69
|
// 3. Deterministic Decision
|
|
67
70
|
if (!result.allowed) {
|
|
68
|
-
//
|
|
69
|
-
|
|
71
|
+
// 🛑 BLOCKED: The AI tried to say something unsafe.
|
|
72
|
+
// Action: Fallback to a canned response or route to human agent.
|
|
73
|
+
console.warn("Safety Violation:", result.enforcement.violations);
|
|
74
|
+
sendToUser("I'm having trouble retrieving that info. A human will be with you shortly.");
|
|
70
75
|
} else {
|
|
71
|
-
//
|
|
72
|
-
|
|
76
|
+
// ✅ SAFE: The output adheres to your contract and policies.
|
|
77
|
+
// Action: Send the validated reply to the customer.
|
|
78
|
+
console.log("Verified Reply:", result.safeOutput.reply_text);
|
|
79
|
+
sendToUser(result.safeOutput.reply_text);
|
|
73
80
|
}
|
|
74
81
|
```
|
|
75
82
|
|
|
83
|
+
|
|
76
84
|
---
|
|
77
85
|
|
|
78
86
|
## 🛡️ Policy Library
|
|
@@ -156,4 +164,4 @@ Every call to `verify()` returns a comprehensive `EnforcementReport`. Use this f
|
|
|
156
164
|
|
|
157
165
|
## License
|
|
158
166
|
|
|
159
|
-
MIT
|
|
167
|
+
MIT
|