# Keeping prompts and answers

The full rules for `ai: { keep_content: }`. The common case is under
[Prompts and answers in logs](/docs/safety-and-privacy.md#prompts-and-answers-in-logs).

- **`keep_content:`** takes `prompts:` and `keep:`, required, and
  `store:`. `prompts:` lists one or more of the app's prompts by name,
  `answer_question`, each once. `keep:` is a duration written out, from
  `1d` to `3650d`. `store:` is a database, `main` when left out (a
  declared one, or the one an app with none has), else the app's only
  database. Every mistake in it is `ai.settings_invalid`.
- **The field key is required**
  (`data.field_encryption_key_required` at `keep_content:`), since what
  is kept is sealed with it
  ([Encrypted fields](/docs/encrypted-fields.md)).
- **What is kept.** Each `ai.generate` call of a listed prompt that a
  model answered, in `jadpo_ai_content`, after its last attempt: the
  prompt's name, the model, when, the messages the last attempt sent,
  repairs included, and the text of the answer, if it had any. A refused
  or cut-off answer is kept too. A call with no answer (`timed_out`,
  `over_budget` before sending, `too_long`, `unavailable`) keeps
  nothing, and one given back on a rerun isn't kept again. A row that
  can't be written makes the call `unavailable`, as a budget's store
  does. `jadpo ai record` keeps nothing.
- **Sealed as `health` data.** The messages, a `List<ChatMessage>`, and
  the answer, a `Text?`, are each sealed with the field key, bound to
  their column and the row, as an encrypted field is. A rotation
  re-seals them with the sealed fields, and `jadpo config rotation`
  counts them.
- **Who it was made for** is the signed-in caller, a user's or a
  service's record. A call made for no one (an address's, a
  subscriber's, a schedule's) is kept for no one, and only `keep:` ends
  it.
- **Exported and erased with them.** It is kept beside their sessions,
  so `store:` must be the store of every entity someone signs in as
  (`ai.settings_invalid` otherwise). The person's export lists each call
  kept for a record of theirs that someone signs in as, under
  `AiContent`, with its `id`, `prompt`, `model`, `made_at`, `messages`
  and `answer`, kept for `keep:` since `made_at` and sent to the `ai:`
  connection. Their erasure deletes it in the same statement as their
  sessions, and so does their record's retention.
- **Read nowhere else.** No query, route or command reads it, so the
  export is its only reader, and every export is recorded
  ([Access records](/docs/access-records.md)).
- **Deleted at `keep:`.** The tick deletes each call once `keep:` has
  passed since it was made.
- **Everywhere the app runs:** in production, in `jadpo dev` and in
  `jadpo test`, each test with its own database.
- **The personal-data report** lists each kept prompt with its store and
  how long it is kept, and the approval review shows a change to them
  ([The personal-data report](/docs/the-personal-data-report.md)).
- **A streamed prompt** can't be listed yet: its answer is read by the
  route after the action has ended (`toolchain.not_built_yet`).
