@privacyscrubber/sdk
v2.2.5
Published
In-process consumer privacy defense and pre-emptive PII interception SDK for Node.js, Next.js, and AI pipelines. Zero data loss, zero third parties, sub-millisecond in-memory execution.
Downloads
1,064
Maintainers
Readme
@privacyscrubber/sdk
In-Process Consumer Privacy Defense & Pre-Emptive Interception Engine
100% In-Memory Execution. Zero Third-Party Subprocessors. Zero Data Loss. Sub-Millisecond Latency.
The official Node.js / TypeScript programmatic SDK for PrivacyScrubber.com. Acting as an autonomous in-process consumer data fiduciary, @privacyscrubber/sdk intercepts and neutralizes consumer PII and infrastructure secrets at your application boundary before transmission to external AI models or persistent storage—enforcing GDPR, CCPA/CPRA, and HIPAA Safe Harbor compliance without introducing third-party subprocessors or sacrificing LLM reasoning fidelity.
🏛️ The 4 Strategic Pillars of In-Process Privacy
- Active Consumer Privacy Defense (Fiduciary): Act systematically on behalf of end-users at the application boundary, protecting their statutory rights (GDPR, CCPA, State Privacy Acts) automatically without requiring end-user intervention.
- Pre-Emptive Interception: Quash sensitive customer identifiers and cloud credentials before ingestion, vector embedding, or LLM inference, preventing permanent data leaks at the perimeter.
- Zero Data Loss: Syntax-preserving deterministic tokenization (
[NAME_1],[EMAIL_1],[FINANCIAL_1]) retains 100% semantic context for LLMs, with instant in-memory detokenization (restore()) in local RAM. - Zero Third Parties: Pure in-process execution inside your Node.js runtime. Completely eliminates external DLP proxies (Skyflow, Nightfall, Lakera, AWS Comprehend), DPA renegotiations, and third-party data egress liability.
⚡ Why @privacyscrubber/sdk vs Cloud DLP / Presidio?
| Dimension | @privacyscrubber/sdk | MS Presidio | Google Cloud DLP | AWS Comprehend |
| :--- | :--- | :--- | :--- | :--- |
| Execution Model | Local In-Memory (<1ms) | Self-hosted Python (~35ms) | Cloud API Proxy (180–400ms) | Cloud API Proxy (200–500ms) |
| Network Egress | 0 Bytes (Air-gapped) | 0 Bytes (Internal hop) | Full unencrypted payload | Full unencrypted payload |
| Third-Party Subprocessors | 0 (Zero DPA / Vendor Risk) | 0 (Self-managed compute) | +1 Subprocessor (Google) | +1 Subprocessor (AWS) |
| Context & Data Loss | 0 Loss (Reversible in RAM) | High (Manual vault needed) | High (Lossy masking / hash) | High (Lossy masking) |
| Runtime Footprint | ~150KB (0 dependencies) | ~500MB (Python + spaCy) | Cloud SDK | Cloud SDK |
| OpenAI 1-Line Drop-in | Yes (wrapOpenAI) | Custom wrapper required | Custom pipeline | Custom pipeline |
| DevOps Secrets Scanning | Built-in (AWS, JWT, DBs) | Custom regex rules | Custom detectors | Custom classifiers |
| Cost Predictability | Free Tier / Flat $199/mo | DevOps server maintenance | Pay-per-GB cloud fees | Pay-per-unit API fees |
📊 Full Technical Benchmark: Read the in-depth latency analysis, cold-start profiles, and architecture deep-dive in docs/benchmarks/sdk-vs-presidio.md.
💡 The Breach Math vs SDK Math
| The Risk You Eliminate | Real-World Incident Cost | The @privacyscrubber/sdk Solution |
| :--- | :--- | :--- |
| 1 Leaked AWS Key in Cloud LLM Logs | $18,400+ (Emergency key rotation, forensic audit, incident response) | $0 / $199 flat: Masked to [AWS_KEY_1] in local RAM before leaving your node |
| 50k Customer Records in Vector DB | $4.45M (Average data breach cost, IBM Security Report) | <1ms latency: Sanitize streams on-the-fly before embedding vectors |
| Cloud DLP Egress Fees & Latency | $1,500–$4,000/mo + 350ms added prompt delay | 0 egress bytes: Pure in-memory execution, 0 network dependencies |
| Third-Party Subprocessor Vendor Audit | $25,000+ per enterprise vendor review (SOC 2, DPA, Legal) | 0 Subprocessors: No third party touches data; zero security review backlog |
🛡️ Architecture & Security Deep-Dive (CISO & DevSecOps Verification)
Backend engineering and InfoSec review boards consistently ask four core architectural questions before clearing SDK dependencies:
- Volatile In-Memory Isolation (Zero Network Egress): All string masking, token mapping, and session states execute strictly in the host Node.js process V8 heap memory. The SDK initiates zero outbound network connections, writes zero files to persistent disk, and communicates over zero IPC sockets. It operates seamlessly in 100% air-gapped VPCs and AWS Lambda / Google Cloud Run container environments.
- Deterministic Lookarounds vs Stochastic NER (Presidio/BERT):
To scrub data with cloud NER models, cleartext must first traverse an internal or external network to reach a Python microservice, violating zero-trust at step zero. Furthermore, stochastic NLP models hallucinate, drift between model weights, and consume 500MB+ RAM with cold starts.
@privacyscrubber/sdkutilizes deterministic abstract syntax lookarounds with 30 pre-compiled sector profiles (HIPAA EHR numbers, legal privilege codes, SWIFT/IBAN structures, and cloud API tokens) guaranteeing 100% reproducible results in <1ms. - Fuzzy Reverse Unscrubbing (LLM Token Drift Protection):
When external LLMs reformat or alter tokens in their completions (e.g. changing
[NAME_1]to[Name 1], altering casing, or adding Markdown formatting**[NAME_1]**), our fault-tolerant unscrubbing engine maps tokens back to original cleartext without corruption. - Local Cryptographic Audit Receipts: Generate signed SHA-256 session integrity receipts for enterprise SIEM ingestion (Splunk, Datadog, Elastic) directly within your backend microservice, proving regulatory compliance (GDPR Art. 25/32, HIPAA § 164.514, SOC 2 CC6.6) with zero telemetry leaving your VPC.
📚 Academic & Standards Track SSOT:
- IETF Specification: draft-sibiryakov-ztds-protocol-00
- CERN / Zenodo Foundation: DOI 10.5281/zenodo.22058770
- Center for Open Science (OSF) Benchmark: DOI 10.17605/OSF.IO/5BYJF
- Law Archive Treatise: osf.io/preprints/lawarchive/4wc86/
- Patent Pending: Israel Patent Office Application
IL 331905(WIPO DAS Code:B17B)
📦 Installation
npm install @privacyscrubber/sdk🚀 Quickstart
1. Transparent OpenAI Client Wrapper (1 Line of Code)
Zero changes to your prompt logic. Wrapping your OpenAI client intercepts outbound prompts in memory, replaces PII with tokens like [NAME_1], and rehydrates the original data into the assistant's response:
import OpenAI from 'openai';
import { wrapOpenAI } from '@privacyscrubber/sdk';
// Wrap your existing OpenAI client instance
const openai = wrapOpenAI(new OpenAI({ apiKey: process.env.OPENAI_API_KEY }));
// Outbound prompt is sanitized in local RAM before leaving your machine:
// "Contact [NAME_1] at [EMAIL_1] regarding invoice #99281."
const completion = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [
{ role: 'user', content: 'Contact Alice Smith at [email protected] regarding invoice #99281.' }
]
});
// Incoming LLM answer is automatically rehydrated with "Alice Smith ([email protected])":
console.log(completion.choices[0].message.content);2. Direct In-Memory Sanitization & Restoration
import { sanitize, restore } from '@privacyscrubber/sdk';
const rawPrompt = "Hello, my name is John Doe and my phone is 555-0199.";
// 1. Sanitize text before sending to LLM
const { scrubbedText, tokenMap, telemetry, auditReceipt } = sanitize(rawPrompt);
console.log(scrubbedText);
// "Hello, my name is [NAME_1] and my phone is [PHONE_1]."
console.log(auditReceipt);
// > 🛡️ **PrivacyScrubber Audit Receipt**
// > * **Risk Level:** 🟡 MODERATE EXPOSURE
// > * **Compliance Enforced:** ZTDS Standard, GDPR (Art. 4), CCPA/CPRA
// > * **Tokens Masked:** 2 (1 NAME, 1 PHONE)
// > * ⭐ **Star on GitHub:** [moxno/privacyscrubber-mcp](https://github.com/moxno/privacyscrubber-mcp) | **SDK & Enterprise:** [privacyscrubber.com/pricing](https://privacyscrubber.com/pricing)
// 2. Deterministically restore LLM response
const aiResponse = "I have queued an SMS notification for [NAME_1] at [PHONE_1].";
const { restoredText } = restore(aiResponse, tokenMap);
console.log(restoredText);
// "I have queued an SMS notification for John Doe at 555-0199."3. Vercel AI SDK Integration (generateText & streamText)
Drop-in sanitization for Next.js and Node.js applications built with the Vercel AI SDK (ai):
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { sanitize, restore } from '@privacyscrubber/sdk';
export async function POST(req: Request) {
const { prompt } = await req.json();
// 1. Sanitize user prompt in local RAM (<1ms)
const { scrubbedText, tokenMap } = sanitize(prompt, {
profile: 'General',
detectSecrets: true
});
// 2. Outbound call to LLM contains zero PII or credentials
const { text } = await generateText({
model: openai('gpt-4o'),
prompt: scrubbedText,
});
// 3. Deterministically restore authentic tokens locally
const { restoredText } = restore(text, tokenMap);
return Response.json({ response: restoredText });
}3b. Real-Time LLM Streaming De-tokenization (wrapAiStream, createStreamTokenRestorer, createNodeStreamTokenRestorer)
When LLMs stream responses via Server-Sent Events (SSE) or WebSockets, tokens can be split across arbitrary chunk boundaries (e.g. Chunk 1: "Contact [EM", Chunk 2: "AIL_1] at once"). StreamingDetokenizer uses a zero-latency sliding window buffer to stitch and restore tokens on the fly without delaying stream output:
import { streamText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { sanitize, wrapAiStream } from '@privacyscrubber/sdk';
export async function POST(req: Request) {
const { prompt } = await req.json();
// 1. Sanitize prompt in RAM
const { scrubbedText, tokenMap } = sanitize(prompt, { profile: 'General' });
// 2. Stream from LLM
const { textStream } = streamText({
model: openai('gpt-4o'),
prompt: scrubbedText,
});
// 3. Wrap stream — split tokens ([EM + AIL_1]) are rehydrated in real-time!
const restoredStream = wrapAiStream(textStream, tokenMap);
// 4. Return SSE stream to client with authentic values restored
return new Response(restoredStream);
}Transparent OpenAI Streaming (wrapOpenAI with stream: true):
import OpenAI from 'openai';
import { wrapOpenAI } from '@privacyscrubber/sdk';
const client = wrapOpenAI(new OpenAI(), { profile: 'Dev' });
const stream = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Debug AWS_KEY=AKIAIOSFODNN7EXAMPLE for user [email protected]' }],
stream: true, // Transparent real-time chunk de-tokenization!
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}Node.js Pipeline Streaming (createNodeStreamTokenRestorer):
import { pipeline } from 'node:stream/promises';
import { createNodeStreamTokenRestorer } from '@privacyscrubber/sdk';
const restorer = createNodeStreamTokenRestorer(tokenMap);
await pipeline(readableLlmStream, restorer, clientResponseStream);4. LangChain (LCEL Pipelines & createLangChainTransform)
Use the official middleware helper or compose inside LangChain Expression Language (LCEL) chains:
import { ChatOpenAI } from '@langchain/openai';
import { createLangChainTransform, PrivacyScrubberEngine } from '@privacyscrubber/sdk';
// Option A: 1-line middleware helper
const transform = createLangChainTransform({ defaultProfile: 'Healthcare' });
const { scrubbedText, tokenMap } = transform.preprocess("Patient John Doe MRN-99120 prescribed Lipitor.");
// ... invoke LLM with scrubbedText ...
const restoredOutput = transform.postprocess(llmOutput, tokenMap);
// Option B: Composable LCEL Runnable chain
const engine = new PrivacyScrubberEngine({ defaultProfile: 'Dev' });
const model = new ChatOpenAI({ model: 'gpt-4o', temperature: 0 });
const secureChain = async (rawQuestion: string) => {
const { scrubbedText, tokenMap } = engine.sanitize(rawQuestion);
const response = await model.invoke(scrubbedText);
return engine.restore(response.content as string, tokenMap);
};
const result = await secureChain("Debug AWS_KEY=AKIAIOSFODNN7EXAMPLE for user [email protected]");5. LlamaIndex.TS (RAG Node Sanitizer)
Prevent PII poisoning in vector stores by sanitizing documents prior to indexing:
import { Document } from 'llamaindex';
import { sanitize } from '@privacyscrubber/sdk';
// Sanitize documents before vector index ingestion (HIPAA & GDPR safe)
export function sanitizeDocumentsForIndex(docs: Document[]): Document[] {
return docs.map(doc => {
const { scrubbedText, telemetry } = sanitize(doc.text, {
profile: 'Healthcare', // Masks 18 HIPAA identifiers
detectSecrets: true
});
return new Document({
text: scrubbedText,
metadata: {
...doc.metadata,
psRiskLevel: telemetry.riskLevel,
psCompliant: telemetry.frameworksList.join(',')
}
});
});
}6. RAG & Vector Database Ingestion (Pinecone, Chroma, pgvector)
Storing raw PII inside vector embeddings is irreversible and violates GDPR Article 17 (Right to be Forgotten). Sanitize document chunks prior to vectorization:
import { sanitize } from '@privacyscrubber/sdk';
function prepareVectorChunk(rawDocumentChunk) {
const { scrubbedText, tokenMap, telemetry } = sanitize(rawDocumentChunk, {
profile: 'Healthcare', // Masks 18 HIPAA identifiers
detectSecrets: true // Masks API tokens, JWTs, DB credentials
});
// Embed only the sanitized text into your vector store
return {
anonymizedChunk: scrubbedText,
riskLevel: telemetry.riskLevel,
frameworks: telemetry.frameworksList
};
}7. Stateful Multi-Turn Agent Engine (PrivacyScrubberEngine)
Maintain token bindings across multi-step autonomous agent loops (LangChain, AutoGen, CrewAI):
import { PrivacyScrubberEngine } from '@privacyscrubber/sdk';
const engine = new PrivacyScrubberEngine({ defaultProfile: 'Dev' });
// Turn 1: Assigns [NAME_1] to John Doe
const turn1 = engine.sanitize("John Doe initiated deployment on prod.");
// Turn 2: Engine remembers [NAME_1] is John Doe across the entire thread
const turn2 = engine.sanitize("Review logs for John Doe.");
// Result: "Review logs for [NAME_1]." (Token numbering is consistently preserved!)
// Restore full thread context
const restored = engine.restore(agentOutputText);8. High-Throughput Stream Sanitization (createSanitizeStream)
Sanitize massive log files, database dumps, and SSE payloads on-the-fly with <1MB heap memory. Automatically handles split chunk boundaries:
import fs from 'node:fs';
import { createSanitizeStream } from '@privacyscrubber/sdk';
const sanitizeStream = createSanitizeStream({
profile: 'Dev',
detectSecrets: true
});
fs.createReadStream('prod-debug.log')
.pipe(sanitizeStream)
.pipe(fs.createWriteStream('sanitized-debug.log'));
sanitizeStream.on('finish', () => {
console.log(`Masked ${sanitizeStream.getTokenCount()} sensitive tokens in stream.`);
});9. AI Agent Guard & Function Calling (createGuardedTools, applyPatch)
Equip autonomous agents (Cursor, Vercel AI SDK, OpenAI, LangChain) with safe tools that intercept secrets and restore authentic data on disk:
import { PrivacyScrubberEngine, createGuardedTools, applyPatch } from '@privacyscrubber/sdk';
const engine = new PrivacyScrubberEngine({ defaultProfile: 'Dev' });
const { guardExec, guardReadFile, guardApplyPatch, guardGitDiff } = createGuardedTools(engine, {
cwd: process.cwd(),
timeoutMs: 15000
});
// 1. Agent runs commands safely: stdout PII is masked in RAM before LLM sees it
const execResult = await guardExec.execute({ command: 'npm test' });
// 2. Agent reads config safely: live secrets masked as [API_KEY_1]
const readResult = await guardReadFile.execute({ filePath: '.env' });
// 3. Agent modifies code: authentic secrets are restored to disk automatically
const patchResult = await guardApplyPatch.execute({
filePath: '.env',
content: readResult.sanitizedContent.replace('PORT=3000', 'PORT=8080')
});
// Automatically creates .env.bak before patching!10. Automated PR Security Verification Stamp (CI/CD)
Enforce zero plaintext PII and credential leaks in your CI/CD pipeline (GitHub Actions, GitLab CI, Jenkins) before pull requests are merged into production.
# Verify prompt templates or log exports in CI
npx @privacyscrubber/sdk --verify-ci prompts/user-context.txt
# Or pipe output directly from your test suite / build stream
cat test-output.log | npx @privacyscrubber/sdk --verify-ciWhen verified, the SDK generates a deterministic Zero-Trust Audit Receipt for PR comments:
> 🛡️ **Verified by PrivacyScrubber (ZTDS Standard)**
> * **Status:** ✅ PASSED · 0 PII / 0 Secrets detected in prompt pipeline
> * **Execution:** Local RAM (<1ms) · 0 Network Egress Bytes
> * **Audit Hash:** `8f4b1e...c902` (Zero-Trust Verified)Programmatic CI assertion in Node.js test suites (Jest, Vitest, Node Test Runner):
import { sanitize } from '@privacyscrubber/sdk';
import assert from 'node:assert';
test('pipeline prompt does not leak PII to third-party LLM', () => {
const prompt = buildUserPrompt(mockUserData);
const { scrubbedText, telemetry } = sanitize(prompt, { detectSecrets: true });
// Assert zero unmasked secrets and zero unmasked PII
assert.strictEqual(telemetry.riskLevel, 'SAFE / MINIMAL');
assert.ok(!scrubbedText.includes(mockUserData.email));
assert.ok(!scrubbedText.includes(mockUserData.apiKey));
});
### 11. Client-Side Website Form Interceptor (`@privacyscrubber/sdk/browser`)
Intercept customer support forms, loan applications, and lead generation inputs inside the browser DOM before network transmission. Dispatches safe surrogate tokens to public CRMs (Zendesk, HubSpot) or LLMs while isolating the encrypted `tokenMap` in your private database:
```html
<script type="module">
import { sanitize } from '@privacyscrubber/sdk/browser';
document.querySelector('#support-form').addEventListener('submit', async (e) => {
e.preventDefault();
const textarea = e.target.querySelector('textarea');
// 1. Sanitize in local browser RAM (<0.4ms)
const { scrubbedText, tokenMap } = sanitize(textarea.value, { profile: 'support' });
// 2. Transmit sanitized prompt to public CRM / AI (Zero PII Egress)
await fetch('/api/tickets', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: scrubbedText, tokenMap })
});
});
</script>🛡️ DevOps Secrets & Credentials Detection
Auto-detect and strip infrastructure secrets alongside consumer PII:
import { sanitize } from '@privacyscrubber/sdk';
const devLog = `
AWS_KEY=AKIAIOSFODNN7EXAMPLE
JWT=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M
DB_URI=postgres://admin:[email protected]:5432/prod
`;
const result = sanitize(devLog, { profile: 'Dev', detectSecrets: true });
console.log(result.scrubbedText);
// AWS_KEY=[AWS_KEY_1]
// JWT=[JWT_TOKEN_1]
// DB_URI=[SECRET_1]🔑 Licensing & Commercial Tiers
PrivacyScrubber works free out-of-the-box with standard developer limits:
- Free Tier ($0): Up to 15,000 characters per request for General profile; 5,000 characters free quota for specialized industry profiles. Built-in quota for local dev and CI testing without credit card or sign-up.
- Developer SDK License ($199/mo or $1,990/yr): Unlimited character throughput across all 30 specialized compliance profiles, unrestricted RAG & microservice batch pipelines, zero quota limits.
Activating Your Commercial License
Set the environment variable or pass your key explicitly:
export PRIVACYSCRUBBER_KEY="PS-SDK-PRODXXXXKEY5-XXXX"import { sanitize, validateLicense } from '@privacyscrubber/sdk';
// Check license status programmatically
const license = validateLicense(process.env.PRIVACYSCRUBBER_KEY);
console.log(`Active Tier: ${license.tier}, Valid: ${license.valid}`);
// Unlimited throughput is automatically enabled across all profiles
const result = sanitize(largeTextPayload, {
profile: 'Healthcare'
});To acquire a commercial Developer SDK license:
👉 PrivacyScrubber Developer Licensing
🏛️ Compliance Frameworks Enforced
- GDPR (Art. 4 & Art. 17): Direct & indirect personal identifiers, Right to be Forgotten.
- HIPAA (§164.514 Safe Harbor): 18 Protected Health Information (PHI) identifiers.
- PCI-DSS v4.0: Primary Account Numbers (PAN), CVVs, financial tokens.
- SOC 2 Type II / ISO 27001 (A.8.11): Zero-trust data masking and credential segregation.
- NIST SP 800-53: Automated secrets and cryptographic key sanitization.
🔗 PrivacyScrubber Ecosystem
- 🌐 Web App: https://privacyscrubber.com
- 🔌 MCP Server: @privacyscrubber/mcp-server
- 🧩 Chrome Extension: Chrome Web Store
- 📖 Developer SDK Specs: https://privacyscrubber.com/features/developer-sdk/
- ⭐ GitHub Repository: moxno/privacyscrubber-mcp (Star us on GitHub!)
- 🧪 DLP Latency Benchmark: https://privacyscrubber.com/dlp-speed-test/
📚 Production Architecture Guides
- 🛡️ RAG & Vector Databases: Sanitizing PII Before Vector DB Ingestion (Pinecone, Chroma, Qdrant)
- 🤖 LangChain & LlamaIndex: In-Memory PII Middleware for AI Agent Pipelines
- ⚡ AWS Comprehend Alternative: In-Memory Redaction Without Egress or Cloud Overhead
⚖️ License
MIT License © 2026 PrivacyScrubber. Commercial production usage without quota limits requires an active Developer SDK or Enterprise license.
🏛️ Intellectual Property & Virtual Patent Marking
The Zero-Trust Data Sanitization (ZTDS) architecture, in-memory deterministic tokenization, cryptographic session handoff, and headless execution methods implemented in this SDK are proprietary technology of Ilya Sibiryakov (BrandMeWeb) and are protected under Patent Pending status:
- Patent Office: State of Israel Ministry of Justice, Patent Office (ILPO)
- Application Number:
331905(Tracking ID:94221) - WIPO DAS Access Control Code:
B17B(World Intellectual Property Organization Digital Access Service electronic priority document exchange for USPTO, EPO, CNIPA, and PCT receiving offices) - Filing / Priority Date: September 14, 2026 (Paris Convention Art. 4 & 35 U.S.C. § 119 Priority locked through September 14, 2027)
- Official Title: SYSTEM AND METHOD FOR CLIENT-SIDE ZERO-TRUST DATA SANITIZATION AND CRYPTOGRAPHIC SESSION HANDOFF IN ARTIFICIAL INTELLIGENCE WORKFLOWS
- Virtual Patent Marking: privacyscrubber.com/patents/ in accordance with 35 U.S.C. § 287(a).
🌐 Internet Engineering Task Force (IETF) Specification
- Specification Title: The Zero-Trust Data Sanitization (ZTDS) Protocol for Frontier Artificial Intelligence Ingestion
- Standards Track: IETF Internet Standard Track
- IETF Datatracker: https://datatracker.ietf.org/doc/draft-sibiryakov-ztds-protocol/
- Archive Plaintext: https://www.ietf.org/archive/id/draft-sibiryakov-ztds-protocol-00.txt
