| name | openrouter-data-privacy |
| description | Implement data privacy controls for OpenRouter API usage. Use when handling PII, meeting GDPR/CCPA requirements, or protecting sensitive data in prompts. Triggers: 'openrouter privacy', 'openrouter pii', 'openrouter gdpr', 'openrouter data handling'.
|
| allowed-tools | Read, Write, Edit, Grep, Bash(python3:*) |
| version | 1.20.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","openrouter","privacy","security","compliance"] |
| compatibility | Designed for Claude Code |
OpenRouter Data Privacy
Overview
When sending data through OpenRouter to upstream LLM providers, you're responsible for ensuring prompts don't leak PII inappropriately. OpenRouter itself does not train on API data, but each upstream provider has its own data retention and training policies. This skill covers PII detection and redaction, placeholder substitution, provider selection for privacy, and consent tracking.
Prerequisites
- An OpenRouter API key (
sk-or-v1-...) exported as OPENROUTER_API_KEY — see the openrouter-install-auth skill for setup
- Python 3.8+ with the OpenAI SDK (
pip install openai) — every pattern in this skill is Python
- A sensitivity classification for your workloads (
public / standard / sensitive) so privacy_aware_completion() can route each one
- A list of providers your org approves for sensitive data, to plug into
provider.order with allow_fallbacks: False
Instructions
- Start with PII Detection and Redaction: adapt
PII_RULES (email, phone, SSN, credit card, sk-or-v1- API keys, IPs) to your data, then run scan_and_redact() on representative inputs and review the findings for false positives.
- When downstream code needs the original values back, use the Placeholder Substitution Pattern instead of plain redaction —
PrivacyProxy.anonymize() before the API call, deanonymize() on the model's reply.
- Classify each workload and route it via Provider Selection for Privacy:
privacy_aware_completion() maps sensitivity to a model plus a provider block (order: ["Anthropic"], allow_fallbacks: False for standard/sensitive).
- Wire the Privacy Middleware into every call path, choosing
block_on_pii=True (raise on detection) or auto_redact=True (scrub and continue) per workload.
- Apply the Enterprise Considerations: hash logged prompts (SHA-256) for GDPR right-to-erasure, and use BYOK for the most sensitive workloads.
PII Detection and Redaction
import re
from dataclasses import dataclass
typing
:
clean_text:
findings: []
has_pii:
PII_RULES = [
(, ),
(, ),
(, ),
(, ),
(, ),
(, ),
]
REPLACEMENTS = {
: , : , : ,
: , : , : ,
}
() -> PiiScanResult:
findings = []
clean = text
pii_type, pattern PII_RULES:
matches = re.findall(pattern, clean)
matches:
findings.append({: pii_type, : [:] + })
clean = re.sub(pattern, REPLACEMENTS[pii_type], clean)
PiiScanResult(clean_text=clean, findings=findings, has_pii=(findings) > )