🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(observation-evals): support parent observation is null filter (#12063)
marliessophie6098a5f1faa1
diff --git a/packages/shared/src/features/evals/observationForEval.ts b/packages/shared/src/features/evals/observationForEval.tsindex 399c50095c..06b068673e 100644--- a/packages/shared/src/features/evals/observationForEval.ts+++ b/packages/shared/src/features/evals/observationForEval.ts@@ -89,6 +89,7 @@ export type ObservationEvalFilterColumnInternal =| "tags"| "experiment_dataset_id"| "metadata"+ | "parent_span_id">;export type ObservationEvalMappingColumnInternal = keyof Pick<@@ -270,6 +271,13 @@ export const observationEvalFilterColumns: ObservationEvalColumnDef[] = [type: "stringObject",internal: "metadata",},+ {+ name: "Parent Observation",+ id: "parentObservationId",+ type: "null",+ internal: "parent_span_id",+ nullable: true,+ },];export const experimentEvalFilterColumns: ObservationEvalColumnDef[] = [diff --git a/packages/shared/src/tableDefinitions/types.ts b/packages/shared/src/tableDefinitions/types.tsindex f7ffb93fed..df221556c1 100644--- a/packages/shared/src/tableDefinitions/types.ts+++ b/packages/shared/src/tableDefinitions/types.ts@@ -26,7 +26,7 @@ export type ColumnDefinition =| {name: string;id: string;- type: "number" | "string" | "datetime" | "boolean";+ type: "number" | "string" | "datetime" | "boolean" | "null";internal: string;nullable?: boolean;}diff --git a/web/src/features/evals/pages/remap-evaluator.tsx b/web/src/features/evals/pages/remap-evaluator.tsxindex 6e5ff759d3..283fd96011 100644--- a/web/src/features/evals/pages/remap-evaluator.tsx+++ b/web/src/features/evals/pages/remap-evaluator.tsx@@ -21,6 +21,7 @@ import {} from "@/src/components/ui/dropdown-menu";import { ChevronDown } from "lucide-react";import { useEvalCapabilities } from "@/src/features/evals/hooks/useEvalCapabilities";+import { DEFAULT_OBSERVATION_FILTER_WHEN_REMAPPING } from "@/src/features/evals/utils/evaluator-constants";type LegacyEvalAction = "keep-active" | "mark-inactive" | "delete";@@ -87,7 +88,10 @@ export default function RemapEvaluatorPage() {scoreName: oldConfig.scoreName,targetObject: mapLegacyToModernTarget(oldConfig.targetObject),jobType: oldConfig.jobType,- filter: [],+ filter:+ oldConfig.targetObject === "trace"+ ? DEFAULT_OBSERVATION_FILTER_WHEN_REMAPPING+ : [],variableMapping: [],sampling: oldConfig.sampling,delay: oldConfig.delay,diff --git a/web/src/features/evals/utils/evaluator-constants.ts b/web/src/features/evals/utils/evaluator-constants.tsindex 3cae6a2f99..218ad6a6c5 100644--- a/web/src/features/evals/utils/evaluator-constants.ts+++ b/web/src/features/evals/utils/evaluator-constants.ts@@ -64,4 +64,20 @@ export const DEFAULT_OBSERVATION_FILTER = [value: ["GENERATION"],type: "stringOptions" as const,},+ {+ column: "environment",+ operator: "none of" as const,+ value: [...INTERNAL_ENVIRONMENTS],+ type: "stringOptions" as const,+ },+];++// Default filter when remapping an evaluator from trace-level to observation-level+export const DEFAULT_OBSERVATION_FILTER_WHEN_REMAPPING = [+ {+ column: "parentObservationId",+ operator: "is null" as const,+ value: "",+ type: "null" as const,+ },];diff --git a/web/src/features/filters/components/filter-builder.tsx b/web/src/features/filters/components/filter-builder.tsxindex c8096e5e36..dc82842414 100644--- a/web/src/features/filters/components/filter-builder.tsx+++ b/web/src/features/filters/components/filter-builder.tsx@@ -304,7 +304,9 @@ export function InlineFilterState({? filter.value: filter.type === "boolean"? `${filter.value}`- : `"${filter.value}"`}+ : filter.type === "null"+ ? ""+ : `"${filter.value}"`}</span>);});@@ -658,7 +660,10 @@ function FilterBuilderForm({column: col?.[columnIdentifier],type: col?.type,operator: defaultOperator,- value: undefined,+ value:+ col?.type === "null"+ ? ""+ : undefined,key:col?.type === "positionInTrace"? "last"@@ -820,8 +825,12 @@ function FilterBuilderForm({handleFilterChange({...filter,-operator: value as any,+ // Ensure null filters always have empty string value+ value:+ filter.type === "null"+ ? ""+ : (filter.value as any),},i,);@@ -986,7 +995,7 @@ function FilterBuilderForm({) : (<Input disabled placeholder="-" />)- ) : (+ ) : filter.type === "null" ? null : (<Input disabled />)}</td>diff --git a/worker/src/features/evaluation/observationEval/__tests__/filterEvaluation.test.ts b/worker/src/features/evaluation/observationEval/__tests__/filterEvaluation.test.tsindex 6fb0d09e8c..952991a0f9 100644--- a/worker/src/features/evaluation/observationEval/__tests__/filterEvaluation.test.ts+++ b/worker/src/features/evaluation/observationEval/__tests__/filterEvaluation.test.ts@@ -960,4 +960,128 @@ describe("Filter Evaluation for Observation Evals", () => {expect(matched).toBe(false);});});++ describe("null filters (parentObservationId)", () => {+ it("should match observations where parentObservationId is null (root observations)", async () => {+ const observation = createTestObservation({+ project_id: projectId,+ parent_span_id: null,+ });++ const matched = await testFilterMatch(observation, [+ {+ column: "parentObservationId",+ type: "null",+ operator: "is null",+ value: "",+ },+ ]);++ expect(matched).toBe(true);+ });++ it("should not match observations where parentObservationId is not null (child observations)", async () => {+ const observation = createTestObservation({+ project_id: projectId,+ parent_span_id: "some-parent-span-id",+ });++ const matched = await testFilterMatch(observation, [+ {+ column: "parentObservationId",+ type: "null",+ operator: "is null",+ value: "",+ },+ ]);++ expect(matched).toBe(false);+ });++ it("should match observations where parentObservationId is not null using 'is not null' operator", async () => {+ const observation = createTestObservation({+ project_id: projectId,+ parent_span_id: "some-parent-span-id",+ });++ const matched = await testFilterMatch(observation, [+ {+ column: "parentObservationId",+ type: "null",+ operator: "is not null",+ value: "",+ },+ ]);++ expect(matched).toBe(true);+ });++ it("should not match root observations with parentObservationId is not null using 'is not null' operator", async () => {+ const observation = createTestObservation({+ project_id: projectId,+ parent_span_id: null,+ });++ const matched = await testFilterMatch(observation, [+ {+ column: "parentObservationId",+ type: "null",+ operator: "is not null",+ value: "",+ },+ ]);++ expect(matched).toBe(false);+ });++ it("should combine null filter with other filters using AND logic", async () => {+ const observation = createTestObservation({+ project_id: projectId,+ parent_span_id: null,+ type: "GENERATION",+ });++ const matched = await testFilterMatch(observation, [+ {+ column: "parentObservationId",+ type: "null",+ operator: "is null",+ value: "",+ },+ {+ column: "type",+ type: "stringOptions",+ operator: "any of",+ value: ["GENERATION"],+ },+ ]);++ expect(matched).toBe(true);+ });++ it("should not match when null filter passes but other filter fails", async () => {+ const observation = createTestObservation({+ project_id: projectId,+ parent_span_id: null,+ type: "SPAN",+ });++ const matched = await testFilterMatch(observation, [+ {+ column: "parentObservationId",+ type: "null",+ operator: "is null",+ value: "",+ },+ {+ column: "type",+ type: "stringOptions",+ operator: "any of",+ value: ["GENERATION"],+ },+ ]);++ expect(matched).toBe(false);+ });+ });});diff --git a/worker/src/features/evaluation/observationEval/__tests__/observationForEvalSchema.test.ts b/worker/src/features/evaluation/observationEval/__tests__/observationForEvalSchema.test.tsindex 8456f8c5b8..0fdefc3e4d 100644--- a/worker/src/features/evaluation/observationEval/__tests__/observationForEvalSchema.test.ts+++ b/worker/src/features/evaluation/observationEval/__tests__/observationForEvalSchema.test.ts@@ -199,6 +199,7 @@ describe("observationForEvalSchema", () => {expect(columnIds).toContain("environment");expect(columnIds).toContain("level");expect(columnIds).toContain("version");+ expect(columnIds).toContain("parentObservationId");// Trace-level propertiesexpect(columnIds).toContain("traceName");