- Reduce data before sending it to the model.
- Separate useful logs from dangerous logs.
- Design retention, anonymization, and review for educational or SMB apps.
What should not go into logs without thinking
- Full prompts containing personal data.
- Responses with contracts, invoices, or records.
- Tokens, API keys, cookies, or headers.
- Complete retrieved documents.
- Original user audio when there is no clear need.
Minimum secure log
{
"request_id": "req_20260703_001",
"user_role": "soporte",
"tenant_id_hash": "6f2a...",
"route": "/api/chat",
"model": "qwen3:8b",
"risk_flags": ["pii_detected", "rag_used"],
"retrieved_document_ids": ["doc_123", "doc_456"],
"answer_length": 842,
"refused": false,
"latency_ms": 1840
}Filter before the model
Dataset and permission audit
Before indexing documents or training with internal data, create an inventory. The question is not only “do we have this data?”, but “may we use it for this purpose?”.
data_inventory:
dataset: "support_tickets_2026"
contains_pii: true
usage_basis: "internal support"
allowed_for:
- "classification"
- "drafts with review"
forbidden_for:
- "training without anonymization"
- "sharing with external APIs"
retention_days: 90
owner: "operations"def redact(text):
text = text.replace("API_KEY=", "API_KEY=[REDACTED]")
# In production, use more robust detectors for emails, phone numbers, national IDs, and secrets.
return text
safe_prompt = redact(user_prompt)
response = model.generate(safe_prompt)