Skip to content

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

fix(server): handle empty array options (#16086)

marliessophiee91c56cb74d5
diff --git a/web/src/__tests__/server/evals-trpc.servertest.ts b/web/src/__tests__/server/evals-trpc.servertest.ts
index 9b0d3ff1c1..d043c0aba6 100644
--- a/web/src/__tests__/server/evals-trpc.servertest.ts
+++ b/web/src/__tests__/server/evals-trpc.servertest.ts
@@ -352,6 +352,58 @@ describe("evals trpc", () => {
);
expect(response.totalCount).toBe(2);
});
+
+ // A Time Scope filter with no selected values is a reachable UI state
+ // (the facet's operator toggle can be flipped before any checkbox is
+ // checked). It must not crash the query — passing an empty value list
+ // into the Postgres array literal throws (`Prisma.join([])`), so the
+ // router treats an empty-value arrayOptions filter as no filter on that
+ // column. Only "all of"/"none of" can carry an empty value at all — the
+ // arrayOptionsFilter zod schema itself rejects "any of" with an empty
+ // value before this ever runs.
+ it.each(["all of", "none of"] as const)(
+ "does not throw and does not filter on an empty time scope value list ('%s')",
+ async (operator) => {
+ const { project, caller } = await prepare();
+
+ const evaluator = await prisma.jobConfiguration.create({
+ data: {
+ projectId: project.id,
+ jobType: "EVAL",
+ scoreName: "unfiltered-score",
+ filter: [],
+ targetObject: EvalTargetObject.TRACE,
+ variableMapping: [],
+ sampling: 1,
+ delay: 0,
+ status: "ACTIVE",
+ timeScope: ["NEW"],
+ },
+ });
+
+ const response = await caller.evals.allConfigs({
+ projectId: project.id,
+ filter: [
+ {
+ column: "timeScope",
+ type: "arrayOptions",
+ operator,
+ value: [],
+ },
+ ],
+ orderBy: {
+ column: "createdAt",
+ order: "DESC",
+ },
+ limit: 10,
+ page: 0,
+ });
+
+ expect(response.configs.map((config) => config.id)).toEqual([
+ evaluator.id,
+ ]);
+ },
+ );
});
describe("evals.templateNames", () => {
diff --git a/web/src/features/evals/server/router.ts b/web/src/features/evals/server/router.ts
index ad05bf96b0..7baceafbd8 100644
--- a/web/src/features/evals/server/router.ts
+++ b/web/src/features/evals/server/router.ts
@@ -520,9 +520,18 @@ export const evalRouter = createTRPCRouter({
projectId: input.projectId,
scope: "evalJob:read",
});
+ // Passing in empty arrayOptions is a no-op, so we exclude it
+ const sanitizedFilter = input.filter.filter(
+ (f) =>
+ !(
+ f.type === "arrayOptions" &&
+ f.value.length === 0 &&
+ f.operator !== "any of"
+ ),
+ );
const filterCondition = tableColumnsToSqlFilterAndPrefix(
- input.filter,
+ sanitizedFilter,
evalConfigFilterColumns,
"job_configurations",
);