Skip to content

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

fix(scores): update score validation logic to accept inclusive ranges for score config validation (#7650)

marliessophie38f020e48220
diff --git a/packages/shared/src/features/scores/interfaces/ingestion/validation.ts b/packages/shared/src/features/scores/interfaces/ingestion/validation.ts
index 103f30d575..9ea648994b 100644
--- a/packages/shared/src/features/scores/interfaces/ingestion/validation.ts
+++ b/packages/shared/src/features/scores/interfaces/ingestion/validation.ts
@@ -37,13 +37,13 @@ const ScorePropsAgainstConfigNumeric = z
dataType: z.literal("NUMERIC"),
})
.superRefine((data, ctx) => {
- if (isPresent(data.maxValue) && data.value >= data.maxValue) {
+ if (isPresent(data.maxValue) && data.value > data.maxValue) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `Value exceeds maximum value of ${data.maxValue} defined in config`,
});
}
- if (isPresent(data.minValue) && data.value <= data.minValue) {
+ if (isPresent(data.minValue) && data.value < data.minValue) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `Value is below minimum value of ${data.minValue} defined in config`,
diff --git a/web/src/__tests__/async/scores-api-v1.servertest.ts b/web/src/__tests__/async/scores-api-v1.servertest.ts
index 0a880597a5..71cb82cd2d 100644
--- a/web/src/__tests__/async/scores-api-v1.servertest.ts
+++ b/web/src/__tests__/async/scores-api-v1.servertest.ts
@@ -244,6 +244,67 @@ describe("/api/public/scores API Endpoint", () => {
"test-key": "test-value-updated",
});
});
+
+ it("should post score with score config if in valid range", async () => {
+ const configId = v4();
+ const traceId = v4();
+ const scoreId = v4();
+
+ const { projectId: projectId, auth } = await createOrgProjectAndApiKey();
+
+ const config = await prisma.scoreConfig.create({
+ data: {
+ name: "score-name",
+ id: configId,
+ dataType: "NUMERIC",
+ maxValue: 100,
+ projectId: projectId,
+ },
+ });
+
+ const trace = createTrace({
+ id: traceId,
+ project_id: projectId,
+ });
+ await createTracesCh([trace]);
+
+ const score = createTraceScore({
+ id: scoreId,
+ project_id: projectId,
+ trace_id: traceId,
+ name: "score-name",
+ value: 100,
+ source: "API",
+ comment: "comment",
+ metadata: { "test-key": "test-value" },
+ observation_id: null,
+ environment: "production",
+ config_id: config.id,
+ });
+ await createScoresCh([score]);
+
+ const fetchedScore = await makeZodVerifiedAPICall(
+ GetScoreResponseV1,
+ "GET",
+ `/api/public/scores/${scoreId}`,
+ undefined,
+ auth,
+ );
+
+ expect(fetchedScore.body?.id).toBe(scoreId);
+ expect(fetchedScore.body?.traceId).toBe(traceId);
+ expect(fetchedScore.body?.name).toBe("score-name");
+ expect(fetchedScore.body?.value).toBe(100);
+ expect(fetchedScore.body?.configId).toBe(configId);
+ expect(fetchedScore.body?.observationId).toBeNull();
+ expect(fetchedScore.body?.comment).toBe("comment");
+ expect(fetchedScore.body?.source).toBe("API");
+ expect(fetchedScore.body?.projectId).toBe(projectId);
+ expect(fetchedScore.body?.environment).toBe("production");
+ expect(fetchedScore.body?.metadata).toEqual({
+ "test-key": "test-value",
+ });
+ });
});
describe("GET /api/public/scores", () => {