Skip to content
reaatech

Files · xAI Grok PII Detection for SMB Customer Communication

32 (0 binary, 267.3 kB total)attempt 1

README.md·2305 B·markdown
markdown
# xAI Grok PII Detection for SMB Customer Communication
 
Protect customer data by scanning Grok-powered messages for PII and offensive content before they reach end users.
 
## Architecture
 
This recipe acts as a reverse proxy between your application and the xAI Grok API. It implements an Express middleware chain:
 
1. **Classifier** (`@reaatech/agent-mesh-classifier`) — Classifies incoming messages for intent and language
2. **Guardrails** (`@presidio-dev/hai-guardrails`) — PII and secret detection using PII Guard and Secret Guard
3. **Safety Chain** — Orchestrates pre-call (prompt) and post-call (completion) safety checks
4. **Circuit Breaker** (`@reaatech/circuit-breaker-core`) — Fast fail-stop when downstream calls fail
5. **Budget Tracker** (`@reaatech/agent-budget-middleware`) — Tracks token usage and cost
6. **xAI Grok** (`@ai-sdk/xai`) — The underlying LLM provider for customer communication
 
## Prerequisites
 
- Node.js >= 22
- pnpm 10.x
- xAI API key
 
## Setup
 
```bash
pnpm install
cp .env.example .env
# Fill in your XAI_API_KEY
```
 
## Run
 
```bash
pnpm tsx src/index.ts
```
 
## Test
 
```bash
pnpm test
```
 
## API
 
### POST /api/generate
 
Send a prompt for safe Grok-generated responses:
 
```bash
curl -X POST http://localhost:3000/api/generate \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Hello, how can I help you?"}'
```
 
Response (safe):
```json
{
  "text": "Hello! How can I assist you today?",
  "usage": { "inputTokens": 10, "outputTokens": 5 }
}
```
 
Response (blocked):
```json
{
  "text": "I'm sorry, I cannot process this request at the moment due to content safety policies.",
  "blocked": true,
  "reason": "pii-in-prompt"
}
```
 
### GET /health
 
```bash
curl http://localhost:3000/health
```
 
## Packages
 
- [xAI Grok SDK (@ai-sdk/xai)](https://www.npmjs.com/package/@ai-sdk/xai)
- [hai-guardrails](https://www.npmjs.com/package/@presidio-dev/hai-guardrails)
- [REAA Circuit Breaker](https://www.npmjs.com/package/@reaatech/circuit-breaker-core)
- [REAA Agent Mesh Classifier](https://www.npmjs.com/package/@reaatech/agent-mesh-classifier)
- [REAA Agent Handoff Validation](https://www.npmjs.com/package/@reaatech/agent-handoff-validation)
- [REAA Agent Budget Middleware](https://www.npmjs.com/package/@reaatech/agent-budget-middleware)