> AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt # Datasets Canonical URL: https://posthog.com/docs/ai-evals/datasets > **Cloud region:** This page uses US Cloud hosts. For an EU Cloud project, use `https://eu.posthog.com` instead of `https://app.posthog.com` (app host for links). ## On this page - [Why use datasets?](#why-use-datasets) - [How datasets work](#how-datasets-work) - [Creating a dataset](#creating-a-dataset) - [Adding items](#adding-items) - [Versioning](#versioning) - [Data retention](#data-retention) - [Exporting a dataset](#exporting-a-dataset) - [Programmatic access](#programmatic-access) - [Limits](#limits) - [Report results with offline evals](#report-results-with-offline-evals) - [Further reading](#further-reading) **Datasets are in beta** Datasets are currently in beta. We'd love your [feedback](https://app.posthog.com/ai-observability#panel=support%3Afeedback%3Allm-analytics%3Alow%3Atrue) as we develop the feature. Datasets let you curate sets of inputs and expected outputs that you can replay against prompt or model changes to catch regressions before they reach production. Instead of hoping a prompt tweak didn't break anything, you keep a growing collection of the cases you care about – the tricky ones, the ones users complained about, the ones that broke last time – and re-run them. Every change is versioned, so you can see what a dataset looked like when you ran a test. Revisions are available until they expire under the [retention policy](#data-retention). ## Why use datasets? - **Catch regressions before shipping** – Replay real cases against a new prompt, model, or agent version. - **Turn production failures into test cases** – Add a trace to a dataset directly from AI observability the moment you spot a problem. - **Keep tests reproducible** – Every dataset change creates an immutable revision, so a test run can be pinned to exactly the data it used. - **Work programmatically** – Build and update datasets from agents and scripts, not just the PostHog UI. ## How datasets work Datasets have three layers: - **Dataset** – A named collection of items, scoped to a project. It has a description and a free-form `metadata` object. - **Dataset item** – A single test case with a stable ID. An item's content lives in its versions, not on the item itself. - **Item version** – An immutable snapshot of one item's content. Editing an item never overwrites anything, it appends a new version. On top of item versions sit **dataset revisions**: monotonically increasing snapshots of the whole dataset. Every item mutation creates a new revision, so revision `12` describes exactly which version of every item was current at that point. A brand new dataset has no revision. Its first revision is created along with its first item. ### Item fields | Field | Description | | --- | --- | | `input` | The input given to the system under test. Any non-null JSON value – a string, an array of messages, an object. | | `expected_output` | Optional. The output you want, authored by you. This is what you compare against. | | `source_output` | Optional. The actual output captured from the source trace, kept for reference. | | `metadata` | Optional JSON object for your own labels – category, difficulty, owning team, whatever you filter on later. | | `client_item_id` | Optional case-sensitive key you own. Makes creates idempotent and safe to retry. It can't be changed. | | `source_trace_id` | The trace the item came from. Provide it together with `source_timestamp`. | | `source_event_id` | Optional. The specific event within the trace. | | `source_timestamp` | Required when you set `source_trace_id`. Needed to look the source trace back up. | Both `expected_output` and `source_output` are optional, so you can save a case you know is wrong before you've decided what the right answer looks like. ## Creating a dataset You can create a dataset in the PostHog UI or with the [PostHog MCP server](https://posthog.com/docs/model-context-protocol.md). ## Adding items ### From a trace The fastest way to build a useful dataset is to harvest real traffic. On a [trace](https://posthog.com/docs/ai-observability/traces.md), click **Add to dataset** and pick a dataset. PostHog pre-fills the item with the trace's input, its output as `source_output`, and the trace provenance fields, so you can jump back to where the case came from. ### Manually Open a dataset and add an item directly, filling in **Input**, **Expected output**, and **Metadata** as JSON. ## Versioning Every item change creates an immutable version and a new dataset revision. You can view past revisions and restore an earlier version of an item while that history is still available under the [retention policy](#data-retention). ### Archiving Datasets and items can be archived instead of deleted immediately. An archived dataset stays readable until it expires, but rejects item mutations until you restore it. Archived items are filtered out of the default view – and out of exports. Their history follows the retention policy below. ## Data retention PostHog deletes data after these periods without use: - **Active datasets:** 90 days, starting at creation. - **Archived datasets:** 30 days, starting when archived. - **Older revisions:** 30 days, starting when replaced by a newer revision. Reading contents in PostHog or through the SDK/API, exporting, editing, restoring, or using them in an evaluation counts as use. Listing datasets or revisions does not. Using a revision restarts the clock for that revision and its dataset, but not other revisions. The latest revision stays available with its dataset. Ongoing evaluation uploads and exports keep the data they need until they finish. **Expiring soon** appears in the final 7 days. Expired datasets and revisions cannot be read or restored. Export and download anything you need to keep. Historical evaluation scores and scorer configurations are kept. Evaluation inputs, outputs, and other payloads follow a [separate 30-day policy](https://posthog.com/docs/ai-evals/offline-evals.md#data-retention). ## Exporting a dataset Exports let you run a dataset through your own harness, in CI or on your machine, and keep the results comparable over time. Click **Export** on a dataset to generate a JSONL file. Exports are: - **Asynchronous** – The export is prepared in the background, then made available to download. Exported files expire, so download or re-export as needed. - **Pinned to a revision** – Exporting from **Latest** pins to the current revision, and exporting while viewing a historical revision pins to that one. Because revisions are immutable, re-downloading the same export always gives you identical data. - **Active items only** – Archived items are excluded. Each line is one item, with the revision recorded on every row: ```json {"dataset_id":"018f...","dataset_revision":12,"item_id":"018f...","client_item_id":"ticket-4821","version":3,"input":{"messages":[{"role":"user","content":"How do I cancel?"}]},"expected_output":"Point the user to the billing settings page.","source_output":"You can cancel any time.","metadata":{"category":"billing"},"source_trace_id":"trace_abc","source_event_id":"event_def","source_timestamp":"2026-05-04T10:12:33+00:00"} ``` Pinning to a revision is what makes an export worth storing next to your test results: "this run scored 84% on revision 12" stays meaningful even after the dataset has moved on. ## Programmatic access ### MCP The [PostHog MCP server](https://posthog.com/docs/model-context-protocol.md) exposes datasets to AI agents like Claude Code and Cursor, so an agent that just debugged a bad generation can add it to your regression set without you switching windows. | Tool | Description | | --- | --- | | `llma-dataset-list` | List datasets, with search and an active/archived filter | | `llma-dataset-get` | Get a dataset by ID | | `llma-dataset-create` | Create a dataset | | `llma-dataset-update` | Update a dataset's name, description, or metadata | | `llma-dataset-archive` | Archive a dataset | | `llma-dataset-restore` | Restore an archived dataset | | `llma-dataset-revision-list` | List a dataset's revisions, newest first | | `llma-dataset-item-list` | List items, optionally as they appeared at a specific revision | | `llma-dataset-item-get` | Get an item, optionally at a specific revision | | `llma-dataset-item-create` | Add an item and create its first version | | `llma-dataset-item-update` | Create a new version of an item | | `llma-dataset-item-archive` | Archive an item | | `llma-dataset-item-restore` | Restore an archived item, optionally from a chosen historical version | | `llma-dataset-item-version-list` | List an item's version history | Pass a `client_item_id` when an agent creates items. An identical retry returns the existing item instead of creating a duplicate, which makes agent loops safe to re-run. ### API The same operations are available over REST at [`/api/projects/:project_id/datasets`](https://posthog.com/docs/api/datasets.md) and [`/api/projects/:project_id/dataset_items`](https://posthog.com/docs/api/dataset-items.md), including creating exports and downloading their content. Use a [personal API key](https://posthog.com/docs/api.md#authentication) with the `dataset` scope. ### CLI CLI access is on the way, so you'll be able to pull a dataset revision and run it as part of a build without writing API glue. It isn't available yet. ## Limits PostHog applies limits to datasets to prevent abuse. These limits are subject to change. ## Report results with offline evals After your CI run scores each dataset item, send the results to PostHog with [offline evals](https://posthog.com/docs/ai-evals/offline-evals.md). Each run appears as an experiment, with one row per test case and one column per evaluator, so you can compare runs and find the items that regressed. ## Further reading - [Evaluations overview](https://posthog.com/docs/ai-evals.md) – online evaluations that score production generations automatically - [Trace reviews](https://posthog.com/docs/ai-observability/trace-reviews.md) – the manual review workflow for finding failure modes worth adding to a dataset - [Traces](https://posthog.com/docs/ai-observability/traces.md) – where dataset items usually come from