Skip to content

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

feat(scores): flatten v3 response shape to match proposal (#14088)

Niklas Semmlereea4629c3f47
diff --git a/fern/apis/server/_drafts/scores-v3.yml b/fern/apis/server/_drafts/scores-v3.yml
index 23b48946f4..f3336c8324 100644
--- a/fern/apis/server/_drafts/scores-v3.yml
+++ b/fern/apis/server/_drafts/scores-v3.yml
@@ -99,19 +99,6 @@ service:
response: GetScoresV3Response
types:
- ScoreDetailsV3:
- docs: Returned when fields includes "details".
- properties:
- comment:
- type: nullable<string>
- docs: Optional comment attached to the score.
- configId:
- type: nullable<string>
- docs: The score config ID, if this score was created from a config.
- metadata:
- type: map<string, unknown>
- docs: Arbitrary metadata attached to the score.
-
ScoreSubjectTraceV3:
properties:
id:
@@ -140,7 +127,7 @@ types:
docs: The dataset run ID (experiment ID).
ScoreSubjectV3:
- docs: Returned when fields includes "subject".
+ docs: A reference to the entity this score is attached to. Discriminated by "kind" — one of trace, observation, session, or experiment.
discriminant: kind
union:
trace:
@@ -156,16 +143,6 @@ types:
type: ScoreSubjectExperimentV3
docs: Subject is a dataset run (experiment) score.
- ScoreAnnotationV3:
- docs: Returned when fields includes "annotation".
- properties:
- authorUserId:
- type: nullable<string>
- docs: The user who created this score, if available.
- queueId:
- type: nullable<string>
- docs: The annotation queue this score belongs to, if any.
-
BaseScoreV3:
properties:
id: string
@@ -178,15 +155,24 @@ types:
docs: The environment from which this score originated.
createdAt: datetime
updatedAt: datetime
- details:
- type: optional<ScoreDetailsV3>
- docs: Present when "details" is included in the fields parameter.
+ comment:
+ type: optional<nullable<string>>
+ docs: Optional comment attached to the score. Present when "details" is included in the fields parameter.
+ configId:
+ type: optional<nullable<string>>
+ docs: The score config ID, if this score was created from a config. Present when "details" is included in the fields parameter.
+ metadata:
+ type: optional<map<string, unknown>>
+ docs: Arbitrary metadata attached to the score. Present when "details" is included in the fields parameter.
+ authorUserId:
+ type: optional<nullable<string>>
+ docs: The user who created this score, if available. Present when "annotation" is included in the fields parameter.
+ queueId:
+ type: optional<nullable<string>>
+ docs: The annotation queue this score belongs to, if any. Present when "annotation" is included in the fields parameter.
subject:
type: optional<ScoreSubjectV3>
- docs: Present when "subject" is included in the fields parameter.
- annotation:
- type: optional<ScoreAnnotationV3>
- docs: Present when "annotation" is included in the fields parameter.
+ docs: The entity this score is attached to (trace, observation, session, or experiment). Present when "subject" is included in the fields parameter.
NumericScoreV3:
extends: BaseScoreV3
diff --git a/packages/shared/src/features/scores/interfaces/api/v3/schemas.ts b/packages/shared/src/features/scores/interfaces/api/v3/schemas.ts
index f0892743b5..c878d81350 100644
--- a/packages/shared/src/features/scores/interfaces/api/v3/schemas.ts
+++ b/packages/shared/src/features/scores/interfaces/api/v3/schemas.ts
@@ -1,13 +1,6 @@
import { z } from "zod";
import { ScoreSourceDomain } from "../../../../../domain/scores";
-// Optional group schemas
-export const ScoreDetailsV3 = z.object({
- comment: z.string().nullable(),
- configId: z.string().nullable(),
- metadata: z.record(z.string(), z.unknown()),
-});
-
// Discriminated on `kind` so the type system enforces that `traceId` is
// only ever present on the observation arm — matches the Fern union and
// the deriveSubject runtime contract.
@@ -31,11 +24,6 @@ export const ScoreSubjectV3 = z.discriminatedUnion("kind", [
}),
]);
-export const ScoreAnnotationV3 = z.object({
- authorUserId: z.string().nullable(),
- queueId: z.string().nullable(),
-});
-
/**
* Foundation schema for scores API v3.
*
@@ -55,9 +43,12 @@ const ScoreFoundationSchemaV3 = z.object({
createdAt: z.coerce.date(),
updatedAt: z.coerce.date(),
// optional groups
- details: ScoreDetailsV3.optional(),
+ comment: z.string().nullable().optional(),
+ configId: z.string().nullable().optional(),
+ metadata: z.record(z.string(), z.unknown()).optional(),
+ authorUserId: z.string().nullable().optional(),
+ queueId: z.string().nullable().optional(),
subject: ScoreSubjectV3.optional(),
- annotation: ScoreAnnotationV3.optional(),
});
export const APIScoreSchemaV3 = z.discriminatedUnion("dataType", [
diff --git a/web/src/__tests__/server/scores-api-v3.servertest.ts b/web/src/__tests__/server/scores-api-v3.servertest.ts
index 6aa3c0144b..3acae29514 100644
--- a/web/src/__tests__/server/scores-api-v3.servertest.ts
+++ b/web/src/__tests__/server/scores-api-v3.servertest.ts
@@ -459,8 +459,8 @@ describe("/api/public/v3/scores API Endpoint", () => {
for (const s of res.body.data) {
expect(seenIds.has(s.id)).toBe(false);
seenIds.add(s.id);
- expect(s.details).toBeDefined();
- expect(s.details!.comment).toMatch(/^c\d$/);
+ expect(s.comment).toBeDefined();
+ expect(s.comment!).toMatch(/^c\d$/);
}
cursor = res.body.meta.cursor;
} while (cursor);
@@ -535,9 +535,12 @@ describe("/api/public/v3/scores API Endpoint", () => {
const score = res.body.data.find((s) => s.id === scoreId);
expect(score).toBeDefined();
- expect(score).not.toHaveProperty("details");
+ expect(score!.comment).toBeUndefined();
+ expect(score!.configId).toBeUndefined();
+ expect(score!.metadata).toBeUndefined();
expect(score).not.toHaveProperty("subject");
- expect(score).not.toHaveProperty("annotation");
+ expect(score!.authorUserId).toBeUndefined();
+ expect(score!.queueId).toBeUndefined();
});
it("fields=core,details → details present", async () => {
@@ -562,12 +565,12 @@ describe("/api/public/v3/scores API Endpoint", () => {
const score = res.body.data.find((s) => s.id === scoreId);
expect(score).toBeDefined();
- expect(score!.details).toBeDefined();
- expect(score!.details!.comment).toBe("test comment");
- expect(score!.details!.configId).toBe("cfg-abc");
- expect(score!.details!.metadata).toEqual({ key: "val" });
+ expect(score!.comment).toBe("test comment");
+ expect(score!.configId).toBe("cfg-abc");
+ expect(score!.metadata).toEqual({ key: "val" });
expect(score).not.toHaveProperty("subject");
- expect(score).not.toHaveProperty("annotation");
+ expect(score!.authorUserId).toBeUndefined();
+ expect(score!.queueId).toBeUndefined();
});
it("fields=core,annotation → annotation present", async () => {
@@ -591,10 +594,11 @@ describe("/api/public/v3/scores API Endpoint", () => {
const score = res.body.data.find((s) => s.id === scoreId);
expect(score).toBeDefined();
- expect(score!.annotation).toBeDefined();
- expect(score!.annotation!.authorUserId).toBe("user-xyz");
- expect(score!.annotation!.queueId).toBe("queue-abc");
- expect(score).not.toHaveProperty("details");
+ expect(score!.authorUserId).toBe("user-xyz");
+ expect(score!.queueId).toBe("queue-abc");
+ expect(score!.comment).toBeUndefined();
+ expect(score!.configId).toBeUndefined();
+ expect(score!.metadata).toBeUndefined();
expect(score).not.toHaveProperty("subject");
});
@@ -617,9 +621,8 @@ describe("/api/public/v3/scores API Endpoint", () => {
const score = res.body.data.find((s) => s.id === scoreId);
expect(score).toBeDefined();
- expect(score!.annotation).toBeDefined();
- expect(score!.annotation!.authorUserId).toBeNull();
- expect(score!.annotation!.queueId).toBeNull();
+ expect(score!.authorUserId).toBeNull();
+ expect(score!.queueId).toBeNull();
});
it("fields=core,subject → trace score has kind=trace", async () => {
@@ -764,9 +767,12 @@ describe("/api/public/v3/scores API Endpoint", () => {
expect(res.status).toBe(200);
const score = res.body.data.find((s) => s.id === scoreId);
expect(score).toBeDefined();
- expect(score).not.toHaveProperty("details");
+ expect(score!.comment).toBeUndefined();
+ expect(score!.configId).toBeUndefined();
+ expect(score!.metadata).toBeUndefined();
expect(score).not.toHaveProperty("subject");
- expect(score).not.toHaveProperty("annotation");
+ expect(score!.authorUserId).toBeUndefined();
+ expect(score!.queueId).toBeUndefined();
});
it("fields=core,details,subject,annotation → all groups present simultaneously", async () => {
@@ -792,9 +798,12 @@ describe("/api/public/v3/scores API Endpoint", () => {
expect(res.status).toBe(200);
const score = res.body.data.find((s) => s.id === scoreId);
expect(score).toBeDefined();
- expect(score).toHaveProperty("details");
+ expect(score).toHaveProperty("comment");
+ expect(score).toHaveProperty("configId");
+ expect(score).toHaveProperty("metadata");
expect(score).toHaveProperty("subject");
- expect(score).toHaveProperty("annotation");
+ expect(score).toHaveProperty("authorUserId");
+ expect(score).toHaveProperty("queueId");
expect(score!.subject!.kind).toBe("trace");
expect(score!.subject!.id).toBe(traceId);
});
@@ -1556,7 +1565,7 @@ describe("/api/public/v3/scores API Endpoint", () => {
expect(res.status).toBe(200);
expect(
res.body.data.length > 0 &&
- res.body.data.every((s) => s.details?.configId === configId),
+ res.body.data.every((s) => s.configId === configId),
).toBe(true);
const ids = res.body.data.map((s) => s.id);
expect(ids).toContain(scoreId);
@@ -1587,7 +1596,7 @@ describe("/api/public/v3/scores API Endpoint", () => {
expect(res.status).toBe(200);
expect(
res.body.data.length > 0 &&
- res.body.data.every((s) => s.annotation?.queueId === queueId),
+ res.body.data.every((s) => s.queueId === queueId),
).toBe(true);
const ids = res.body.data.map((s) => s.id);
expect(ids).toContain(scoreId);
@@ -1618,7 +1627,7 @@ describe("/api/public/v3/scores API Endpoint", () => {
expect(res.status).toBe(200);
expect(
res.body.data.length > 0 &&
- res.body.data.every((s) => s.annotation?.authorUserId === userId),
+ res.body.data.every((s) => s.authorUserId === userId),
).toBe(true);
const ids = res.body.data.map((s) => s.id);
expect(ids).toContain(scoreId);
@@ -1762,7 +1771,7 @@ describe("/api/public/v3/scores API Endpoint", () => {
expect(res.status).toBe(200);
expect(res.body.meta.limit).toBe(10);
const score = res.body.data.find((s) => s.id === scoreId);
- expect(score?.details?.comment).toBe("regression-check");
+ expect(score?.comment).toBe("regression-check");
});
});
});
diff --git a/web/src/features/public-api/server/scores-api-v3.ts b/web/src/features/public-api/server/scores-api-v3.ts
index 509a3a3865..5a31ca6c1f 100644
--- a/web/src/features/public-api/server/scores-api-v3.ts
+++ b/web/src/features/public-api/server/scores-api-v3.ts
@@ -113,22 +113,18 @@ function domainToV3(
updatedAt: score.updatedAt,
...(fields.includes("details")
? {
- details: {
- comment: score.comment,
- configId: score.configId,
- metadata: score.metadata,
- },
+ comment: score.comment,
+ configId: score.configId,
+ metadata: score.metadata,
}
: {}),
- ...(fields.includes("subject") ? { subject: deriveSubject(score) } : {}),
...(fields.includes("annotation")
? {
- annotation: {
- authorUserId: score.authorUserId,
- queueId: score.queueId,
- },
+ authorUserId: score.authorUserId,
+ queueId: score.queueId,
}
: {}),
+ ...(fields.includes("subject") ? { subject: deriveSubject(score) } : {}),
} as APIScoreV3;
}