Skip to content

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

feat: add boolean score widgets and monitors (#15255)

Tobias Wochingerb0387f700020
diff --git a/fern/apis/server/definition/legacy/metrics-v1.yml b/fern/apis/server/definition/legacy/metrics-v1.yml
index 3fb254035b..c5a6925fe9 100644
--- a/fern/apis/server/definition/legacy/metrics-v1.yml
+++ b/fern/apis/server/definition/legacy/metrics-v1.yml
@@ -24,7 +24,7 @@ service:
JSON string containing the query parameters with the following structure:
```json
{
- "view": string, // Required. One of "traces", "observations", "scores-numeric", "scores-categorical"
+ "view": string, // Required. One of "traces", "observations", "scores-numeric", "scores-boolean", "scores-categorical"
"dimensions": [ // Optional. Default: []
{
"field": string // Field to group by, e.g. "name", "userId", "sessionId"
diff --git a/fern/apis/server/definition/metrics.yml b/fern/apis/server/definition/metrics.yml
index d50fae563e..bafa18f054 100644
--- a/fern/apis/server/definition/metrics.yml
+++ b/fern/apis/server/definition/metrics.yml
@@ -11,7 +11,7 @@ service:
Get metrics from the Langfuse project using a query object. V2 endpoint with optimized performance.
## V2 Differences
- - Supports `observations`, `scores-numeric`, and `scores-categorical` views only (traces view not supported)
+ - Supports `observations`, `scores-numeric`, `scores-boolean`, and `scores-categorical` views only (traces view not supported)
- Direct access to tags and release fields on observations
- Backwards-compatible: traceName, traceRelease, traceVersion dimensions are still available on observations view
- High cardinality dimensions are not supported and will return a 400 error (see below)
@@ -79,6 +79,16 @@ service:
- `count` - Total number of scores
- `value` - Score value (for aggregations)
+ ### scores-boolean
+ Query boolean score data. It has the same score and parent trace/observation dimensions as scores-numeric, plus:
+
+ **Dimensions:**
+ - `booleanValue` - Boolean value for true/false grouping and filtering
+
+ **Measures:**
+ - `count` - Total number of boolean scores
+ - `value` - Numeric 0/1 score value; `avg` returns the true-rate
+
### scores-categorical
Query categorical score data. Same dimensions as scores-numeric except uses `stringValue` instead of `value`.
@@ -96,7 +106,7 @@ service:
- `sessionId` - Use sessionId filter instead
- `parentObservationId` - Use parentObservationId filter instead
- **scores-numeric / scores-categorical views:**
+ **scores-numeric / scores-boolean / scores-categorical views:**
- `id` - Use specific filters to narrow down results
- `traceId` - Use traceId filter instead
- `userId` - Use userId filter instead
@@ -120,7 +130,7 @@ service:
JSON string containing the query parameters with the following structure:
```json
{
- "view": string, // Required. One of "observations", "scores-numeric", "scores-categorical"
+ "view": string, // Required. One of "observations", "scores-numeric", "scores-boolean", "scores-categorical"
"dimensions": [ // Optional. Default: []
{
"field": string // Field to group by (see available dimensions above)
diff --git a/fern/apis/server/definition/unstable/dashboard-widgets.yml b/fern/apis/server/definition/unstable/dashboard-widgets.yml
index 44a8d7187d..521265706b 100644
--- a/fern/apis/server/definition/unstable/dashboard-widgets.yml
+++ b/fern/apis/server/definition/unstable/dashboard-widgets.yml
@@ -41,7 +41,7 @@ service:
This endpoint creates the widget only; place it on a dashboard via
`POST /dashboards/{dashboardId}/placements`.
- Supported views are `observations`, `scores-numeric`, and `scores-categorical`.
+ Supported views are `observations`, `scores-numeric`, `scores-boolean`, and `scores-categorical`.
The legacy `traces` view is not supported by this unstable API.
Widgets are created as v2 internally.
@@ -165,6 +165,8 @@ types:
- observations
- name: ScoresNumeric
value: scores-numeric
+ - name: ScoresBoolean
+ value: scores-boolean
- name: ScoresCategorical
value: scores-categorical
@@ -176,6 +178,8 @@ types:
- observations
- name: ScoresNumeric
value: scores-numeric
+ - name: ScoresBoolean
+ value: scores-boolean
- name: ScoresCategorical
value: scores-categorical
- traces
diff --git a/packages/shared/prisma/migrations/20260721120000_add_boolean_score_widget_views/migration.sql b/packages/shared/prisma/migrations/20260721120000_add_boolean_score_widget_views/migration.sql
new file mode 100644
index 0000000000..a0abcb4590
--- /dev/null
+++ b/packages/shared/prisma/migrations/20260721120000_add_boolean_score_widget_views/migration.sql
@@ -0,0 +1,3 @@
+ALTER TYPE "DashboardWidgetViews" ADD VALUE 'SCORES_BOOLEAN';
+
+ALTER TYPE "MonitorView" ADD VALUE 'SCORES_BOOLEAN';
diff --git a/packages/shared/prisma/schema.prisma b/packages/shared/prisma/schema.prisma
index 35c33e03ec..2b7926ecfb 100644
--- a/packages/shared/prisma/schema.prisma
+++ b/packages/shared/prisma/schema.prisma
@@ -1554,6 +1554,7 @@ enum DashboardWidgetViews {
OBSERVATIONS
SCORES_NUMERIC
SCORES_CATEGORICAL
+ SCORES_BOOLEAN
}
enum DashboardWidgetChartType {
@@ -1766,6 +1767,7 @@ enum MonitorView {
OBSERVATIONS
SCORES_NUMERIC
SCORES_CATEGORICAL
+ SCORES_BOOLEAN
}
enum MonitorSeverity {
diff --git a/packages/shared/src/features/monitors/processor/buildPermalink.test.ts b/packages/shared/src/features/monitors/processor/buildPermalink.test.ts
index 41c2cc9048..049249df24 100644
--- a/packages/shared/src/features/monitors/processor/buildPermalink.test.ts
+++ b/packages/shared/src/features/monitors/processor/buildPermalink.test.ts
@@ -49,7 +49,7 @@ describe("buildDataWindowPermalink", () => {
);
});
- it.each(["scores-numeric", "scores-categorical"] as const)(
+ it.each(["scores-numeric", "scores-boolean", "scores-categorical"] as const)(
"links a %s monitor to the traces table windowed by dateRange",
(view) => {
envMock.env.NEXTAUTH_URL = "https://cloud.langfuse.com";
diff --git a/packages/shared/src/features/monitors/service/helpers.test.ts b/packages/shared/src/features/monitors/service/helpers.test.ts
index f51cdf78e0..ab08549908 100644
--- a/packages/shared/src/features/monitors/service/helpers.test.ts
+++ b/packages/shared/src/features/monitors/service/helpers.test.ts
@@ -409,6 +409,7 @@ describe("calculateSchedulerBatchId", () => {
for (const view of [
"observations",
"scores-numeric",
+ "scores-boolean",
"scores-categorical",
] as const) {
const id = calculateSchedulerBatchId({ ...base, view });
diff --git a/packages/shared/src/features/monitors/service/helpers.ts b/packages/shared/src/features/monitors/service/helpers.ts
index 269756a005..6d0b808d62 100644
--- a/packages/shared/src/features/monitors/service/helpers.ts
+++ b/packages/shared/src/features/monitors/service/helpers.ts
@@ -164,6 +164,8 @@ export const viewToPrisma = (view: MonitorView): PrismaMonitorView => {
return PrismaMonitorView.OBSERVATIONS;
case "scores-numeric":
return PrismaMonitorView.SCORES_NUMERIC;
+ case "scores-boolean":
+ return PrismaMonitorView.SCORES_BOOLEAN;
case "scores-categorical":
return PrismaMonitorView.SCORES_CATEGORICAL;
}
@@ -176,6 +178,8 @@ export const viewFromPrisma = (view: PrismaMonitorView): MonitorView => {
return "observations";
case PrismaMonitorView.SCORES_NUMERIC:
return "scores-numeric";
+ case PrismaMonitorView.SCORES_BOOLEAN:
+ return "scores-boolean";
case PrismaMonitorView.SCORES_CATEGORICAL:
return "scores-categorical";
}
diff --git a/packages/shared/src/features/query/dataModel.ts b/packages/shared/src/features/query/dataModel.ts
index acc8b99aaf..90aa6a26bc 100644
--- a/packages/shared/src/features/query/dataModel.ts
+++ b/packages/shared/src/features/query/dataModel.ts
@@ -995,9 +995,59 @@ function scoresCategoricalViewBase(version: "v1" | "v2"): ViewDeclarationType {
};
}
+function scoresBooleanViewBase(version: "v1" | "v2"): ViewDeclarationType {
+ const baseDimensions =
+ version === "v1" ? scoreBaseDimensions : scoresV2BaseDimensions;
+ return {
+ name: "scores_boolean",
+ description:
+ "Scores are flexible objects that are used for evaluations. This view contains boolean scores.",
+ dimensions: {
+ ...baseDimensions,
+ ...createScoreSpecificDimensions("scores_boolean", version === "v2"),
+ booleanValue: {
+ sql: "toBool(scores_boolean.value)",
+ alias: "booleanValue",
+ type: "boolean",
+ description: "Boolean value of the score.",
+ },
+ },
+ measures: {
+ count: {
+ sql: "count(*)",
+ alias: "count",
+ type: "integer",
+ description: "Total number of scores.",
+ unit: "scores",
+ },
+ value: {
+ sql: "any(value)",
+ alias: "value",
+ type: "number",
+ description:
+ "Numeric 0/1 value of the score. Its average is the true-rate.",
+ },
+ },
+ tableRelations: createScoreTableRelations(version),
+ segments: [
+ {
+ column: "data_type",
+ operator: "=" as const,
+ value: "BOOLEAN",
+ type: "string" as const,
+ },
+ ],
+ timeDimension: "timestamp",
+ baseCte: `scores scores_boolean FINAL`,
+ };
+}
+
export const scoresNumericView: ViewDeclarationType =
scoresNumericViewBase("v1");
+export const scoresBooleanView: ViewDeclarationType =
+ scoresBooleanViewBase("v1");
+
export const scoresCategoricalView: ViewDeclarationType =
scoresCategoricalViewBase("v1");
@@ -1005,6 +1055,9 @@ export const scoresCategoricalView: ViewDeclarationType =
export const scoresNumericViewV2: ViewDeclarationType =
scoresNumericViewBase("v2");
+export const scoresBooleanViewV2: ViewDeclarationType =
+ scoresBooleanViewBase("v2");
+
export const scoresCategoricalViewV2: ViewDeclarationType =
scoresCategoricalViewBase("v2");
@@ -1387,7 +1440,7 @@ export const eventsObservationsView: ViewDeclarationType = {
};
// Define versioned structure type
-// Both v1 and v2 have all views (traces, observations, scores-numeric, scores-categorical)
+// Both v1 and v2 have all views (traces, observations, and score views)
// v1 uses normalized tables (traces, observations), v2 uses events table
type VersionedViewDeclarations = {
readonly [version in ViewVersion]: {
@@ -1401,12 +1454,14 @@ export const viewDeclarations: VersionedViewDeclarations = {
traces: traceView,
observations: observationsView, // Old: observations table
"scores-numeric": scoresNumericView,
+ "scores-boolean": scoresBooleanView,
"scores-categorical": scoresCategoricalView,
},
v2: {
traces: eventsTracesView,
observations: eventsObservationsView,
"scores-numeric": scoresNumericViewV2,
+ "scores-boolean": scoresBooleanViewV2,
"scores-categorical": scoresCategoricalViewV2,
},
} as const;
diff --git a/packages/shared/src/features/query/server/queryBuilder.filterValidation.test.ts b/packages/shared/src/features/query/server/queryBuilder.filterValidation.test.ts
index ef1284e435..15d71da95b 100644
--- a/packages/shared/src/features/query/server/queryBuilder.filterValidation.test.ts
+++ b/packages/shared/src/features/query/server/queryBuilder.filterValidation.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it, vi } from "vitest";
import type { FilterCondition } from "../../../types";
+import { getViewDeclaration } from "../dataModel";
import type { QueryType, ViewVersion } from "../types";
import { QueryBuilder } from "./queryBuilder";
@@ -36,6 +37,13 @@ const buildQueryWithFilter = (
);
describe("queryBuilder filter type validation", () => {
+ it("exposes only the typed Boolean score value as a dimension", () => {
+ const view = getViewDeclaration("scores-boolean", "v2");
+
+ expect(view.dimensions.booleanValue?.uiHidden).toBeUndefined();
+ expect(view.dimensions.value).toBeUndefined();
+ });
+
it.each([
{
name: "arrayOptions on scalar string dimension",
@@ -73,6 +81,20 @@ describe("queryBuilder filter type validation", () => {
expectedMessage:
"Filter type 'string' is not supported for dimension type 'number'",
},
+ {
+ name: "string on boolean score dimension",
+ filter: {
+ column: "booleanValue",
+ operator: "=",
+ value: "true",
+ type: "string",
+ },
+ queryOverrides: {
+ view: "scores-boolean",
+ },
+ expectedMessage:
+ "Filter type 'string' is not supported for dimension type 'boolean'",
+ },
{
name: "string on time dimension",
filter: {
@@ -131,4 +153,19 @@ describe("queryBuilder filter type validation", () => {
expect(query).toContain("has");
});
+
+ it("lowers a compatible boolean score filter to a Boolean SQL predicate", async () => {
+ const { query } = await buildQueryWithFilter(
+ {
+ column: "booleanValue",
+ operator: "=",
+ value: true,
+ type: "boolean",
+ },
+ { view: "scores-boolean" },
+ );
+
+ expect(query).toContain("toBool(scores_boolean.value) = {booleanFilter");
+ expect(query).toContain(": Boolean}");
+ });
});
diff --git a/packages/shared/src/features/query/types.ts b/packages/shared/src/features/query/types.ts
index f0cd492af5..a80c1447a1 100644
--- a/packages/shared/src/features/query/types.ts
+++ b/packages/shared/src/features/query/types.ts
@@ -87,6 +87,7 @@ export const views = z.enum([
"observations",
"scores-numeric",
"scores-categorical",
+ "scores-boolean",
// "sessions",
// "users",
]);
@@ -96,6 +97,7 @@ export const viewsV2 = z.enum([
"observations",
"scores-numeric",
"scores-categorical",
+ "scores-boolean",
]);
export const viewVersions = z.enum(["v1", "v2"]);
diff --git a/packages/shared/src/server/clickhouse/schema.ts b/packages/shared/src/server/clickhouse/schema.ts
index 1998b1df5a..f3a40ee798 100644
--- a/packages/shared/src/server/clickhouse/schema.ts
+++ b/packages/shared/src/server/clickhouse/schema.ts
@@ -14,6 +14,7 @@ export const ClickhouseTableNames = {
// Virtual tables for dashboards
// TODO: Check if we can do this more elegantly
scores_numeric: "scores_numeric",
+ scores_boolean: "scores_boolean",
scores_categorical: "scores_categorical",
events_traces: "events_traces",
events_observations: "events_observations",
diff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.yml
index ec9f54dadd..29f7e4e213 100644
--- a/web/public/generated/api/openapi.yml
+++ b/web/public/generated/api/openapi.yml
@@ -1960,7 +1960,7 @@ paths:
```json
{
- "view": string, // Required. One of "traces", "observations", "scores-numeric", "scores-categorical"
+ "view": string, // Required. One of "traces", "observations", "scores-numeric", "scores-boolean", "scores-categorical"
"dimensions": [ // Optional. Default: []
{
"field": string // Field to group by, e.g. "name", "userId", "sessionId"
@@ -2755,8 +2755,8 @@ paths:
## V2 Differences
- - Supports `observations`, `scores-numeric`, and `scores-categorical`
- views only (traces view not supported)
+ - Supports `observations`, `scores-numeric`, `scores-boolean`, and
+ `scores-categorical` views only (traces view not supported)
- Direct access to tags and release fields on observations
@@ -2890,6 +2890,24 @@ paths:
- `value` - Score value (for aggregations)
+ ### scores-boolean
+
+ Query boolean score data. It has the same score and parent
+ trace/observation dimensions as scores-numeric, plus:
+
+
+ **Dimensions:**
+
+ - `booleanValue` - Boolean value for true/false grouping and filtering
+
+
+ **Measures:**
+
+ - `count` - Total number of boolean scores
+
+ - `value` - Numeric 0/1 score value; `avg` returns the true-rate
+
+
### scores-categorical
Query categorical score data. Same dimensions as scores-numeric except
@@ -2922,7 +2940,7 @@ paths:
- `parentObservationId` - Use parentObservationId filter instead
- **scores-numeric / scores-categorical views:**
+ **scores-numeric / scores-boolean / scores-categorical views:**
- `id` - Use specific filters to narrow down results
@@ -2961,7 +2979,7 @@ paths:
```json
{
- "view": string, // Required. One of "observations", "scores-numeric", "scores-categorical"
+ "view": string, // Required. One of "observations", "scores-numeric", "scores-boolean", "scores-categorical"
"dimensions": [ // Optional. Default: []
{
"field": string // Field to group by (see available dimensions above)
@@ -6616,8 +6634,8 @@ paths:
`POST /dashboards/{dashboardId}/placements`.
- Supported views are `observations`, `scores-numeric`, and
- `scores-categorical`.
+ Supported views are `observations`, `scores-numeric`, `scores-boolean`,
+ and `scores-categorical`.
The legacy `traces` view is not supported by this unstable API.
@@ -14819,6 +14837,7 @@ components:
enum:
- observations
- scores-numeric
+ - scores-boolean
- scores-categorical
unstableDashboardWidgetViewWithLegacy:
title: unstableDashboardWidgetViewWithLegacy
@@ -14826,6 +14845,7 @@ components:
enum:
- observations
- scores-numeric
+ - scores-boolean
- scores-categorical
- traces
description: |-
diff --git a/web/src/__tests__/server/mcp-tools-read.servertest.ts b/web/src/__tests__/server/mcp-tools-read.servertest.ts
index 561dc23d67..680d3c5983 100644
--- a/web/src/__tests__/server/mcp-tools-read.servertest.ts
+++ b/web/src/__tests__/server/mcp-tools-read.servertest.ts
@@ -1825,6 +1825,7 @@ describe("MCP Read Tools", () => {
"observations",
"scores-numeric",
"scores-categorical",
+ "scores-boolean",
],
granularities: expect.arrayContaining(["day"]),
config: {
@@ -1842,8 +1843,19 @@ describe("MCP Read Tools", () => {
},
},
},
+ "scores-boolean": {
+ dimensions: {
+ booleanValue: { type: "boolean" },
+ },
+ measures: {
+ value: {
+ validAggregations: expect.arrayContaining(["avg"]),
+ },
+ },
+ },
},
});
+ expect(views["scores-boolean"].dimensions.value).toBeUndefined();
expect(Reflect.get(Object(views), "traces")).toBeUndefined();
});
diff --git a/web/src/__tests__/server/metrics-v2-api.servertest.ts b/web/src/__tests__/server/metrics-v2-api.servertest.ts
index 06aa2a67dc..4bfed6f19b 100644
--- a/web/src/__tests__/server/metrics-v2-api.servertest.ts
+++ b/web/src/__tests__/server/metrics-v2-api.servertest.ts
@@ -566,6 +566,111 @@ describe("/api/public/v2/metrics API Endpoint", () => {
expect(response.status).toBe(200);
});
+
+ it("should query boolean scores with true/false breakdowns and true-rate aggregation", async () => {
+ const scoreName = `boolean-metrics-v2-${randomUUID()}`;
+ const scoreIds = Array.from({ length: 4 }, () => randomUUID());
+
+ await createScoresCh([
+ createTraceScore({
+ id: scoreIds[0],
+ project_id: projectId,
+ name: scoreName,
+ data_type: "BOOLEAN",
+ value: 1,
+ string_value: "true",
+ }),
+ createTraceScore({
+ id: scoreIds[1],
+ project_id: projectId,
+ name: scoreName,
+ data_type: "BOOLEAN",
+ value: 0,
+ string_value: "false",
+ }),
+ createTraceScore({
+ id: scoreIds[2],
+ project_id: projectId,
+ name: scoreName,
+ data_type: "BOOLEAN",
+ value: 1,
+ string_value: "true",
+ }),
+ createTraceScore({
+ id: scoreIds[3],
+ project_id: projectId,
+ name: scoreName,
+ data_type: "NUMERIC",
+ value: 1,
+ }),
+ ]);
+
+ const query = {
+ view: "scores-boolean",
+ dimensions: [{ field: "booleanValue" }],
+ metrics: [
+ { measure: "count", aggregation: "count" },
+ { measure: "value", aggregation: "avg" },
+ ],
+ filters: [
+ {
+ column: "name",
+ operator: "=",
+ value: scoreName,
+ type: "string",
+ },
+ ],
+ fromTimestamp: new Date(Date.now() - 86_400_000).toISOString(),
+ toTimestamp: new Date(Date.now() + 86_400_000).toISOString(),
+ };
+
+ const response = await makeZodVerifiedAPICall(
+ GetMetricsV1Response,
+ "GET",
+ `/api/public/v2/metrics?query=${encodeURIComponent(JSON.stringify(query))}`,
+ );
+
+ expect(response.status).toBe(200);
+ expect(response.body.data).toHaveLength(2);
+ expect(response.body.data).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({
+ booleanValue: true,
+ count_count: 2,
+ avg_value: 1,
+ }),
+ expect.objectContaining({
+ booleanValue: false,
+ count_count: 1,
+ avg_value: 0,
+ }),
+ ]),
+ );
+
+ const trueOnlyResponse = await makeZodVerifiedAPICall(
+ GetMetricsV1Response,
+ "GET",
+ `/api/public/v2/metrics?query=${encodeURIComponent(
+ JSON.stringify({
+ ...query,
+ dimensions: [],
+ filters: [
+ ...query.filters,
+ {
+ column: "booleanValue",
+ operator: "=",
+ value: true,
+ type: "boolean",
+ },
+ ],
+ }),
+ )}`,
+ );
+ expect(trueOnlyResponse.status).toBe(200);
+ expect(trueOnlyResponse.body.data).toEqual([
+ expect.objectContaining({ count_count: 2, avg_value: 1 }),
+ ]);
+ });
});
maybe("Time Dimension", () => {
diff --git a/web/src/__tests__/server/queryBuilder.servertest.ts b/web/src/__tests__/server/queryBuilder.servertest.ts
index 793e4b44d5..0f5c07e47a 100644
--- a/web/src/__tests__/server/queryBuilder.servertest.ts
+++ b/web/src/__tests__/server/queryBuilder.servertest.ts
@@ -208,6 +208,22 @@ describe("queryBuilder", () => {
orderBy: null,
} as QueryType,
],
+ [
+ "scores-boolean query",
+ {
+ view: "scores-boolean",
+ dimensions: [{ field: "booleanValue" }],
+ metrics: [
+ { measure: "count", aggregation: "count" },
+ { measure: "value", aggregation: "avg" },
+ ],
+ filters: [],
+ timeDimension: null,
+ fromTimestamp: "2025-01-01T00:00:00.000Z",
+ toTimestamp: "2025-03-01T00:00:00.000Z",
+ orderBy: null,
+ } as QueryType,
+ ],
[
"scores-numeric query with filters and time dimension",
{
@@ -2452,6 +2468,97 @@ describe("queryBuilder", () => {
});
});
+ describe("scores-boolean view", () => {
+ it("isolates boolean scores and supports boolean breakdowns, filters, and true-rate aggregation", async () => {
+ const projectId = randomUUID();
+ const timestamp = Date.now();
+
+ await createScoresCh([
+ createTraceScore({
+ project_id: projectId,
+ data_type: "BOOLEAN",
+ name: "boolean-widget-test",
+ value: 1,
+ string_value: "true",
+ timestamp,
+ }),
+ createTraceScore({
+ project_id: projectId,
+ data_type: "BOOLEAN",
+ name: "boolean-widget-test",
+ value: 0,
+ string_value: "false",
+ timestamp,
+ }),
+ createTraceScore({
+ project_id: projectId,
+ data_type: "BOOLEAN",
+ name: "boolean-widget-test",
+ value: 1,
+ string_value: "true",
+ timestamp,
+ }),
+ createTraceScore({
+ project_id: projectId,
+ data_type: "NUMERIC",
+ name: "boolean-widget-test",
+ value: 1,
+ timestamp,
+ }),
+ createTraceScore({
+ project_id: projectId,
+ data_type: "CATEGORICAL",
+ name: "boolean-widget-test",
+ string_value: "true",
+ timestamp,
+ }),
+ ]);
+
+ const baseQuery = {
+ view: "scores-boolean",
+ metrics: [
+ { measure: "count", aggregation: "count" },
+ { measure: "value", aggregation: "avg" },
+ ],
+ timeDimension: null,
+ fromTimestamp: new Date(timestamp - 86_400_000).toISOString(),
+ toTimestamp: new Date(timestamp + 86_400_000).toISOString(),
+ orderBy: null,
+ } satisfies Omit<QueryType, "dimensions" | "filters">;
+
+ const grouped = await executeQuery(projectId, {
+ ...baseQuery,
+ dimensions: [{ field: "booleanValue" }],
+ filters: [],
+ });
+
+ expect(grouped).toHaveLength(2);
+ const trueGroup = grouped.find((row) => row.booleanValue === true);
+ const falseGroup = grouped.find((row) => row.booleanValue === false);
+ expect(Number(trueGroup?.count_count)).toBe(2);
+ expect(Number(trueGroup?.avg_value)).toBe(1);
+ expect(Number(falseGroup?.count_count)).toBe(1);
+ expect(Number(falseGroup?.avg_value)).toBe(0);
+
+ const filtered = await executeQuery(projectId, {
+ ...baseQuery,
+ dimensions: [],
+ filters: [
+ {
+ column: "booleanValue",
+ operator: "=",
+ value: true,
+ type: "boolean",
+ },
+ ],
+ });
+
+ expect(filtered).toHaveLength(1);
+ expect(Number(filtered[0]?.count_count)).toBe(2);
+ expect(Number(filtered[0]?.avg_value)).toBe(1);
+ });
+ });
+
describe("scores-categorical view", () => {
it("should group categorical scores by value correctly", async () => {
// Setup
diff --git a/web/src/__tests__/server/unstable-dashboard-widgets-api.servertest.ts b/web/src/__tests__/server/unstable-dashboard-widgets-api.servertest.ts
index 9503c58c90..44b0dd4572 100644
--- a/web/src/__tests__/server/unstable-dashboard-widgets-api.servertest.ts
+++ b/web/src/__tests__/server/unstable-dashboard-widgets-api.servertest.ts
@@ -101,6 +101,43 @@ describe("/api/public/unstable/dashboard-widgets API", () => {
});
});
+ it("creates and persists a boolean score widget", async () => {
+ const { auth, projectId } = await createOrgProjectAndApiKey();
+
+ const response = await makeZodVerifiedAPICall(
+ PostUnstableDashboardWidgetResponse,
+ "POST",
+ "/api/public/unstable/dashboard-widgets",
+ {
+ ...baseWidgetBody,
+ name: "Boolean score widget",
+ view: "scores-boolean",
+ dimensions: [{ field: "booleanValue" }],
+ metrics: [{ measure: "value", agg: "avg" }],
+ filters: [
+ {
+ column: "booleanValue",
+ type: "boolean",
+ operator: "=",
+ value: true,
+ },
+ ],
+ },
+ auth,
+ );
+
+ expect(response.body).toMatchObject({
+ view: "scores-boolean",
+ dimensions: [{ field: "booleanValue" }],
+ metrics: [{ measure: "value", agg: "avg" }],
+ });
+ await expect(
+ prisma.dashboardWidget.findUniqueOrThrow({
+ where: { id: response.body.id, projectId },
+ }),
+ ).resolves.toMatchObject({ view: DashboardWidgetViews.SCORES_BOOLEAN });
+ });
+
it("rejects traces widgets", async () => {
const { auth } = await createOrgProjectAndApiKey();
diff --git a/web/src/features/dashboard/lib/dashboardUiTableToViewMapping.clienttest.ts b/web/src/features/dashboard/lib/dashboardUiTableToViewMapping.clienttest.ts
new file mode 100644
index 0000000000..c17b1ea299
--- /dev/null
+++ b/web/src/features/dashboard/lib/dashboardUiTableToViewMapping.clienttest.ts
@@ -0,0 +1,27 @@
+import { describe, expect, it } from "vitest";
+
+import {
+ mapViewFilterToUiTableFilter,
+ mapWidgetUiTableFilterToView,
+} from "./dashboardUiTableToViewMapping";
+
+describe("boolean score widget filter mappings", () => {
+ const booleanFilter = {
+ column: "booleanValue",
+ type: "boolean" as const,
+ operator: "=" as const,
+ value: true,
+ };
+
+ it("round-trips Boolean Value between editor and query view space", () => {
+ expect(
+ mapWidgetUiTableFilterToView("scores-boolean", [
+ { ...booleanFilter, column: "Boolean Value" },
+ ]),
+ ).toEqual([booleanFilter]);
+
+ expect(
+ mapViewFilterToUiTableFilter("scores-boolean", [booleanFilter]),
+ ).toEqual([{ ...booleanFilter, column: "Boolean Value" }]);
+ });
+});
diff --git a/web/src/features/dashboard/lib/dashboardUiTableToViewMapping.ts b/web/src/features/dashboard/lib/dashboardUiTableToViewMapping.ts
index f2763efb55..e2d1ff8561 100644
--- a/web/src/features/dashboard/lib/dashboardUiTableToViewMapping.ts
+++ b/web/src/features/dashboard/lib/dashboardUiTableToViewMapping.ts
@@ -213,6 +213,53 @@ const viewFilterDefinitions: Record<
sourceSpec("Version", { uiTableId: "version" }),
),
],
+ "scores-boolean": [
+ defineField("name", sourceSpec("Score Name", { uiTableId: "scoreName" })),
+ defineField(
+ "source",
+ sourceSpec("Score Source", { uiTableId: "scoreSource" }),
+ ),
+ defineField(
+ "booleanValue",
+ sourceSpec("Boolean Value", { uiTableId: "booleanValue" }),
+ ),
+ defineField(
+ "dataType",
+ sourceSpec("Scores Data Type", { uiTableId: "scoreDataType" }),
+ ),
+ defineField("tags", sourceSpec("Tags", { uiTableId: "traceTags" })),
+ defineField(
+ "environment",
+ sourceSpec("Environment", { uiTableId: "environment" }),
+ ),
+ defineField(
+ "userId",
+ sourceSpec("User", { uiTableId: "user" }),
+ sourceSpec("User", { uiTableId: "userId" }),
+ ),
+ defineField(
+ "sessionId",
+ sourceSpec("Session", { uiTableId: "session" }),
+ sourceSpec("Session", { uiTableId: "sessionId" }),
+ ),
+ defineField("metadata", sourceSpec("Metadata", { uiTableId: "metadata" })),
+ defineField(
+ "traceName",
+ sourceSpec("Trace Name", { uiTableId: "traceName" }),
+ ),
+ defineField(
+ "observationName",
+ sourceSpec("Observation Name", { uiTableId: "observationName" }),
+ ),
+ defineField(
+ "traceRelease",
+ sourceSpec("Release", { uiTableId: "release" }),
+ ),
+ defineField(
+ "traceVersion",
+ sourceSpec("Version", { uiTableId: "version" }),
+ ),
+ ],
"scores-categorical": [
defineField("name", sourceSpec("Score Name", { uiTableId: "scoreName" })),
defineField(
diff --git a/web/src/features/dashboard/lib/viewFilterToTableFilter.clienttest.ts b/web/src/features/dashboard/lib/viewFilterToTableFilter.clienttest.ts
index 46830ae166..203bb9fbe8 100644
--- a/web/src/features/dashboard/lib/viewFilterToTableFilter.clienttest.ts
+++ b/web/src/features/dashboard/lib/viewFilterToTableFilter.clienttest.ts
@@ -46,6 +46,7 @@ describe("tableTargetForView", () => {
it("routes traces and every scores-* view to the traces table", () => {
expect(tableTargetForView("traces")).toBe("traces");
expect(tableTargetForView("scores-numeric")).toBe("traces");
+ expect(tableTargetForView("scores-boolean")).toBe("traces");
expect(tableTargetForView("scores-categorical")).toBe("traces");
});
});
@@ -222,6 +223,14 @@ describe("classifyViewFiltersForTable", () => {
stringFilter("traceRelease"),
stringFilter("traceVersion"),
],
+ "scores-boolean": [
+ stringOptionsFilter("traceName"),
+ arrayOptionsFilter("tags"),
+ stringFilter("userId"),
+ stringFilter("sessionId"),
+ stringFilter("traceRelease"),
+ stringFilter("traceVersion"),
+ ],
"scores-categorical": [
stringOptionsFilter("traceName"),
arrayOptionsFilter("tags"),
diff --git a/web/src/features/dashboard/lib/viewFilterToTableFilter.ts b/web/src/features/dashboard/lib/viewFilterToTableFilter.ts
index 978d220782..2530b510d3 100644
--- a/web/src/features/dashboard/lib/viewFilterToTableFilter.ts
+++ b/web/src/features/dashboard/lib/viewFilterToTableFilter.ts
@@ -106,6 +106,15 @@ const VIEW_DIMENSION_TO_TABLE_COL: Record<
traceRelease: "release",
traceVersion: "version",
},
+ // scores-boolean view -> traces table (same trace-derived dimensions).
+ "scores-boolean": {
+ traceName: "traceName",
+ tags: "traceTags",
+ userId: "userId",
+ sessionId: "sessionId",
+ traceRelease: "release",
+ traceVersion: "version",
+ },
// scores-categorical view -> traces table (same trace-derived dimensions).
"scores-categorical": {
traceName: "traceName",
@@ -156,6 +165,17 @@ const DROPPED_REASONS: Partial<
observationName:
"Observation name has no equivalent column on the traces table.",
},
+ "scores-boolean": {
+ name: "Score name has no equivalent column on the traces table.",
+ source: "Score source has no equivalent column on the traces table.",
+ booleanValue: "Score value has no equivalent column on the traces table.",
+ dataType: "Score data type has no equivalent column on the traces table.",
+ metadata: "Score metadata does not map to trace metadata.",
+ environment:
+ "Score environment does not map to the trace environment column.",
+ observationName:
+ "Observation name has no equivalent column on the traces table.",
+ },
"scores-categorical": {
name: "Score name has no equivalent column on the traces table.",
source: "Score source has no equivalent column on the traces table.",
diff --git a/web/src/features/mcp/features/dashboardWidgets/tools/dashboardCrud.ts b/web/src/features/mcp/features/dashboardWidgets/tools/dashboardCrud.ts
index e76f28ffe8..70d1575663 100644
--- a/web/src/features/mcp/features/dashboardWidgets/tools/dashboardCrud.ts
+++ b/web/src/features/mcp/features/dashboardWidgets/tools/dashboardCrud.ts
@@ -67,7 +67,12 @@ const dashboardWidgetPatchBaseSchema = z.object({
name: z.string().min(1).optional(),
description: z.string().optional(),
view: z
- .enum(["observations", "scores-numeric", "scores-categorical"])
+ .enum([
+ "observations",
+ "scores-numeric",
+ "scores-boolean",
+ "scores-categorical",
+ ])
.optional(),
dimensions: z.array(z.object({ field: z.string() })).optional(),
metrics: z
diff --git a/web/src/features/monitors/components/MonitorForm.clienttest.ts b/web/src/features/monitors/components/MonitorForm.clienttest.ts
index 4f8fb7a490..399510c198 100644
--- a/web/src/features/monitors/components/MonitorForm.clienttest.ts
+++ b/web/src/features/monitors/components/MonitorForm.clienttest.ts
@@ -174,6 +174,30 @@ describe("buildFilterColumnsParams", () => {
expect(custom).not.toContain("type");
expect(custom).not.toContain("level");
});
+
+ it("offers a boolean value filter only for boolean score monitors", () => {
+ const booleanParams = buildFilterColumnsParams({
+ view: "scores-boolean",
+ filterOptions: undefined,
+ datasets: undefined,
+ });
+ const booleanColumns = getWidgetFilterColumns(booleanParams);
+ expect(
+ booleanColumns.find((column) => column.id === "booleanValue")?.type,
+ ).toBe("boolean");
+ expect(booleanColumns.some((column) => column.id === "value")).toBe(false);
+
+ const numericParams = buildFilterColumnsParams({
+ view: "scores-numeric",
+ filterOptions: undefined,
+ datasets: undefined,
+ });
+ expect(
+ getWidgetFilterColumns(numericParams).some(
+ (column) => column.id === "booleanValue",
+ ),
+ ).toBe(false);
+ });
});
describe("monitorToDefaults", () => {
diff --git a/web/src/features/monitors/components/MonitorForm.tsx b/web/src/features/monitors/components/MonitorForm.tsx
index 3055587af4..ee139e3d0c 100644
--- a/web/src/features/monitors/components/MonitorForm.tsx
+++ b/web/src/features/monitors/components/MonitorForm.tsx
@@ -171,7 +171,7 @@ const buildFilterColumnsParams = ({
filterOptions,
datasets,
}: {
- view: "traces" | "observations" | "scores-numeric" | "scores-categorical";
+ view: MonitorView;
filterOptions: RouterOutputs["events"]["filterOptions"] | undefined;
datasets: Array<{ id: string; name: string }> | undefined;
}) => {
@@ -355,11 +355,7 @@ export const MonitorForm = ({
const filterColumnsParams = useMemo(
() =>
buildFilterColumnsParams({
- view: (watched.view ?? "observations") as
- | "traces"
- | "observations"
- | "scores-numeric"
- | "scores-categorical",
+ view: (watched.view ?? "observations") as MonitorView,
filterOptions: eventsFilterOptions.data,
datasets: datasets.data,
}),
diff --git a/web/src/features/monitors/helpers/monitorLabels.ts b/web/src/features/monitors/helpers/monitorLabels.ts
index d634c411ab..f1b26ef012 100644
--- a/web/src/features/monitors/helpers/monitorLabels.ts
+++ b/web/src/features/monitors/helpers/monitorLabels.ts
@@ -42,5 +42,6 @@ export const operatorSymbol: Record<MonitorThresholdOperator, string> = {
export const viewLabels: Record<MonitorView, string> = {
observations: "Observations",
"scores-numeric": "Scores (numeric)",
+ "scores-boolean": "Scores (boolean)",
"scores-categorical": "Scores (categorical)",
};
diff --git a/web/src/features/public-api/types/unstable-dashboard-widgets.ts b/web/src/features/public-api/types/unstable-dashboard-widgets.ts
index f3c3b86850..49f51b6500 100644
--- a/web/src/features/public-api/types/unstable-dashboard-widgets.ts
+++ b/web/src/features/public-api/types/unstable-dashboard-widgets.ts
@@ -11,12 +11,14 @@ import { metricAggregations } from "@langfuse/shared/query";
export const PostUnstableDashboardWidgetView = z.enum([
"observations",
"scores-numeric",
+ "scores-boolean",
"scores-categorical",
]);
export const DashboardWidgetViewOutput = z.enum([
"observations",
"scores-numeric",
+ "scores-boolean",
"scores-categorical",
"traces",
]);
diff --git a/web/src/features/widgets/components/widgetFilterColumns.ts b/web/src/features/widgets/components/widgetFilterColumns.ts
index c986ea46a0..78b1e32321 100644
--- a/web/src/features/widgets/components/widgetFilterColumns.ts
+++ b/web/src/features/widgets/components/widgetFilterColumns.ts
@@ -141,6 +141,7 @@ const getWidgetFilterColumnSpecs = ({
if (
selectedView === "scores-numeric" ||
+ selectedView === "scores-boolean" ||
selectedView === "scores-categorical"
) {
filterColumns.push(
@@ -297,6 +298,17 @@ const getWidgetFilterColumnSpecs = ({
});
}
+ if (selectedView === "scores-boolean") {
+ filterColumns.push({
+ column: {
+ name: "Boolean Value",
+ id: "booleanValue",
+ type: "boolean",
+ internal: "internalValue",
+ },
+ });
+ }
+
return filterColumns;
};
diff --git a/web/src/features/widgets/server/public-dashboard-widget-service.ts b/web/src/features/widgets/server/public-dashboard-widget-service.ts
index 9453ea456d..e5e7d5478f 100644
--- a/web/src/features/widgets/server/public-dashboard-widget-service.ts
+++ b/web/src/features/widgets/server/public-dashboard-widget-service.ts
@@ -42,6 +42,7 @@ const viewMapping: Record<DashboardWidgetViewOutputType, DashboardWidgetViews> =
{
observations: DashboardWidgetViews.OBSERVATIONS,
"scores-numeric": DashboardWidgetViews.SCORES_NUMERIC,
+ "scores-boolean": DashboardWidgetViews.SCORES_BOOLEAN,
"scores-categorical": DashboardWidgetViews.SCORES_CATEGORICAL,
traces: DashboardWidgetViews.TRACES,
};
@@ -53,6 +54,7 @@ const reverseViewMapping: Record<
[DashboardWidgetViews.TRACES]: "traces",
[DashboardWidgetViews.OBSERVATIONS]: "observations",
[DashboardWidgetViews.SCORES_NUMERIC]: "scores-numeric",
+ [DashboardWidgetViews.SCORES_BOOLEAN]: "scores-boolean",
[DashboardWidgetViews.SCORES_CATEGORICAL]: "scores-categorical",
};
diff --git a/web/src/features/widgets/utils/import-export-utils.clienttest.ts b/web/src/features/widgets/utils/import-export-utils.clienttest.ts
index 9bee5fa23c..810324f3b0 100644
--- a/web/src/features/widgets/utils/import-export-utils.clienttest.ts
+++ b/web/src/features/widgets/utils/import-export-utils.clienttest.ts
@@ -152,6 +152,46 @@ describe("parseAndNormalizeImportedWidget", () => {
expect(result.snapshot.widgetMinVersion).toBe(1);
});
+ it("imports boolean score widgets with boolean filters intact", async () => {
+ const result = await importWidgetFile({
+ file: {
+ text: async () =>
+ JSON.stringify({
+ ...baseWidget,
+ view: "scores-boolean",
+ dimensions: [{ field: "booleanValue" }],
+ metrics: [{ measure: "value", agg: "avg" }],
+ filters: [
+ {
+ column: "booleanValue",
+ type: "boolean",
+ operator: "=",
+ value: true,
+ },
+ ],
+ minVersion: 2,
+ }),
+ } as File,
+ optionSets: { observationLevels: [] },
+ isBetaEnabled: true,
+ });
+
+ expect(result.snapshot).toMatchObject({
+ selectedView: "scores-boolean",
+ selectedDimension: "booleanValue",
+ selectedMeasure: "value",
+ selectedAggregation: "avg",
+ userFilterState: [
+ {
+ column: "Boolean Value",
+ type: "boolean",
+ operator: "=",
+ value: true,
+ },
+ ],
+ });
+ });
+
it("accepts an enveloped export file (round-trip)", async () => {
const result = await importWidgetFile({
file: {
diff --git a/web/src/server/api/routers/dashboardWidgets.ts b/web/src/server/api/routers/dashboardWidgets.ts
index 01aa2d15aa..1f8dba470a 100644
--- a/web/src/server/api/routers/dashboardWidgets.ts
+++ b/web/src/server/api/routers/dashboardWidgets.ts
@@ -69,6 +69,7 @@ const viewMapping: Record<string, DashboardWidgetViews> = {
traces: DashboardWidgetViews.TRACES,
observations: DashboardWidgetViews.OBSERVATIONS,
"scores-numeric": DashboardWidgetViews.SCORES_NUMERIC,
+ "scores-boolean": DashboardWidgetViews.SCORES_BOOLEAN,
"scores-categorical": DashboardWidgetViews.SCORES_CATEGORICAL,
};
@@ -80,6 +81,7 @@ const reverseViewMapping: Record<
[DashboardWidgetViews.TRACES]: "traces",
[DashboardWidgetViews.OBSERVATIONS]: "observations",
[DashboardWidgetViews.SCORES_NUMERIC]: "scores-numeric",
+ [DashboardWidgetViews.SCORES_BOOLEAN]: "scores-boolean",
[DashboardWidgetViews.SCORES_CATEGORICAL]: "scores-categorical",
};
diff --git a/worker/src/__tests__/__snapshots__/monitorProcessorScalarQuery.test.ts.snap b/worker/src/__tests__/__snapshots__/monitorProcessorScalarQuery.test.ts.snap
index 9c6c5d289a..bf2cd5431b 100644
--- a/worker/src/__tests__/__snapshots__/monitorProcessorScalarQuery.test.ts.snap
+++ b/worker/src/__tests__/__snapshots__/monitorProcessorScalarQuery.test.ts.snap
@@ -185,6 +185,28 @@ exports[`monitor scalar query — empty project > verifies which parameters retu
"observations/usageByType/p99": null,
"observations/usageByType/sum": null,
"observations/usageByType/uniq": null,
+ "scores-boolean/count/avg": null,
+ "scores-boolean/count/count": 0,
+ "scores-boolean/count/max": 0,
+ "scores-boolean/count/min": 0,
+ "scores-boolean/count/p50": null,
+ "scores-boolean/count/p75": null,
+ "scores-boolean/count/p90": null,
+ "scores-boolean/count/p95": null,
+ "scores-boolean/count/p99": null,
+ "scores-boolean/count/sum": 0,
+ "scores-boolean/count/uniq": 0,
+ "scores-boolean/value/avg": null,
+ "scores-boolean/value/count": 0,
+ "scores-boolean/value/max": 0,
+ "scores-boolean/value/min": 0,
+ "scores-boolean/value/p50": null,
+ "scores-boolean/value/p75": null,
+ "scores-boolean/value/p90": null,
+ "scores-boolean/value/p95": null,
+ "scores-boolean/value/p99": null,
+ "scores-boolean/value/sum": 0,
+ "scores-boolean/value/uniq": 0,
"scores-categorical/count/avg": null,
"scores-categorical/count/count": 0,
"scores-categorical/count/max": 0,
diff --git a/worker/src/__tests__/monitorProcessor.test.ts b/worker/src/__tests__/monitorProcessor.test.ts
index df16bf8d2a..fe130ddb46 100644
--- a/worker/src/__tests__/monitorProcessor.test.ts
+++ b/worker/src/__tests__/monitorProcessor.test.ts
@@ -21,7 +21,11 @@ import { prisma } from "@langfuse/shared/src/db";
import type { Prisma, PrismaClient } from "@prisma/client";
type MonitorStatus = "ACTIVE" | "PAUSED" | "ERROR_BAD_QUERY";
-type MonitorView = "OBSERVATIONS" | "SCORES_NUMERIC" | "SCORES_CATEGORICAL";
+type MonitorView =
+ | "OBSERVATIONS"
+ | "SCORES_NUMERIC"
+ | "SCORES_BOOLEAN"
+ | "SCORES_CATEGORICAL";
type MonitorSeverity =
| "UNKNOWN"
| "OK"
diff --git a/worker/src/__tests__/monitorScheduler.test.ts b/worker/src/__tests__/monitorScheduler.test.ts
index ec3b1a6cab..47df47d89c 100644
--- a/worker/src/__tests__/monitorScheduler.test.ts
+++ b/worker/src/__tests__/monitorScheduler.test.ts
@@ -14,7 +14,11 @@ import { prisma } from "@langfuse/shared/src/db";
import type { Prisma } from "@prisma/client";
type MonitorStatus = "ACTIVE" | "PAUSED" | "ERROR_BAD_QUERY";
-type MonitorView = "OBSERVATIONS" | "SCORES_NUMERIC" | "SCORES_CATEGORICAL";
+type MonitorView =
+ | "OBSERVATIONS"
+ | "SCORES_NUMERIC"
+ | "SCORES_BOOLEAN"
+ | "SCORES_CATEGORICAL";
type SeedOverrides = Partial<{
id: string;