Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(api): reject dataset-run-item surface in events_only mode (#15313)

Steffen Schmitz0530589e7160
diff --git a/web/src/features/mcp/features/datasets/events-only-guard.ts b/web/src/features/mcp/features/datasets/events-only-guard.ts
new file mode 100644
index 0000000000..9579881d8d
--- /dev/null
+++ b/web/src/features/mcp/features/datasets/events-only-guard.ts
@@ -0,0 +1,17 @@
+import { env } from "@/src/env.mjs";
+import { LangfuseNotFoundError } from "@langfuse/shared";
+
+/**
+ * The dataset run (item) tools read from and write to the legacy
+ * dataset_run_items ClickHouse table, which is no longer populated when
+ * LANGFUSE_MIGRATION_V4_WRITE_MODE is "events_only". Refuse them like the
+ * corresponding public REST routes do (rejectInEventsOnlyMode), pointing to
+ * the experiments surface instead.
+ */
+export const rejectDatasetRunToolsInEventsOnlyMode = (): void => {
+ if (env.LANGFUSE_MIGRATION_V4_WRITE_MODE === "events_only") {
+ throw new LangfuseNotFoundError(
+ "This tool is not available on deployments running in Langfuse v4 events_only mode. Use the experiments tools instead. Learn more about Langfuse v4 at: https://langfuse.com/docs/v4",
+ );
+ }
+};
diff --git a/web/src/features/mcp/features/datasets/tools/createDatasetRunItem.ts b/web/src/features/mcp/features/datasets/tools/createDatasetRunItem.ts
index 3dece8388f..ab70db3d76 100644
--- a/web/src/features/mcp/features/datasets/tools/createDatasetRunItem.ts
+++ b/web/src/features/mcp/features/datasets/tools/createDatasetRunItem.ts
@@ -4,6 +4,7 @@ import { createDatasetRunItemForApi } from "@/src/features/datasets/server/publi
import { defineTool } from "../../../core/define-tool";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { getMcpPublicApiAuth } from "../../publicApi";
+import { rejectDatasetRunToolsInEventsOnlyMode } from "../events-only-guard";
const CreateDatasetRunItemBaseSchema = z.object({
runName: z.string(),
@@ -42,6 +43,7 @@ export const [createDatasetRunItemTool, handleCreateDatasetRunItem] =
"mcp.dataset_run_name": input.runName,
},
fn: async () => {
+ rejectDatasetRunToolsInEventsOnlyMode();
const auth = await getMcpPublicApiAuth(context);
return await createDatasetRunItemForApi({
body: input,
diff --git a/web/src/features/mcp/features/datasets/tools/deleteDatasetRun.ts b/web/src/features/mcp/features/datasets/tools/deleteDatasetRun.ts
index 352277f073..1971966630 100644
--- a/web/src/features/mcp/features/datasets/tools/deleteDatasetRun.ts
+++ b/web/src/features/mcp/features/datasets/tools/deleteDatasetRun.ts
@@ -2,6 +2,7 @@ import { deleteDatasetRunByIdForApi } from "@/src/features/datasets/server/publi
import { DeleteDatasetRunV1Response } from "@/src/features/public-api/types/datasets";
import { defineTool } from "../../../core/define-tool";
import { runMcpTool } from "../../../core/run-mcp-tool";
+import { rejectDatasetRunToolsInEventsOnlyMode } from "../events-only-guard";
import { DeleteDatasetRunMcpInput } from "../schema";
export const [deleteDatasetRunTool, handleDeleteDatasetRun] = defineTool({
@@ -19,6 +20,7 @@ export const [deleteDatasetRunTool, handleDeleteDatasetRun] = defineTool({
"mcp.dataset_run_id": input.datasetRunId,
},
fn: async () => {
+ rejectDatasetRunToolsInEventsOnlyMode();
const result = await deleteDatasetRunByIdForApi({
projectId: context.projectId,
orgId: context.orgId,
diff --git a/web/src/features/mcp/features/datasets/tools/getDatasetRun.ts b/web/src/features/mcp/features/datasets/tools/getDatasetRun.ts
index f8c9b36f38..8740bea8d6 100644
--- a/web/src/features/mcp/features/datasets/tools/getDatasetRun.ts
+++ b/web/src/features/mcp/features/datasets/tools/getDatasetRun.ts
@@ -3,6 +3,7 @@ import { getDatasetRunByIdForApi } from "@/src/features/datasets/server/publicDa
import { defineTool } from "../../../core/define-tool";
import { buildDatasetRunUrl } from "@/src/utils/product-url";
import { runMcpTool } from "../../../core/run-mcp-tool";
+import { rejectDatasetRunToolsInEventsOnlyMode } from "../events-only-guard";
import { GetDatasetRunMcpInput } from "../schema";
export const [getDatasetRunTool, handleGetDatasetRun] = defineTool({
@@ -20,6 +21,7 @@ export const [getDatasetRunTool, handleGetDatasetRun] = defineTool({
"mcp.dataset_run_id": input.datasetRunId,
},
fn: async () => {
+ rejectDatasetRunToolsInEventsOnlyMode();
const result = await getDatasetRunByIdForApi({
projectId: context.projectId,
datasetId: input.datasetId,
diff --git a/web/src/features/mcp/features/datasets/tools/listDatasetRunItems.ts b/web/src/features/mcp/features/datasets/tools/listDatasetRunItems.ts
index 75441e1827..8e77835d9a 100644
--- a/web/src/features/mcp/features/datasets/tools/listDatasetRunItems.ts
+++ b/web/src/features/mcp/features/datasets/tools/listDatasetRunItems.ts
@@ -4,6 +4,7 @@ import { defineTool } from "../../../core/define-tool";
import { buildDatasetRunUrl } from "@/src/utils/product-url";
import { runMcpTool } from "../../../core/run-mcp-tool";
import { paginationMeta } from "../../publicApi";
+import { rejectDatasetRunToolsInEventsOnlyMode } from "../events-only-guard";
import { GetDatasetRunItemsMcpInput } from "../schema";
export const [listDatasetRunItemsTool, handleListDatasetRunItems] = defineTool({
@@ -21,6 +22,7 @@ export const [listDatasetRunItemsTool, handleListDatasetRunItems] = defineTool({
"mcp.dataset_run_id": input.datasetRunId,
},
fn: async () => {
+ rejectDatasetRunToolsInEventsOnlyMode();
const result = await listDatasetRunItemsByRunIdForApi({
datasetId: input.datasetId,
datasetRunId: input.datasetRunId,
diff --git a/web/src/features/mcp/features/datasets/tools/listDatasetRuns.ts b/web/src/features/mcp/features/datasets/tools/listDatasetRuns.ts
index 5903326447..72c69065d5 100644
--- a/web/src/features/mcp/features/datasets/tools/listDatasetRuns.ts
+++ b/web/src/features/mcp/features/datasets/tools/listDatasetRuns.ts
@@ -3,6 +3,7 @@ import { listDatasetRunsByDatasetIdForApi } from "@/src/features/datasets/server
import { defineTool } from "../../../core/define-tool";
import { buildDatasetRunUrl } from "@/src/utils/product-url";
import { runMcpTool } from "../../../core/run-mcp-tool";
+import { rejectDatasetRunToolsInEventsOnlyMode } from "../events-only-guard";
import { GetDatasetRunsMcpInput } from "../schema";
export const [listDatasetRunsTool, handleListDatasetRuns] = defineTool({
@@ -17,6 +18,7 @@ export const [listDatasetRunsTool, handleListDatasetRuns] = defineTool({
context,
attributes: { "mcp.dataset_id": input.datasetId },
fn: async () => {
+ rejectDatasetRunToolsInEventsOnlyMode();
const result = await listDatasetRunsByDatasetIdForApi({
projectId: context.projectId,
datasetId: input.datasetId,
diff --git a/web/src/features/public-api/server/createAuthedProjectAPIRoute.ts b/web/src/features/public-api/server/createAuthedProjectAPIRoute.ts
index 61ef557e35..404c1c47f2 100644
--- a/web/src/features/public-api/server/createAuthedProjectAPIRoute.ts
+++ b/web/src/features/public-api/server/createAuthedProjectAPIRoute.ts
@@ -75,10 +75,10 @@ export type AuthedProjectAPIRouteConfig<
allowInAppAgentKey?: boolean;
/**
* When true, this route returns 404 if LANGFUSE_MIGRATION_V4_WRITE_MODE is
- * "events_only". Set this on routes that read from the legacy traces or
- * observations ClickHouse tables without an events_full fallback — those
- * tables are no longer populated in events_only mode and would silently
- * return stale or empty data.
+ * "events_only". Set this on routes that read from the legacy traces,
+ * observations, or dataset_run_items ClickHouse tables without an
+ * events_full fallback — those tables are no longer populated in
+ * events_only mode and would silently return stale or empty data.
*/
rejectInEventsOnlyMode?: boolean;
fn: (params: {
diff --git a/web/src/pages/api/public/dataset-run-items.ts b/web/src/pages/api/public/dataset-run-items.ts
index efe2c6232e..ca1c2f8e09 100644
--- a/web/src/pages/api/public/dataset-run-items.ts
+++ b/web/src/pages/api/public/dataset-run-items.ts
@@ -17,6 +17,10 @@ export default withMiddlewares({
bodySchema: PostDatasetRunItemsV1Body,
responseSchema: PostDatasetRunItemsV1Response,
rateLimitResource: "datasets",
+ // Writes a dataset-run-item event into the legacy dataset_run_items
+ // ClickHouse table; events_only deployments expect the experiment runner
+ // SDK or OTel ingestion with experiment attributes instead.
+ rejectInEventsOnlyMode: true,
fn: async ({ body, auth, res }) => {
return await createDatasetRunItemForApi({ body, auth, res });
},
@@ -26,6 +30,10 @@ export default withMiddlewares({
querySchema: GetDatasetRunItemsV1Query,
responseSchema: GetDatasetRunItemsV1Response,
rateLimitResource: "datasets",
+ // Reads from the legacy dataset_run_items ClickHouse table, which is no
+ // longer populated in events_only mode; GET /api/public/experiment-items
+ // is the replacement.
+ rejectInEventsOnlyMode: true,
fn: async ({ query, auth }) => {
return await listDatasetRunItemsForApi({
datasetId: query.datasetId,
diff --git a/web/src/pages/api/public/datasets/[name]/runs/[runName].ts b/web/src/pages/api/public/datasets/[name]/runs/[runName].ts
index 5c82be0398..8e0907eb24 100644
--- a/web/src/pages/api/public/datasets/[name]/runs/[runName].ts
+++ b/web/src/pages/api/public/datasets/[name]/runs/[runName].ts
@@ -17,6 +17,10 @@ export default withMiddlewares({
querySchema: GetDatasetRunV1Query,
responseSchema: GetDatasetRunV1Response,
rateLimitResource: "datasets",
+ // Embeds run items read from the legacy dataset_run_items ClickHouse
+ // table, which is no longer populated in events_only mode;
+ // GET /api/public/experiments + /experiment-items are the replacement.
+ rejectInEventsOnlyMode: true,
fn: async ({ query, auth }) =>
await getDatasetRunForApi({
projectId: auth.scope.projectId,
@@ -29,6 +33,10 @@ export default withMiddlewares({
querySchema: DeleteDatasetRunV1Query,
responseSchema: DeleteDatasetRunV1Response,
rateLimitResource: "datasets",
+ // Deletes legacy dataset runs and their dataset_run_items ClickHouse
+ // rows, which are no longer written in events_only mode; delete the
+ // underlying traces via DELETE /api/public/traces instead.
+ rejectInEventsOnlyMode: true,
fn: async ({ query, auth }) =>
await deleteDatasetRunForApi({
projectId: auth.scope.projectId,
diff --git a/web/src/pages/api/public/datasets/[name]/runs/index.ts b/web/src/pages/api/public/datasets/[name]/runs/index.ts
index ce01454fe8..4a4fe42f2a 100644
--- a/web/src/pages/api/public/datasets/[name]/runs/index.ts
+++ b/web/src/pages/api/public/datasets/[name]/runs/index.ts
@@ -12,6 +12,10 @@ export default withMiddlewares({
querySchema: GetDatasetRunsV1Query,
responseSchema: GetDatasetRunsV1Response,
rateLimitResource: "datasets",
+ // Lists legacy dataset runs whose items live in the dataset_run_items
+ // ClickHouse table, which is no longer populated in events_only mode;
+ // GET /api/public/experiments is the replacement.
+ rejectInEventsOnlyMode: true,
fn: async ({ query, auth }) =>
await listDatasetRunsForApi({
projectId: auth.scope.projectId,
diff --git a/web/src/pages/api/public/ingestion.ts b/web/src/pages/api/public/ingestion.ts
index 8913e41bb1..b3ea3f096b 100644
--- a/web/src/pages/api/public/ingestion.ts
+++ b/web/src/pages/api/public/ingestion.ts
@@ -234,7 +234,6 @@ export default async function handler(
const EVENTS_ONLY_ALLOWED_TYPES = new Set<string>([
eventTypes.SCORE_CREATE,
eventTypes.SDK_LOG,
- eventTypes.DATASET_RUN_ITEM_CREATE,
]);
function filterBatchForEventsOnly(
@@ -278,7 +277,7 @@ function filterBatchForEventsOnly(
id,
status: 400,
message: "Event type not accepted",
- error: `Event type "${type ?? "unknown"}" is not accepted by /api/public/ingestion when LANGFUSE_MIGRATION_V4_WRITE_MODE is events_only. This endpoint only accepts score, log, and dataset-run-item events.`,
+ error: `Event type "${type ?? "unknown"}" is not accepted by /api/public/ingestion when LANGFUSE_MIGRATION_V4_WRITE_MODE is events_only. This endpoint only accepts score and log events.`,
});
}
}