Skip to content

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

fix(eval-service): selected observation type not handled in eval service (#8586)

Nimard7a4a34df121
diff --git a/packages/shared/src/features/evals/types.ts b/packages/shared/src/features/evals/types.ts
index 7360634721..5e6df4786f 100644
--- a/packages/shared/src/features/evals/types.ts
+++ b/packages/shared/src/features/evals/types.ts
@@ -59,47 +59,38 @@ const observationCols = [
export const availableTraceEvalVariables = [
{
- id: "trace",
- display: "Trace",
- availableColumns: [
- {
- name: "Metadata",
- id: "metadata",
- type: "stringObject",
- internal: 't."metadata"',
- },
- { name: "Input", id: "input", internal: 't."input"' },
- { name: "Output", id: "output", internal: 't."output"' },
- ],
+ id: "agent",
+ display: "Agent",
+ availableColumns: observationCols,
},
{
- id: "span",
- display: "Span",
+ id: "chain",
+ display: "Chain",
availableColumns: observationCols,
},
{
- id: "generation",
- display: "Generation",
+ id: "embedding",
+ display: "Embedding",
availableColumns: observationCols,
},
{
- id: "event",
- display: "Event",
+ id: "evaluator",
+ display: "Evaluator",
availableColumns: observationCols,
},
{
- id: "agent",
- display: "Agent",
+ id: "event",
+ display: "Event",
availableColumns: observationCols,
},
{
- id: "tool",
- display: "Tool",
+ id: "generation",
+ display: "Generation",
availableColumns: observationCols,
},
{
- id: "chain",
- display: "Chain",
+ id: "guardrail",
+ display: "Guardrail",
availableColumns: observationCols,
},
{
@@ -108,19 +99,28 @@ export const availableTraceEvalVariables = [
availableColumns: observationCols,
},
{
- id: "evaluator",
- display: "Evaluator",
+ id: "span",
+ display: "Span",
availableColumns: observationCols,
},
{
- id: "embedding",
- display: "Embedding",
+ id: "tool",
+ display: "Tool",
availableColumns: observationCols,
},
{
- id: "guardrail",
- display: "Guardrail",
- availableColumns: observationCols,
+ id: "trace",
+ display: "Trace",
+ availableColumns: [
+ {
+ name: "Metadata",
+ id: "metadata",
+ type: "stringObject",
+ internal: 't."metadata"',
+ },
+ { name: "Input", id: "input", internal: 't."input"' },
+ { name: "Output", id: "output", internal: 't."output"' },
+ ],
},
];
diff --git a/worker/src/__tests__/evalService.test.ts b/worker/src/__tests__/evalService.test.ts
index d05039736a..53a16d46df 100644
--- a/worker/src/__tests__/evalService.test.ts
+++ b/worker/src/__tests__/evalService.test.ts
@@ -2,6 +2,7 @@ import {
ApiError,
LLMAdapter,
LangfuseNotFoundError,
+ ObservationType,
variableMappingList,
} from "@langfuse/shared";
import { encrypt } from "@langfuse/shared/encryption";
@@ -2084,6 +2085,78 @@ describe("eval service tests", () => {
},
]);
}, 10_000);
+
+ test.each(
+ Object.values(ObservationType).filter(
+ (type) => !["SPAN", "EVENT", "GENERATION"].includes(type),
+ ),
+ )(
+ "extracts variables from a %s observation",
+ async (observationType) => {
+ const traceId = randomUUID();
+
+ await upsertTrace({
+ id: traceId,
+ project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ user_id: "a",
+ input: JSON.stringify({ input: "This is a great prompt" }),
+ output: JSON.stringify({ output: "This is a great response" }),
+ timestamp: convertDateToClickhouseDateTime(new Date()),
+ created_at: convertDateToClickhouseDateTime(new Date()),
+ updated_at: convertDateToClickhouseDateTime(new Date()),
+ });
+
+ await upsertObservation({
+ id: randomUUID(),
+ trace_id: traceId,
+ project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ name: `great-${observationType.toLowerCase()}-name`,
+ type: observationType,
+ environment: "production",
+ input: JSON.stringify({ huhu: "This is a great prompt" }),
+ output: JSON.stringify({ haha: "This is a great response" }),
+ start_time: convertDateToClickhouseDateTime(new Date()),
+ created_at: convertDateToClickhouseDateTime(new Date()),
+ updated_at: convertDateToClickhouseDateTime(new Date()),
+ });
+
+ const variableMapping = variableMappingList.parse([
+ {
+ langfuseObject: observationType.toLowerCase(),
+ selectedColumnId: "input",
+ templateVariable: "input",
+ objectName: `great-${observationType.toLowerCase()}-name`,
+ },
+ {
+ langfuseObject: observationType.toLowerCase(),
+ selectedColumnId: "output",
+ templateVariable: "output",
+ objectName: `great-${observationType.toLowerCase()}-name`,
+ },
+ ]);
+
+ const result = await extractVariablesFromTracingData({
+ projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ variables: ["input", "output"],
+ traceId: traceId,
+ variableMapping: variableMapping,
+ });
+
+ expect(result).toEqual([
+ {
+ value: '{"huhu":"This is a great prompt"}',
+ var: "input",
+ environment: "production",
+ },
+ {
+ value: '{"haha":"This is a great response"}',
+ var: "output",
+ environment: "production",
+ },
+ ]);
+ },
+ 10_000,
+ );
});
test("requiresDatabaseLookup correctly identifies complex filters", () => {
diff --git a/worker/src/features/evaluation/evalService.ts b/worker/src/features/evaluation/evalService.ts
index 3882ef79bb..577205b5c7 100644
--- a/worker/src/features/evaluation/evalService.ts
+++ b/worker/src/features/evaluation/evalService.ts
@@ -920,7 +920,11 @@ export async function extractVariablesFromTracingData({
continue;
}
- if (["generation", "span", "event"].includes(mapping.langfuseObject)) {
+ const observationTypes = availableTraceEvalVariables
+ .filter((obj) => obj.id !== "trace") // trace is handled separately above
+ .map((obj) => obj.id);
+
+ if (observationTypes.includes(mapping.langfuseObject)) {
const safeInternalColumn = availableTraceEvalVariables
.find((o) => o.id === mapping.langfuseObject)
?.availableColumns.find((col) => col.id === mapping.selectedColumnId);