Skip to content

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

chore: add eval tests (#1888)

Max Deichmann08b04811f1d9
diff --git a/worker/src/__tests__/eval-service.test.ts b/worker/src/__tests__/eval-service.test.ts
index 0fb896e658..67522aed06 100644
--- a/worker/src/__tests__/eval-service.test.ts
+++ b/worker/src/__tests__/eval-service.test.ts
@@ -569,6 +569,7 @@ describe("test variable extraction", () => {
},
]);
}, 10_000);
+
test("extracts variables from a observation", async () => {
await pruneDatabase();
const traceId = randomUUID();
@@ -631,6 +632,111 @@ describe("test variable extraction", () => {
]);
}, 10_000);
+ test("fails if observation is not present", async () => {
+ await pruneDatabase();
+ const traceId = randomUUID();
+
+ await kyselyPrisma.$kysely
+ .insertInto("traces")
+ .values({
+ id: traceId,
+ project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ user_id: "a",
+ input: { input: "This is a great prompt" },
+ output: { output: "This is a great response" },
+ })
+ .execute();
+
+ const variableMapping = variableMappingList.parse([
+ {
+ langfuseObject: "generation",
+ selectedColumnId: "input",
+ templateVariable: "input",
+ objectName: "great-llm-name",
+ },
+ {
+ langfuseObject: "generation",
+ selectedColumnId: "output",
+ templateVariable: "output",
+ objectName: "great-llm-name",
+ },
+ ]);
+
+ await expect(
+ extractVariablesFromTrace(
+ "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ ["input", "output"],
+ traceId,
+ variableMapping
+ )
+ ).rejects.toThrowError(
+ new LangfuseNotFoundError(
+ `Observation great-llm-name for trace ${traceId} not found. Please ensure the mapped data exists and consider extending the job delay.`
+ )
+ );
+ }, 10_000);
+
+ test("does not fail if observation data is null", async () => {
+ await pruneDatabase();
+ const traceId = randomUUID();
+
+ await kyselyPrisma.$kysely
+ .insertInto("traces")
+ .values({
+ id: traceId,
+ project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ user_id: "a",
+ input: { input: "This is a great prompt" },
+ output: { output: "This is a great response" },
+ })
+ .execute();
+
+ // fetching input and output for an observation which has NULL values
+ await kyselyPrisma.$kysely
+ .insertInto("observations")
+ .values({
+ id: randomUUID(),
+ trace_id: traceId,
+ name: "great-llm-name",
+ type: sql`'GENERATION'::"ObservationType"`,
+ project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ })
+ .execute();
+
+ const variableMapping = variableMappingList.parse([
+ {
+ langfuseObject: "generation",
+ selectedColumnId: "input",
+ templateVariable: "input",
+ objectName: "great-llm-name",
+ },
+ {
+ langfuseObject: "generation",
+ selectedColumnId: "output",
+ templateVariable: "output",
+ objectName: "great-llm-name",
+ },
+ ]);
+
+ const result = await extractVariablesFromTrace(
+ "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ ["input", "output"],
+ traceId,
+ variableMapping
+ );
+
+ expect(result).toEqual([
+ {
+ value: "",
+ var: "input",
+ },
+ {
+ value: "",
+ var: "output",
+ },
+ ]);
+ }, 10_000);
+
test("extracts variables from a youngest observation", async () => {
await pruneDatabase();
const traceId = randomUUID();
diff --git a/worker/src/eval-service.ts b/worker/src/eval-service.ts
index 357fa74f57..cbd242c105 100644
--- a/worker/src/eval-service.ts
+++ b/worker/src/eval-service.ts
@@ -432,10 +432,10 @@ export async function extractVariablesFromTrace(
// user facing errors
if (!observation) {
logger.error(
- `Observation ${mapping.objectName} for trace ${traceId} not found. Eval will succeed without observation input. Please ensure the mapped data exists and consider extending the job delay.`
+ `Observation ${mapping.objectName} for trace ${traceId} not found. Please ensure the mapped data exists and consider extending the job delay.`
);
throw new LangfuseNotFoundError(
- `Observation ${mapping.objectName} for trace ${traceId} not found. Eval will succeed without observation input. Please ensure the mapped data exists and consider extending the job delay.`
+ `Observation ${mapping.objectName} for trace ${traceId} not found. Please ensure the mapped data exists and consider extending the job delay.`
);
}