Handle personal data and sensitive actions the way an enterprise customer or auditor expects, with the least code. Covers knowing which fields hold personal data and why, collecting less, an append-only audit trail of who did what, a delete-my-data path that reaches every copy, and retention that actually deletes. Use whenever a change stores, exports or deletes personal data (name, email, phone, address, IP, payment, health or ID data), adds an admin or permission action, carries the sensiti...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Audit And Privacy?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/restierecon-audit-and-privacy)
---
name: audit-and-privacy
description: Handle personal data and sensitive actions the way an enterprise customer or auditor expects, with the least code. Covers knowing which fields hold personal data and why, collecting less, an append-only audit trail of who did what, a delete-my-data path that reaches every copy, and retention that actually deletes. Use whenever a change stores, exports or deletes personal data (name, email, phone, address, IP, payment, health or ID data), adds an admin or permission action, carries the sensitive-data hazard, or when someone asks for an audit log, GDPR or SOC 2 work, account deletion or data retention.
---
# Audit and Privacy
Personal data is a liability you pay for in storage, breach risk and audit time.
Store only what a feature needs, record who touched what, and be able to delete it.
Use what the project already has. Nothing more, nothing less.
## 1. List the personal data the change touches
For every field the change stores, reads, exports or deletes, write one line:
`<table.field> — <class> — <why it is stored> — <kept for>`. Classes:
- personal: name, email, phone, address, IP address, device ID
- sensitive: payment, health, government ID, precise location, anything about a child
- not personal: everything else
A field with no reason is not stored. A "kept for" nobody decided is a product and
legal decision, not yours: in a TBV project it goes back to /grill.
## 2. Use what the project already has
Search for an existing audit table or log, soft-delete column, erase or anonymize
function, retention job, encryption or masking helper (`audit`, `activity`,
`deleted_at`, `erase`, `anonymize`, `retention`, `purge`, `encrypt`). Extend it. Never
add a second audit mechanism or a privacy library for one change.
## 3. Collect less
- Don't store what the feature doesn't use. Ask for a birth year, not a birth date,
if age is all you check.
- Store the derived value, not the source: the card's last 4 digits and the payment
provider's token, never the card number.
- Never put personal data in logs, metric labels, URLs, error messages or analytics
events. Use the record's ID (observability skill).
- Test fixtures use made-up people (`ada@example.com`), never copied production rows.
## 4. Record who did what
Write one audit event for each action someone could later ask "who did this?" about:
sign-in and permission changes, role or access grants, data exports, deletions, money
moves, admin access to another user's data, security settings. Not every read, not
every page view.
Each event holds: who (`actor_id`), what (a stable `action` name like
`user_role_changed`), which record (`target_id`), when (UTC), the request ID, and the
new value only when it is not personal (a role name, a plan). Never the personal data
itself.
Write it in the same transaction as the change, so the change and its record succeed
or fail together. Application code only ever inserts audit rows: no update, no delete.
If the project manages database grants, the app's user gets `INSERT` and `SELECT` on
that table and nothing else.
```python
def change_role(connection, actor_id, user_id, role, request_id):
with connection:
connection.execute("UPDATE users SET role = ? WHERE id = ?", (role, user_id))
connection.execute(
"INSERT INTO audit_events (actor_id, action, target_id, detail, request_id, at) "
"VALUES (?, 'user_role_changed', ?, ?, ?, CURRENT_TIMESTAMP)",
(actor_id, user_id, role, request_id),
)
```
## 5. Delete it everywhere
A delete-my-data request reaches every place from section 1: each table, file store,
cache and search index, and the third parties the data was sent to. Two ways:
- delete the row when nothing else needs it
- anonymize it when other records must stay (orders and invoices a finance or tax rule
keeps): blank or replace the personal fields, keep the ID and the non-personal facts
Then write an audit event for the erasure itself, without the erased values.
```python
def erase_user(connection, actor_id, user_id):
with connection:
connection.execute(
"UPDATE users SET email = NULL, phone = NULL, name = 'deleted user', erased_at = CURRENT_TIMESTAMP WHERE id = ?",
(user_id,),
)
connection.execute("DELETE FROM addresses WHERE user_id = ?", (user_id,))
connection.execute(
"INSERT INTO audit_events (actor_id, action, target_id, at) VALUES (?, 'user_erased', ?, CURRENT_TIMESTAMP)",
(actor_id, user_id),
)
```
Backups age out on their own schedule; say how long in your report, don't edit them.
## 6. Keep it only as long as decided
A "kept for" from section 1 that isn't "until the account is deleted" needs a job that
deletes older rows, in batches so it never locks a large table, through the project's
existing scheduler.
```python
def purge_old_sessions(connection, days):
while True:
with connection:
deleted = connection.execute(
"DELETE FROM sessions WHERE id IN "
"(SELECT id FROM sessions WHERE created_at < datetime('now', ?) LIMIT 1000)",
(f"-{days} days",),
).rowcount
if deleted < 1000:
return
```
## 7. Prove it with a test
- Each audited action writes exactly one event with the actor, action and target,
and none when the action fails.
- Erasure: after it runs, no table from section 1 holds the user's personal fields,
and the records that must stay still exist.
- Retention: old rows are deleted and recent rows are kept.
- No log line or audit event contains a personal value from the test's fixture.
```python
def test_erasing_a_user_removes_their_email_and_keeps_their_orders(connection):
erase_user(connection, actor_id=1, user_id=7)
assert connection.execute("SELECT email FROM users WHERE id = 7").fetchone() == (None,)
assert connection.execute("SELECT COUNT(*) FROM orders WHERE user_id = 7").fetchone() == (2,)
```
## 8. Keep it readable
Write the audit insert next to the change it records, in plain SQL or the project's
ORM. No comments: the `action` name says what happened. No audit decorators, event
buses or base classes of your own unless the project already uses them.
## In a TBV project
Personal data the grill settled (what is stored, why, for how long, which actions are
audited) becomes criteria like "changing a user's role writes one `user_role_changed`
event with the actor and target" or "erasing an account removes the email from users
and the search index" (slice-planning skill). A slice that touches sensitive data
carries the `sensitive-data` hazard (risk-gate skill), so it gets the auditor and a
human merge approval. Build exactly the criteria. Gaps you notice elsewhere go under
FLAG CANDIDATES, not into the diff.
## Never
- A personal field stored without a reason, or kept without a decided period.
- Personal data in a log, metric, URL, error, analytics event or audit event.
- An audit row updated or deleted by application code, or written outside the
change's transaction.
- An erasure that misses a copy you know about.
- Real people's data in fixtures.
- A new audit or privacy dependency added for one change.
- Comments explaining audit or privacy code.