Datasets
Contents
Datasets are currently in beta. We'd love your feedback 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.
Because every change is versioned, a dataset is also an audit trail. You can always see what a dataset looked like at the moment you ran a test against it.
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
metadataobject. - 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.
Adding items
From a trace
The fastest way to build a useful dataset is to harvest real traffic. On a trace, 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 without losing its history.
Archiving
Datasets and items can be archived instead of deleted. An archived dataset stays readable but rejects item mutations until you restore it. Archived items are filtered out of the default view – and out of exports – but their history is intact.
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:
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 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 and /api/projects/:project_id/dataset_items, including creating exports and downloading their content. Use a personal API key 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.
Coming soon: offline evals reporting
Today datasets are the curation and export half of the loop. You export a revision, run it in your own harness, and read the results wherever you run them.
We're working on closing that loop. Soon you'll be able to report the results of an offline evaluation run back into PostHog, scored per dataset item and grouped by run, so you can compare a prompt or model change against the previous run and see which specific items regressed – all next to the online evaluations already scoring your production traffic.
Further reading
- Evaluations overview – online evaluations that score production generations automatically
- Trace reviews – the manual review workflow for finding failure modes worth adding to a dataset
- Traces – where dataset items usually come from