langfuse/langfuse · error · LangfuseNotFoundError
The dataset item with id ${input.id} already exists in a dat
Error message
The dataset item with id ${input.id} already exists in a dataset other than ${datasetIdentifierForLog} What it means
On upsert of a dataset item, the (id, projectId) uniqueness path fires when the supplied id already exists but is attached to a different dataset than the target. The service logs a warning and returns 404-style NotFoundError rather than moving the item between datasets.
Source
Thrown at web/src/features/datasets/server/publicDatasetService.ts:679
...transformDbDatasetItemDomainToAPIDatasetItem({
...datasetItem,
datasetName: datasetItem.datasetName,
status: datasetItem.status ?? "ACTIVE",
}),
mediaReferences:
mediaReferences.get(datasetItemMediaReferenceKey(datasetItem)) ?? [],
};
} catch (error) {
if (error instanceof Prisma.PrismaClientKnownRequestError) {
if (error.code === "P2025") {
// this case happens when a dataset item was created for a different dataset.
// In the database, the uniqueness constraint is on (id, projectId) only.
// When this constraint is violated, the database will upsert based on (id, projectId, datasetId).
// If this record does not exist, the database will throw an error.
logger.warn(
`Failed to upsert dataset item. Dataset item ${input.id} already exists for a different dataset than ${datasetIdentifierForLog}`,
);
throw new LangfuseNotFoundError(
`The dataset item with id ${input.id} already exists in a dataset other than ${datasetIdentifierForLog}`,
);
}
if (error.code === "P2002") {
// Unique constraint violation on (id, projectId, validFrom).
// This can happen when concurrent requests try to update the same dataset item
// and create versions with the same timestamp.
logger.warn(
`Failed to upsert dataset item due to version conflict. Dataset item ${input.id} was modified concurrently.`,
);
throw new LangfuseConflictError(
`Dataset item ${input.id ?? "new"} was modified concurrently. Please retry the request.`,
);
}
}
throw error;View on GitHub (pinned to 59d92c7cf3)
Solutions
- Use a dataset-scoped id scheme (e.g. `${datasetName}:${itemId}`) or omit id to let Langfuse generate one
- Delete the item from the old dataset first if you intend to move it
- Check which dataset owns the id: GET /api/public/dataset-items/:id
Example fix
// before
await datasetItems.create({ id: "item-1", datasetName: "dataset-b", ... });
// after
await datasetItems.create({ id: "dataset-b:item-1", datasetName: "dataset-b", ... }); Defensive patterns
Strategy: validation
Validate before calling
const existing = await client.fetch(`/api/public/dataset-items/${id}`);
if (existing && existing.datasetName !== targetDataset) id = `${targetDataset}:${id}`; Try / catch
catch (e) { if (is404WithMessage(e, /already exists in a dataset other than/)) useNamespacedId(); else throw e; } Prevention
- Namespace deterministic item ids per dataset
- Never assume ids are portable across datasets
When it happens
Trigger: POST/PUT /api/public/dataset-items with an explicit id that already exists under another dataset in the same project (e.g. re-using an id from dataset A when writing to dataset B).
Common situations: Copy/sync scripts that reuse deterministic item ids across datasets; renaming a dataset and recreating it under a new name while re-importing items with the same ids.
Related errors
- Dataset item not found
- A queue with this name already exists.
- Dataset id must not be empty
- Dataset name not valid. ${validation.error.message}
- ${duplicateErrorMessage}
AI-assisted analysis of langfuse/langfuse@59d92c7cf3 (2026-08-27).
Data as JSON: /api/errors/e51936fdf56c8b8c.
Report an issue: GitHub.