Skip to content
reaatech

Files · Perplexity PII Shield for SMB E-commerce Support Chat

68 (1 binary, 495.2 kB total)attempt 1

README.md·2852 B·markdown
markdown
# Perplexity PII Shield for SMB E-commerce Support Chat
 
A guardrail-wrapped Perplexity API endpoint that strips PII from e-commerce support chat transcripts before sending them to Perplexity for AI drafting, ensuring GDPR/PCI compliance.
 
## Quick Start
 
```bash
pnpm install
cp .env.example .env.local
# Set PERPLEXITY_API_KEY in .env.local
pnpm dev
```
 
## Architecture
 
The guardrail pipeline flow:
 
**Express POST → PII regex scrubber → PIIRedaction guardrail → InjectionGuardrail with pi-bench-core taxonomy → perplexity-sdk → reply with redaction audit log**
 
### Packages
 
| Package | Purpose |
|---|---|
| `@reaatech/guardrail-chain` | Core guardrail orchestration, ChainBuilder, Guardrail interface |
| `@reaatech/guardrail-chain-guardrails` | Built-in PII redaction and prompt injection guardrails |
| `@reaatech/guardrail-chain-config` | Configuration loading and validation |
| `@reaatech/pi-bench-core` | Prompt injection attack taxonomy for classification |
| `@reaatech/guardrail-chain-observability` | Logging and metrics infrastructure |
| `perplexity-sdk` | Perplexity chat completions API |
| `express` | HTTP server |
| `zod` | Schema validation |
 
## Usage
 
```bash
curl -X POST http://localhost:3000/api/chat/completion \
  -H "Content-Type: application/json" \
  -d '{"transcript":"my email is user@example.com and my card is 4111-1111-1111-1111"}'
```
 
## Environment Variables
 
| Variable | Description | Default |
|---|---|---|
| `PERPLEXITY_API_KEY` | Perplexity API key | — |
| `PORT` | HTTP server port | `3000` |
| `GUARDRAIL_BUDGET_LATENCY_MS` | Max latency budget for guardrail pipeline (ms) | `2000` |
| `GUARDRAIL_BUDGET_TOKENS` | Max token budget for guardrail pipeline | `8000` |
 
## Project Structure
 
```
src/
  config.ts               Application configuration (Zod schema + guardrail-chain-config)
  app.ts                  Express app factory
  index.ts                Entry point
  api/
    chat-completion.ts    Express route handler for /api/chat/completion
  middleware/
    pii-guard.ts          Custom PII scrubber guardrail + chain builder
    injection-guard.ts    Prompt injection guardrail with pi-bench-core taxonomy
    observability-setup.ts Observability initialization
  services/
    pii-patterns.ts       Regex PII detection patterns
    perplexity-client.ts  Perplexity SDK wrapper
    prompt-enricher.ts    Safe-field schema injection
    redaction-logger.ts   Compliance audit logger
    chat-pipeline.ts      End-to-end pipeline orchestrator
tests/
  config.test.ts
  pii-patterns.test.ts
  pii-guard.test.ts
  injection-guard.test.ts
  perplexity-client.test.ts
  prompt-enricher.test.ts
  redaction-logger.test.ts
  observability-setup.test.ts
  chat-pipeline.test.ts
  chat-completion.test.ts
  app.test.ts
  index.test.ts
```
 
## License
 
MIT — see [LICENSE](./LICENSE).