Skip to course content
Free generative AI app course

Generative AI Application Development with Python

Unit 07.03: Persisting a conversation responsibly

A stored conversation is personal data, whatever it was built for.

Retention, access control, deletion

A session record with a creation date and a retention period.

The code computes its age and the verdict.

import json
from datetime import date

record = {"user_id": "user-a", "session_id": "s-1",
          "created": "2026-07-01", "retention_days": 30,
          "messages": 14, "extracted_facts": {"account": "ACC-1187"}}

age = (date(2026, 7, 29) - date.fromisoformat(record["created"])).days
print(json.dumps({k: v for k, v in record.items() if k != "messages"}, indent=2))
print(f"\nage {age}d against {record['retention_days']}d: "
      f"{'PURGE' if age > record['retention_days'] else 'keep'}")

print("""
A stored conversation is personal data: what the user typed, their account
number, and whatever else came up. It needs a retention limit, access control
and a deletion path -- being built for convenience does not exempt it.
""")

The record holds the conversation, an account number, and whatever else the user typed - which may be anything. That is the same category of data as your primary store and needs the same three controls.

Note that the messages are excluded from the printed summary. Operational views of a session store should not casually display its contents.

The mistake this prevents

The mistake is treating session storage as a cache. Caches get built without retention policies, replicated for performance, and excluded from deletion tooling because nobody thinks of them as a data store.

Takeaway

Give persisted sessions a retention limit, access control and a deletion path. A conversation store holds personal data regardless of its purpose.