> ## Documentation Index
> Fetch the complete documentation index at: https://docs.braintrust.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Retention and deletion for datasets and experiments

> Age out datasets and experiments with retention automations, and remove one person's records when a deleted dataset row is still in earlier versions.

> [!NOTE]
>
> **Applies to:**
>
> * Plan - Any. Retention automations require Enterprise.
> * Deployment - Any
> *
> * Use case - Age out datasets and experiments, or remove one person's records from them

## Summary

Retention automations delete datasets and experiments once they pass a retention period. Deleting a single dataset record doesn't erase it: the record stays in earlier versions of the dataset and in experiments that ran on it. To remove one person's records, find them with SQL, rebuild the dataset without them, and delete the original dataset and the affected experiments.

## What is happening

Datasets are versioned so that experiments can pin to a specific version. Deleting a record adds a new version without it, so earlier versions still contain the record. You can read any earlier version with the `version` parameter of the [SQL API](https://docs.braintrust.dev/api-reference/query.md), and restoring a [snapshot](https://docs.braintrust.dev/annotate/datasets/manage.md#save-and-restore-snapshots) saved before the deletion brings the record back.

Experiments are separate objects. Each experiment row stores the `input` and `expected` values of the record it ran on, so deleting the record from the dataset doesn't change experiments that already used it.

## Fix or suggestion

### Age out data with retention automations

Create a [retention automation](https://docs.braintrust.dev/admin/data-management/retention.md#automate-data-deletion) for experiments and for datasets. For experiments, the automation deletes the entire experiment once its creation timestamp passes the retention period. For datasets, it deletes the individual records that are older than the retention period, and the dataset remains.

> [!WARNING]
>
> Retention automations permanently delete data. Deleted logs, experiments, and dataset rows cannot be recovered.

### Remove one person's records

1. Find the person's records. Store their identifier in the same top-level `metadata` field on every record, such as `metadata.customer_id`, then query on the [** Query**](https://www.braintrust.dev/app/~/sql) page or through the [SQL API](https://docs.braintrust.dev/api-reference/query.md). To search several objects at once, pass more than one ID to the [data source](https://docs.braintrust.dev/reference/sql/query-structure.md#data-sources):

   ```sql theme={null}
   -- Replace the IDs with your values
   SELECT id, created, metadata.customer_id
   FROM dataset('<DATASET_ID_1>', '<DATASET_ID_2>')
   WHERE metadata.customer_id = '<CUSTOMER_ID>'
     AND created > now() - interval 365 day -- Widen the window to cover all of your records
   LIMIT 1000
   ```

   Run the same query with `experiment('<EXPERIMENT_ID>')` to find matching experiment rows.

2. Rebuild each affected dataset without the person's records. Copy the records you want to keep into a new dataset, as shown in [Copy records to another dataset](https://docs.braintrust.dev/annotate/datasets/manage.md#copy-records-to-another-dataset), and skip the person's records.

3. Delete the original dataset after you confirm the new one is complete. Go to [** Datasets**](https://www.braintrust.dev/app/~/datasets), select the dataset, and click **Delete**, or run [`bt datasets delete`](https://docs.braintrust.dev/reference/cli/datasets#bt-datasets-delete).

4. Delete the experiments that contain the person's records, for example with [`bt experiments delete`](https://docs.braintrust.dev/reference/cli/experiments#bt-experiments-delete). Deleting only the matching experiment rows leaves them readable in earlier versions of the experiment, the same way dataset record deletions do.

## How to confirm it worked

Run the step 1 query against the new dataset and any experiments you kept. It returns no rows for the person's identifier.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.