https://github.com/emorilebo/redact-ai-stream
A lightweight Node.js library designed to secure your AI applications by automatically redacting Personally Identifiable Information (PII) from data streams before they reach public APIs (like OpenAI, Anthropic, etc.) and restoring the original data in the response stream.
https://github.com/emorilebo/redact-ai-stream
ai godfreylebo llm pii privacy redaction security stream
Last synced: 5 months ago
JSON representation
A lightweight Node.js library designed to secure your AI applications by automatically redacting Personally Identifiable Information (PII) from data streams before they reach public APIs (like OpenAI, Anthropic, etc.) and restoring the original data in the response stream.
- Host: GitHub
- URL: https://github.com/emorilebo/redact-ai-stream
- Owner: emorilebo
- Created: 2025-12-21T08:39:17.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-12-22T13:37:21.000Z (6 months ago)
- Last Synced: 2025-12-23T02:12:36.933Z (6 months ago)
- Topics: ai, godfreylebo, llm, pii, privacy, redaction, security, stream
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/redact-ai-stream
- Size: 27.2 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# redact-ai-stream





**Bi-directional PII Redaction for AI Streams**
`redact-ai-stream` is a lightweight, specialized Node.js library designed to secure your AI applications. It acts as a middleware layer, automatically redacting Personally Identifiable Information (PII) from data streams *before* they exit your secure boundary (e.g., to OpenAI, Anthropic), and transparently restoring that data in the incoming response stream.

## Why use this?
When building RAG requests or chat interfaces, you often need to send user context to an LLM. However, sending raw email addresses, phone numbers, or credit card details violates privacy compliance (GDPR, CCPA) and security best practices. `redact-ai-stream` solves this by tokenizing sensitive data on the fly.
## Features
* **Stream-based Redaction**: Integrates natively with Node.js `Transform` streams.
* **Bi-directional**: Redacts outgoing data, restores incoming data.
* **Session-based Security**: Tokens are unique per session (``).
* **Zero-Persistence**: Original PII is held in memory only for the duration of the stream; never stored on disk.
* **TypeScript Support**: Written in TypeScript with full type definitions included.
## Installation
```bash
npm install redact-ai-stream
```
## Usage
### TypeScript / ES Modules
```typescript
import RedactionSession from 'redact-ai-stream';
import { Readable } from 'stream';
// 1. Create a session
const session = new RedactionSession();
// 2. Mock input stream (e.g., from an API request)
const userInput = Readable.from(["My email is alice@example.com."]);
// 3. Pipe through redaction
const redactedStream = userInput.pipe(session.redact());
redactedStream.on('data', (chunk) => {
console.log('To LLM:', chunk.toString());
// Output: "To LLM: My email is "
});
// ... Send to AI ...
// 4. Restore AI response
const aiResponse = Readable.from(["Sending confirmation to ."]);
const finalStream = aiResponse.pipe(session.restore());
finalStream.on('data', (chunk) => {
console.log('To User:', chunk.toString());
// Output: "To User: Sending confirmation to alice@example.com."
});
```
### CommonJS
```javascript
const RedactionSession = require('redact-ai-stream');
// Usage is identical to above
```
## Supported Redactions
| Type | Pattern Example | Token Format |
| :--- | :--- | :--- |
| **Email** | `alice@example.com` | `` |
| **Credit Card** | `4532 1234 5678 9012` | `` |
| **Phone** | `+1-555-0123` | `` |
## License
MIT © Godfrey Lebo