Anthropic Data Handling
Overview
Anthropic's data policies: API inputs/outputs are NOT used for model training (commercial API). Zero-day retention is available. This skill covers PII redaction before sending to Claude and compliance patterns.
Anthropic Data Policies
| Policy |
Details |
| Training data |
API data is NOT used for training (commercial API) |
| Data retention |
30-day default; 0-day available via agreement |
| Encryption |
TLS 1.2+ in transit, AES-256 at rest |
| SOC 2 Type II |
Certified |
| HIPAA BAA |
Available for eligible customers |
PII Redaction Before API Calls
import re
import anthropic
def redact_pii(text: str) -> tuple[str, dict]:
"""Redact PII before sending to Claude, return redaction map for restoration."""
redaction_map = {}
patterns = [
(r'\b\d{3}-\d{2}-\d{4}\b', 'SSN', '[SSN-REDACTED-{}]'),
(r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b', 'EMAIL', '[EMAIL-REDACTED-{}]'),
(r'\b\d{3}[-.]?\d{3}[-.]?\d{4}\b', 'PHONE', '[PHONE-REDACTED-{}]'),
(r'\b\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}\b', 'CARD', '[CARD-REDACTED-{}]'),
]
counter = 0
for pattern, label, replacement in patterns:
for match in re.finditer(pattern, text):
counter += 1
placeholder = replacement.format(counter)
redaction_map[placeholder] = match.group()
text = text.replace(match.group(), placeholder, 1)
return text, redaction_map
def restore_pii(text: str, redaction_map: dict) -> str:
"""Restore redacted PII in Claude's response."""
for placeholder, original in redaction_map.items():
text = text.replace(placeholder, original)
return text
# Usage
user_input = "Contact John at john@example.com or 555-123-4567"
safe_input, redactions = redact_pii(user_input)
# safe_input: "Contact John at [EMAIL-REDACTED-1] or [PHONE-REDACTED-2]"
client = anthropic.Anthropic()
msg = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=256,
messages=[{"role": "user", "content": safe_input}]
)
final_output = restore_pii(msg.content[0].text, redactions)
Audit Logging
import json
import logging
from datetime import datetime, timezone
audit_logger = logging.getLogger("claude.audit")
def audited_request(client, user_id: str, purpose: str, **kwargs):
"""Wrap Claude API calls with audit logging."""
# Log request metadata (never log content)
audit_logger.info(json.dumps({
"event": "claude.request",
"timestamp": datetime.now(timezone.utc).isoformat(),
"user_id": user_id,
"purpose": purpose,
"model": kwargs.get("model"),
"max_tokens": kwargs.get("max_tokens"),
}))
response = client.messages.create(**kwargs)
audit_logger.info(json.dumps({
"event": "claude.response",
"request_id": response._request_id,
"input_tokens": response.usage.input_tokens,
"output_tokens": response.usage.output_tokens,
"stop_reason": response.stop_reason,
}))
return response
Data Handling Checklist
Error Handling
| Risk |
Mitigation |
| PII in prompts |
Pre-call redaction pipeline |
| PII in responses |
Post-call output scanning |
| Audit log gaps |
Centralized logging with alerting |
| Data subject access request |
Searchable audit trail by user_id |
Resources
Next Steps
For enterprise access control, see anth-enterprise-rbac.
1---
2name: anth-data-handling
3description: |
4 Implement data privacy, PII handling, and compliance patterns for Claude API.
5 Use when handling sensitive data, implementing PII redaction,
6 or configuring data retention for GDPR/CCPA compliance with Claude.
7 Trigger with phrases like "anthropic data privacy", "claude PII",
8 "anthropic gdpr", "claude data handling", "redact data claude".
9allowed-tools: Read, Write, Edit, Grep
10version: 1.0.0
11license: MIT
12author: Jeremy Longshore <jeremy@intentsolutions.io>
13tags: [saas, ai, anthropic]
14compatible-with: claude-code
15metadata:
16 source: https://skillmd.com/skills/aibot88/anth-data-handling
17---
18
19# Anthropic Data Handling
20
21## Overview
22
23Anthropic's data policies: API inputs/outputs are NOT used for model training (commercial API). Zero-day retention is available. This skill covers PII redaction before sending to Claude and compliance patterns.
24
25## Anthropic Data Policies
26
27| Policy | Details |
28|--------|---------|
29| Training data | API data is NOT used for training (commercial API) |
30| Data retention | 30-day default; 0-day available via agreement |
31| Encryption | TLS 1.2+ in transit, AES-256 at rest |
32| SOC 2 Type II | Certified |
33| HIPAA BAA | Available for eligible customers |
34
35## PII Redaction Before API Calls
36
37```python
38import re
39import anthropic
40
41def redact_pii(text: str) -> tuple[str, dict]:
42 """Redact PII before sending to Claude, return redaction map for restoration."""
43 redaction_map = {}
44 patterns = [
45 (r'\b\d{3}-\d{2}-\d{4}\b', 'SSN', '[SSN-REDACTED-{}]'),
46 (r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b', 'EMAIL', '[EMAIL-REDACTED-{}]'),
47 (r'\b\d{3}[-.]?\d{3}[-.]?\d{4}\b', 'PHONE', '[PHONE-REDACTED-{}]'),
48 (r'\b\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}\b', 'CARD', '[CARD-REDACTED-{}]'),
49 ]
50
51 counter = 0
52 for pattern, label, replacement in patterns:
53 for match in re.finditer(pattern, text):
54 counter += 1
55 placeholder = replacement.format(counter)
56 redaction_map[placeholder] = match.group()
57 text = text.replace(match.group(), placeholder, 1)
58
59 return text, redaction_map
60
61def restore_pii(text: str, redaction_map: dict) -> str:
62 """Restore redacted PII in Claude's response."""
63 for placeholder, original in redaction_map.items():
64 text = text.replace(placeholder, original)
65 return text
66
67# Usage
68user_input = "Contact John at john@example.com or 555-123-4567"
69safe_input, redactions = redact_pii(user_input)
70# safe_input: "Contact John at [EMAIL-REDACTED-1] or [PHONE-REDACTED-2]"
71
72client = anthropic.Anthropic()
73msg = client.messages.create(
74 model="claude-sonnet-4-20250514",
75 max_tokens=256,
76 messages=[{"role": "user", "content": safe_input}]
77)
78final_output = restore_pii(msg.content[0].text, redactions)
79```
80
81## Audit Logging
82
83```python
84import json
85import logging
86from datetime import datetime, timezone
87
88audit_logger = logging.getLogger("claude.audit")
89
90def audited_request(client, user_id: str, purpose: str, **kwargs):
91 """Wrap Claude API calls with audit logging."""
92 # Log request metadata (never log content)
93 audit_logger.info(json.dumps({
94 "event": "claude.request",
95 "timestamp": datetime.now(timezone.utc).isoformat(),
96 "user_id": user_id,
97 "purpose": purpose,
98 "model": kwargs.get("model"),
99 "max_tokens": kwargs.get("max_tokens"),
100 }))
101
102 response = client.messages.create(**kwargs)
103
104 audit_logger.info(json.dumps({
105 "event": "claude.response",
106 "request_id": response._request_id,
107 "input_tokens": response.usage.input_tokens,
108 "output_tokens": response.usage.output_tokens,
109 "stop_reason": response.stop_reason,
110 }))
111
112 return response
113```
114
115## Data Handling Checklist
116
117- [ ] PII redacted before sending to Claude API
118- [ ] Audit logs capture who accessed what and when
119- [ ] Logs never contain message content or PII
120- [ ] Data retention policy matches your compliance needs
121- [ ] Zero-day retention enabled if required (contact Anthropic)
122- [ ] HIPAA BAA in place if handling PHI
123- [ ] User consent obtained for AI processing
124- [ ] Data deletion procedures documented
125
126## Error Handling
127
128| Risk | Mitigation |
129|------|------------|
130| PII in prompts | Pre-call redaction pipeline |
131| PII in responses | Post-call output scanning |
132| Audit log gaps | Centralized logging with alerting |
133| Data subject access request | Searchable audit trail by user_id |
134
135## Resources
136
137- [Anthropic Privacy Policy](https://www.anthropic.com/privacy)
138- [Anthropic Security](https://www.anthropic.com/security)
139- [Usage Policy](https://www.anthropic.com/usage-policy)
140
141## Next Steps
142
143For enterprise access control, see `anth-enterprise-rbac`.