Skip to content

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

fix(evals): add evaluator filter validation and handling (#13474)

marliessophiec0ee8d29eae9
diff --git a/packages/shared/src/features/evals/validateEvaluatorFilters.ts b/packages/shared/src/features/evals/validateEvaluatorFilters.ts
new file mode 100644
index 0000000000..8d78e1d203
--- /dev/null
+++ b/packages/shared/src/features/evals/validateEvaluatorFilters.ts
@@ -0,0 +1,140 @@
+import { z } from "zod";
+import { singleFilter } from "../../interfaces/filters";
+import type { ColumnDefinition } from "../../tableDefinitions";
+import {
+ evalDatasetFormFilterCols,
+ evalTraceTableCols,
+} from "../../tableDefinitions/tracesTable";
+import type { FilterCondition, FilterState } from "../../types";
+import {
+ experimentEvalFilterColumns,
+ observationEvalFilterColumns,
+} from "./observationForEval";
+import { COMPATIBLE_FILTER_TYPES } from "../../server/queries/clickhouse-sql/filterTypeCompatibility";
+import {
+ EvalTargetObject,
+ type EvalTargetObject as EvalTargetObjectType,
+} from "./types";
+
+export type EvaluatorFilterValidationIssueCode =
+ | "invalid_filter_shape"
+ | "unsupported_column"
+ | "incompatible_filter_type";
+
+export type EvaluatorFilterValidationIssue = {
+ code: EvaluatorFilterValidationIssueCode;
+ message: string;
+ index: number | null;
+ column: string | null;
+ filterType: FilterCondition["type"] | null;
+ expectedColumnType?: ColumnDefinition["type"];
+};
+
+export type EvaluatorFilterValidationResult = {
+ isValid: boolean;
+ validatedFilters: FilterState;
+ issues: EvaluatorFilterValidationIssue[];
+};
+
+const parsedFilterSchema = z.array(singleFilter).nullable();
+
+const getSupportedColumnsForTarget = (
+ targetObject: EvalTargetObjectType,
+): ColumnDefinition[] => {
+ switch (targetObject) {
+ case EvalTargetObject.TRACE:
+ return evalTraceTableCols;
+ case EvalTargetObject.DATASET:
+ return evalDatasetFormFilterCols;
+ case EvalTargetObject.EVENT:
+ return observationEvalFilterColumns;
+ case EvalTargetObject.EXPERIMENT:
+ return experimentEvalFilterColumns;
+ }
+};
+
+const findMatchingColumnDefinition = (
+ filterColumn: string,
+ columns: ColumnDefinition[],
+): ColumnDefinition | undefined =>
+ columns.find(
+ (column) =>
+ column.id === filterColumn ||
+ column.name === filterColumn ||
+ column.aliases?.includes(filterColumn),
+ );
+
+export function validateEvaluatorFiltersForTarget(params: {
+ targetObject: EvalTargetObjectType;
+ filter: unknown;
+}): EvaluatorFilterValidationResult {
+ const columns = getSupportedColumnsForTarget(params.targetObject);
+ const parsedFilter = parsedFilterSchema.safeParse(params.filter);
+
+ if (!parsedFilter.success) {
+ return {
+ isValid: false,
+ validatedFilters: [],
+ issues: [
+ {
+ code: "invalid_filter_shape",
+ message:
+ "Evaluator filters are invalid. Remove unsupported or incomplete filters and try again.",
+ index: null,
+ column: null,
+ filterType: null,
+ },
+ ],
+ };
+ }
+
+ const filters = parsedFilter.data ?? [];
+
+ const issues: EvaluatorFilterValidationIssue[] = filters.flatMap(
+ (filter, index): EvaluatorFilterValidationIssue[] => {
+ const column = findMatchingColumnDefinition(filter.column, columns);
+
+ if (!column) {
+ return [
+ {
+ code: "unsupported_column" as const,
+ message: `Filter column "${filter.column}" is not supported for target "${params.targetObject}".`,
+ index,
+ column: filter.column,
+ filterType: filter.type,
+ },
+ ];
+ }
+
+ if (filter.type === "null") {
+ return [];
+ }
+
+ const compatibleFilterTypes = COMPATIBLE_FILTER_TYPES[column.type];
+
+ if (
+ compatibleFilterTypes &&
+ compatibleFilterTypes.includes(filter.type)
+ ) {
+ return [];
+ }
+
+ return [
+ {
+ code: "incompatible_filter_type" as const,
+ message: `Filter type "${filter.type}" is not supported for column "${column.name}".`,
+ index,
+ column: filter.column,
+ filterType: filter.type,
+ expectedColumnType: column.type,
+ },
+ ];
+ },
+ );
+
+ return {
+ isValid: issues.length === 0,
+ validatedFilters: filters,
+ issues,
+ };
+}
diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts
index 88ed7c2093..18006c6f2a 100644
--- a/packages/shared/src/index.ts
+++ b/packages/shared/src/index.ts
@@ -36,6 +36,7 @@ export * from "./features/evals/outputDefinition";
export * from "./features/evals/utilities";
export * from "./features/evals/observationForEval";
export * from "./features/evals/evalConfigBlocking";
+export * from "./features/evals/validateEvaluatorFilters";
// table actions
export * from "./features/batchExport/types";
export * from "./features/batchAction/types";
diff --git a/packages/shared/src/server/queries/clickhouse-sql/factory.ts b/packages/shared/src/server/queries/clickhouse-sql/factory.ts
index 277625f39c..7cb6d871ae 100644
--- a/packages/shared/src/server/queries/clickhouse-sql/factory.ts
+++ b/packages/shared/src/server/queries/clickhouse-sql/factory.ts
@@ -9,6 +9,7 @@ import {
type ColumnDefinition,
type UiColumnMappings,
} from "../../../tableDefinitions";
+import { COMPATIBLE_FILTER_TYPES } from "./filterTypeCompatibility";
import {
StringFilter,
DateTimeFilter,
@@ -30,21 +31,6 @@ export class QueryBuilderError extends Error {
}
}
-// Maps each ColumnDefinition.type to the filter types that are structurally compatible
-// at the ClickHouse level. string/stringOptions both operate on String columns,
-// and stringOptions "any of" works on Array columns too.
-const COMPATIBLE_FILTER_TYPES: Record<string, string[]> = {
- string: ["string", "stringOptions"],
- stringOptions: ["string", "stringOptions"],
- arrayOptions: ["arrayOptions", "stringOptions"],
- datetime: ["datetime"],
- number: ["number"],
- boolean: ["boolean"],
- stringObject: ["stringObject"],
- numberObject: ["numberObject"],
- categoryOptions: ["categoryOptions", "stringOptions"],
-};
-
// This function ensures that the user only selects valid columns from the clickhouse schema.
// The filter property in this column needs to be zod verified.
// User input for values (e.g. project_id = <value>) are sent to Clickhouse as parameters to prevent SQL injection
diff --git a/packages/shared/src/server/queries/clickhouse-sql/filterTypeCompatibility.ts b/packages/shared/src/server/queries/clickhouse-sql/filterTypeCompatibility.ts
new file mode 100644
index 0000000000..a7798c5c44
--- /dev/null
+++ b/packages/shared/src/server/queries/clickhouse-sql/filterTypeCompatibility.ts
@@ -0,0 +1,16 @@
+import type { ColumnDefinition } from "../../../tableDefinitions";
+import type { FilterCondition } from "../../../types";
+
+export const COMPATIBLE_FILTER_TYPES: Partial<
+ Record<ColumnDefinition["type"], FilterCondition["type"][]>
+> = {
+ string: ["string", "stringOptions"],
+ stringOptions: ["string", "stringOptions"],
+ arrayOptions: ["arrayOptions", "stringOptions"],
+ datetime: ["datetime"],
+ number: ["number"],
+ boolean: ["boolean"],
+ stringObject: ["stringObject"],
+ numberObject: ["numberObject"],
+ categoryOptions: ["categoryOptions", "stringOptions"],
+};
diff --git a/web/src/__tests__/server/evals-trpc.servertest.ts b/web/src/__tests__/server/evals-trpc.servertest.ts
index bae551ac4e..e51c093048 100644
--- a/web/src/__tests__/server/evals-trpc.servertest.ts
+++ b/web/src/__tests__/server/evals-trpc.servertest.ts
@@ -447,6 +447,47 @@ describe("evals trpc", () => {
}),
).resolves.toBeNull();
});
+
+ it("rejects unsupported trace filters", async () => {
+ const { project, caller } = await prepare();
+
+ const evalTemplate = await prisma.evalTemplate.create({
+ data: {
+ projectId: project.id,
+ name: "trace-template",
+ version: 1,
+ prompt: "Score this response",
+ outputDefinition: createNumericEvalOutputDefinition({
+ reasoningDescription: "Why",
+ scoreDescription: "How good",
+ }),
+ },
+ });
+
+ await expect(
+ caller.evals.createJob({
+ projectId: project.id,
+ evalTemplateId: evalTemplate.id,
+ scoreName: "bad-trace-filter",
+ target: EvalTargetObject.TRACE,
+ filter: [
+ {
+ type: "numberObject",
+ column: "Scores (numeric)",
+ key: "accuracy",
+ operator: ">",
+ value: 0.8,
+ },
+ ],
+ mapping: [],
+ sampling: 1,
+ delay: 0,
+ timeScope: ["NEW"],
+ }),
+ ).rejects.toThrow(
+ 'Filter column "Scores (numeric)" is not supported for target "trace".',
+ );
+ });
});
describe("evals.updateConfig", () => {
@@ -545,6 +586,84 @@ describe("evals trpc", () => {
expect(unchangedJob?.variableMapping).toEqual(traceVariableMapping);
});
+ it("rejects updates when an evaluator still has unsupported filters", async () => {
+ const { project, caller } = await prepare();
+
+ const evalJobConfig = await prisma.jobConfiguration.create({
+ data: {
+ projectId: project.id,
+ jobType: "EVAL",
+ scoreName: "test-score",
+ filter: [
+ {
+ type: "numberObject",
+ column: "Scores (numeric)",
+ key: "accuracy",
+ operator: ">",
+ value: 0.8,
+ },
+ ],
+ targetObject: EvalTargetObject.TRACE,
+ variableMapping: [],
+ sampling: 1,
+ delay: 0,
+ status: "ACTIVE",
+ timeScope: ["NEW"],
+ },
+ });
+
+ await expect(
+ caller.evals.updateEvalJob({
+ projectId: project.id,
+ evalConfigId: evalJobConfig.id,
+ config: {
+ status: "INACTIVE",
+ },
+ }),
+ ).rejects.toThrow(
+ 'Filter column "Scores (numeric)" is not supported for target "trace".',
+ );
+ });
+
+ it("allows updates once unsupported filters are removed", async () => {
+ const { project, caller } = await prepare();
+
+ const evalJobConfig = await prisma.jobConfiguration.create({
+ data: {
+ projectId: project.id,
+ jobType: "EVAL",
+ scoreName: "test-score",
+ filter: [
+ {
+ type: "numberObject",
+ column: "Scores (numeric)",
+ key: "accuracy",
+ operator: ">",
+ value: 0.8,
+ },
+ ],
+ targetObject: EvalTargetObject.TRACE,
+ variableMapping: [],
+ sampling: 1,
+ delay: 0,
+ status: "ACTIVE",
+ timeScope: ["NEW"],
+ },
+ });
+
+ const response = await caller.evals.updateEvalJob({
+ projectId: project.id,
+ evalConfigId: evalJobConfig.id,
+ config: {
+ filter: [],
+ status: "INACTIVE",
+ },
+ });
+
+ expect(response.status).toBe("INACTIVE");
+ expect(response.filter).toEqual([]);
+ });
+
it("when the evaluator ran on existing traces, time scope cannot be changed to NEW only", async () => {
const { project, caller } = await prepare();
diff --git a/web/src/__tests__/server/unit/evaluator-filter-validation.servertest.ts b/web/src/__tests__/server/unit/evaluator-filter-validation.servertest.ts
new file mode 100644
index 0000000000..3b2880398b
--- /dev/null
+++ b/web/src/__tests__/server/unit/evaluator-filter-validation.servertest.ts
@@ -0,0 +1,109 @@
+import {
+ EvalTargetObject,
+ validateEvaluatorFiltersForTarget,
+ type FilterState,
+} from "@langfuse/shared";
+
+describe("validateEvaluatorFiltersForTarget", () => {
+ it.each([
+ {
+ targetObject: EvalTargetObject.TRACE,
+ filter: [
+ {
+ type: "string",
+ column: "name",
+ operator: "=",
+ value: "checkout-trace",
+ },
+ ] satisfies FilterState,
+ },
+ {
+ targetObject: EvalTargetObject.DATASET,
+ filter: [
+ {
+ type: "stringOptions",
+ column: "Dataset",
+ operator: "any of",
+ value: ["dataset-1"],
+ },
+ ] satisfies FilterState,
+ },
+ {
+ targetObject: EvalTargetObject.EVENT,
+ filter: [
+ {
+ type: "stringOptions",
+ column: "Trace Name",
+ operator: "any of",
+ value: ["checkout"],
+ },
+ ] satisfies FilterState,
+ },
+ {
+ targetObject: EvalTargetObject.EXPERIMENT,
+ filter: [
+ {
+ type: "stringOptions",
+ column: "Dataset",
+ operator: "any of",
+ value: ["dataset-1"],
+ },
+ ] satisfies FilterState,
+ },
+ ])(
+ "accepts supported filters for $targetObject",
+ ({ targetObject, filter }) => {
+ const result = validateEvaluatorFiltersForTarget({
+ targetObject,
+ filter,
+ });
+
+ expect(result.isValid).toBe(true);
+ expect(result.issues).toEqual([]);
+ // Filter columns are passed through as-is (no normalization)
+ expect(result.validatedFilters).toEqual(filter);
+ },
+ );
+
+ it("rejects unsupported trace-level score filters", () => {
+ const result = validateEvaluatorFiltersForTarget({
+ targetObject: EvalTargetObject.TRACE,
+ filter: [
+ {
+ type: "numberObject",
+ column: "Scores (numeric)",
+ key: "accuracy",
+ operator: ">",
+ value: 0.8,
+ },
+ ] satisfies FilterState,
+ });
+
+ expect(result.isValid).toBe(false);
+ expect(result.issues[0]).toMatchObject({
+ code: "unsupported_column",
+ column: "Scores (numeric)",
+ });
+ });
+
+ it("rejects incompatible filter types", () => {
+ const result = validateEvaluatorFiltersForTarget({
+ targetObject: EvalTargetObject.EVENT,
+ filter: [
+ {
+ type: "number",
+ column: "environment",
+ operator: ">",
+ value: 1,
+ },
+ ] satisfies FilterState,
+ });
+
+ expect(result.isValid).toBe(false);
+ expect(result.issues[0]).toMatchObject({
+ code: "incompatible_filter_type",
+ column: "environment",
+ expectedColumnType: "stringOptions",
+ });
+ });
+});
diff --git a/web/src/features/evals/components/evaluator-detail.tsx b/web/src/features/evals/components/evaluator-detail.tsx
index 978d72650c..7351adc720 100644
--- a/web/src/features/evals/components/evaluator-detail.tsx
+++ b/web/src/features/evals/components/evaluator-detail.tsx
@@ -8,8 +8,14 @@ import Page from "@/src/components/layouts/page";
import { LevelCountsDisplay } from "@/src/components/level-counts-display";
import { generateJobExecutionCounts } from "@/src/features/evals/utils/job-execution-utils";
import { EvaluatorPausedCallout } from "@/src/features/evals/components/evaluator-paused-callout";
-import { type EvaluatorExecutionStatusCount } from "@langfuse/shared";
+import {
+ type EvalTargetObject,
+ type EvaluatorExecutionStatusCount,
+ validateEvaluatorFiltersForTarget,
+} from "@langfuse/shared";
import { useLazyEvaluatorExecutionCounts } from "@/src/features/evals/hooks/useLazyEvaluatorExecutionCounts";
+import { Alert, AlertDescription, AlertTitle } from "@/src/components/ui/alert";
+import { AlertTriangle } from "lucide-react";
const JobExecutionCounts = ({
isLoading,
@@ -42,6 +48,16 @@ export const EvaluatorDetail = () => {
evaluatorId,
evaluator: evaluator.data,
});
+ const filterValidation = React.useMemo(() => {
+ if (!evaluator.data) {
+ return null;
+ }
+
+ return validateEvaluatorFiltersForTarget({
+ targetObject: evaluator.data.targetObject as EvalTargetObject,
+ filter: evaluator.data.filter,
+ });
+ }, [evaluator.data]);
// get all templates for the current template name
const allTemplates = api.evals.allTemplatesForName.useQuery(
@@ -126,6 +142,19 @@ export const EvaluatorDetail = () => {
>
{existingEvaluator && (
<div className="flex h-full flex-col overflow-hidden">
+ {filterValidation && !filterValidation.isValid && (
+ <div className="mx-3 mt-3">
+ <Alert variant="destructive">
+ <AlertTriangle className="h-4 w-4" />
+ <AlertTitle>Unsupported filters</AlertTitle>
+ <AlertDescription>
+ This evaluator contains deprecated or unsupported filters. The
+ filters must be removed. Until the filters are removed, the
+ evaluator is paused and will not be run.{" "}
+ </AlertDescription>
+ </Alert>
+ </div>
+ )}
{existingEvaluator.blockedAt && (
<div className="mx-3 mt-3">
<EvaluatorPausedCallout
diff --git a/web/src/features/evals/components/inner-evaluator-form.tsx b/web/src/features/evals/components/inner-evaluator-form.tsx
index 3195c8e02e..4110004835 100644
--- a/web/src/features/evals/components/inner-evaluator-form.tsx
+++ b/web/src/features/evals/components/inner-evaluator-form.tsx
@@ -1,5 +1,5 @@
import { type UseFormReturn, useForm } from "react-hook-form";
-import { AlertDescription } from "@/src/components/ui/alert";
+import { Alert, AlertDescription, AlertTitle } from "@/src/components/ui/alert";
import { Input } from "@/src/components/ui/input";
import { Button } from "@/src/components/ui/button";
import {
@@ -24,6 +24,8 @@ import {
type ColumnDefinition,
type availableDatasetEvalVariables,
JobConfigState,
+ validateEvaluatorFiltersForTarget,
+ evalTraceTableCols,
} from "@langfuse/shared";
import { z } from "zod";
import { useEffect, useMemo, useState, memo } from "react";
@@ -38,6 +40,7 @@ import {
observationVariableMapping,
} from "@langfuse/shared";
import { useRouter } from "next/router";
+import { toast } from "sonner";
import { Slider } from "@/src/components/ui/slider";
import { Card } from "@/src/components/ui/card";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
@@ -335,6 +338,22 @@ export const InnerEvaluatorForm = (props: {
} = useEvalConfigFilterOptions({ projectId: props.projectId });
const targetState = useEvaluatorTargetState();
+
+ // Check if existing trace evaluator has invalid filters (e.g., score filters added by bug ff4b03c0b)
+ const hasInvalidTraceFilters = useMemo(() => {
+ if (
+ !props.existingEvaluator?.filter ||
+ props.existingEvaluator.targetObject !== EvalTargetObject.TRACE
+ ) {
+ return false;
+ }
+ const validation = validateEvaluatorFiltersForTarget({
+ targetObject: EvalTargetObject.TRACE,
+ filter: props.existingEvaluator.filter,
+ });
+ return !validation.isValid;
+ }, [props.existingEvaluator?.filter, props.existingEvaluator?.targetObject]);
+
const defaultTargetResult = EvalTargetObjectSchema.safeParse(
props.existingEvaluator?.targetObject ??
props.defaultTarget ??
@@ -457,11 +476,17 @@ export const InnerEvaluatorForm = (props: {
const utils = api.useUtils();
const createJobMutation = api.evals.createJob.useMutation({
onSuccess: () => utils.models.invalidate(),
- onError: (error) => setFormError(error.message),
+ onError: (error) => {
+ setFormError(error.message);
+ toast.error(error.message);
+ },
});
const updateJobMutation = api.evals.updateEvalJob.useMutation({
onSuccess: () => utils.evals.invalidate(),
- onError: (error) => setFormError(error.message),
+ onError: (error) => {
+ setFormError(error.message);
+ toast.error(error.message);
+ },
});
const [availableVariables, setAvailableVariables] = useState<
typeof availableTraceEvalVariables | typeof availableDatasetEvalVariables
@@ -691,6 +716,17 @@ export const InnerEvaluatorForm = (props: {
/>
{!props.hideTargetSection && (
<Card className="flex max-w-full flex-col gap-2 overflow-y-auto p-4">
+ {hasInvalidTraceFilters && (
+ <Alert variant="destructive">
+ <AlertTriangle className="h-4 w-4" />
+ <AlertTitle>Unsupported filter detected</AlertTitle>
+ <AlertDescription>
+ This evaluator has a filter that is not supported for
+ trace-level evaluators. It is effectively paused. Please remove
+ all filters and re-add them from scratch to resume execution.
+ </AlertDescription>
+ </Alert>
+ )}
<div className="flex flex-col gap-4">
{!props.hideTargetSelection && (
<FormField
@@ -1010,7 +1046,10 @@ export const InnerEvaluatorForm = (props: {
allowPropagationFilters,
);
} else if (isTraceTarget(target)) {
- return tracesTableColsWithOptions(traceFilterOptions);
+ return tracesTableColsWithOptions(
+ traceFilterOptions,
+ evalTraceTableCols,
+ );
} else if (isExperimentTarget(target)) {
// Experiment evaluators - only dataset filter
return experimentEvalFilterColsWithOptions(
diff --git a/web/src/features/evals/server/router.ts b/web/src/features/evals/server/router.ts
index 31d1396f53..e2fcdd7c90 100644
--- a/web/src/features/evals/server/router.ts
+++ b/web/src/features/evals/server/router.ts
@@ -27,6 +27,8 @@ import {
jsonSchema,
EvalTargetObject,
EvalTargetObjectSchema,
+ validateEvaluatorFiltersForTarget,
+ InvalidRequestError,
} from "@langfuse/shared";
import {
getQueue,
@@ -766,6 +768,17 @@ export const evalRouter = createTRPCRouter({
targetObject: input.target,
mapping: input.mapping,
});
+ const filterValidation = validateEvaluatorFiltersForTarget({
+ targetObject: input.target,
+ filter: input.filter ?? [],
+ });
+ if (!filterValidation.isValid) {
+ throw new InvalidRequestError(
+ filterValidation.issues[0]?.message ??
+ "Evaluator filters are invalid. Remove unsupported or incomplete filters and try again.",
+ );
+ }
+ const validatedFilter = filterValidation.validatedFilters;
const jobId = uuidv4();
await auditLog({
@@ -783,7 +796,7 @@ export const evalRouter = createTRPCRouter({
evalTemplateId: input.evalTemplateId,
scoreName: input.scoreName,
targetObject: input.target,
- filter: input.filter ?? [],
+ filter: validatedFilter ?? [],
variableMapping: variableMappingForTarget,
sampling: input.sampling,
delay: input.delay,
@@ -825,7 +838,7 @@ export const evalRouter = createTRPCRouter({
cutoffCreatedAt: new Date(),
targetObject: input.target,
query: {
- filter: input.filter ?? [],
+ filter: validatedFilter,
orderBy: {
column: "timestamp",
order: "DESC",
@@ -1185,6 +1198,17 @@ export const evalRouter = createTRPCRouter({
}
: {}),
};
+ const filterValidation = validateEvaluatorFiltersForTarget({
+ targetObject: existingJob.targetObject as EvalTargetObject,
+ filter: config.filter ?? existingJob.filter ?? [],
+ });
+ if (!filterValidation.isValid) {
+ throw new InvalidRequestError(
+ filterValidation.issues[0]?.message ??
+ "Evaluator filters are invalid. Remove unsupported or incomplete filters and try again.",
+ );
+ }
+ const validatedFilter = filterValidation.validatedFilters;
await auditLog({
session: ctx.session,
@@ -1216,6 +1240,11 @@ export const evalRouter = createTRPCRouter({
const updatedConfig = {
...validatedConfig,
+ ...(config.filter !== undefined
+ ? {
+ filter: validatedFilter ?? [],
+ }
+ : {}),
...(validatedConfig.status !== undefined
? resetEvalConfigBlockFields
: {}),
diff --git a/worker/src/features/evaluation/evalService.ts b/worker/src/features/evaluation/evalService.ts
index b374dfc743..ab5ead5a4b 100644
--- a/worker/src/features/evaluation/evalService.ts
+++ b/worker/src/features/evaluation/evalService.ts
@@ -60,7 +60,9 @@ import {
ScoreDataTypeEnum,
validateEvalOutputResult,
extractValueFromObject,
+ validateEvaluatorFiltersForTarget,
} from "@langfuse/shared";
+import { env } from "../../env";
import { prisma } from "@langfuse/shared/src/db";
import { createW3CTraceId } from "../utils";
import { UnrecoverableError } from "../../errors/UnrecoverableError";
@@ -371,6 +373,25 @@ export const createEvalJobs = async ({
continue;
}
+ // Self-hosted only: Skip trace-level evaluators with invalid filters.
+ // A bug (ff4b03c0b, Feb 2026) allowed score filters on trace evaluators, which the worker doesn't support.
+ // Cloud deployments are fixed; self-hosters need this runtime check.
+ if (
+ !env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION &&
+ config.targetObject === EvalTargetObject.TRACE
+ ) {
+ const filterValidation = validateEvaluatorFiltersForTarget({
+ targetObject: EvalTargetObject.TRACE,
+ filter: config.filter,
+ });
+ if (!filterValidation.isValid) {
+ logger.debug(
+ `Skipping trace evaluator ${config.id} with invalid filters: ${filterValidation.issues[0]?.message}`,
+ );
+ continue;
+ }
+ }
+
logger.debug("Creating eval job for config", config.id);
const validatedFilter = z.array(singleFilter).parse(config.filter);