Skip to content

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

feat(traces): Add none filter mode for tags in the sidebar (#13339)

Ben Bachem0f7ccc80a53c
diff --git a/packages/shared/src/interfaces/filters.ts b/packages/shared/src/interfaces/filters.ts
index fa2be0df55..817499acf7 100644
--- a/packages/shared/src/interfaces/filters.ts
+++ b/packages/shared/src/interfaces/filters.ts
@@ -53,10 +53,16 @@ export const arrayOptionsFilter = z
value: z.array(z.string()),
type: z.literal("arrayOptions"),
})
- .refine((data) => data.operator === "all of" || data.value.length > 0, {
- message:
- "Value array must not be empty unless operator is 'all of' (which represents waiting for selection)",
- });
+ .refine(
+ (data) =>
+ data.operator === "all of" ||
+ data.operator === "none of" ||
+ data.value.length > 0,
+ {
+ message:
+ "Value array must not be empty unless operator is 'all of' or 'none of' (which represent waiting for selection)",
+ },
+ );
export const stringObjectFilter = z.object({
type: z.literal("stringObject"),
column: z.string(),
diff --git a/web/src/components/table/data-table-controls.tsx b/web/src/components/table/data-table-controls.tsx
index 3001d2de8e..d5ffc0403f 100644
--- a/web/src/components/table/data-table-controls.tsx
+++ b/web/src/components/table/data-table-controls.tsx
@@ -349,8 +349,8 @@ interface CategoricalFacetProps extends BaseFacetProps {
onChange: (values: string[]) => void;
onOnlyChange?: (value: string) => void;
renderIcon?: (value: string) => React.ReactNode;
- operator?: "any of" | "all of";
- onOperatorChange?: (operator: "any of" | "all of") => void;
+ operator?: "any of" | "all of" | "none of";
+ onOperatorChange?: (operator: "any of" | "all of" | "none of") => void;
textFilters?: TextFilterEntry[];
onTextFilterAdd?: (
operator: "contains" | "does not contain",
@@ -636,23 +636,26 @@ export function CategoricalFacet({
{/* SELECT MODE: Checkboxes with optional counts */}
{filterMode === "select" && (
<div className="px-2">
- {/* SOME/ALL Operator Toggle for arrayOptions filters
+ {/* SOME/ALL/NONE operator toggle for arrayOptions filters
This toggle appears for multi-valued array columns (arrayOptions) like tags.
- It allows switching between OR and AND logic:
+ It allows switching between the supported array matching modes:
- SOME: Match items with ANY selected value (OR logic)
- ALL: Match items with ALL selected values (AND logic)
+ - NONE: Exclude items with ANY selected value
- The toggle is automatically enabled by useSidebarFilterState for any
- arrayOptions column when selections exist. Other filter types (stringOptions,
- boolean, numeric) don't get this toggle as "ALL" wouldn't be semantically meaningful.
+ The toggle is shown whenever useSidebarFilterState exposes operator controls
+ for an arrayOptions column, including before any values are selected so users
+ can persist an operator preference first. Other filter types (stringOptions,
+ boolean, numeric) don't get this toggle because these array-specific modes
+ are not semantically meaningful there.
Currently enabled for:
- Traces: tags
- Sessions: userIds, tags
- Prompts: labels, tags
*/}
- {onOperatorChange && value.length > 0 && (
+ {onOperatorChange && (
<div className="mb-1.5 flex items-center gap-1.5 px-2">
<span className="text-muted-foreground/80 text-[10px]">
Match:
@@ -673,7 +676,7 @@ export function CategoricalFacet({
<button
onClick={() => onOperatorChange("all of")}
className={cn(
- "rounded-r px-1.5 py-0.5 transition-colors",
+ "px-1.5 py-0.5 transition-colors",
operator === "all of"
? "bg-accent text-accent-foreground font-medium"
: "text-muted-foreground hover:text-foreground",
@@ -681,6 +684,18 @@ export function CategoricalFacet({
>
ALL
</button>
+ <div className="bg-border/50 w-px" />
+ <button
+ onClick={() => onOperatorChange("none of")}
+ className={cn(
+ "rounded-r px-1.5 py-0.5 transition-colors",
+ operator === "none of"
+ ? "bg-accent text-accent-foreground font-medium"
+ : "text-muted-foreground hover:text-foreground",
+ )}
+ >
+ NONE
+ </button>
</div>
</div>
)}
diff --git a/web/src/components/table/use-cases/observations.tsx b/web/src/components/table/use-cases/observations.tsx
index 0bde400ea3..1e1f966870 100644
--- a/web/src/components/table/use-cases/observations.tsx
+++ b/web/src/components/table/use-cases/observations.tsx
@@ -983,7 +983,8 @@ export default function ObservationsTable({
cell: ({ row }) => {
const traceTags: string[] | undefined = row.getValue("traceTags");
return (
- traceTags && (
+ traceTags &&
+ traceTags.length > 0 && (
<div
className={cn(
"flex gap-x-2 gap-y-1",
diff --git a/web/src/components/table/use-cases/scores.tsx b/web/src/components/table/use-cases/scores.tsx
index b9d43377bc..a009b1950c 100644
--- a/web/src/components/table/use-cases/scores.tsx
+++ b/web/src/components/table/use-cases/scores.tsx
@@ -742,7 +742,8 @@ export default function ScoresTable({
return <TableTextLoadingCell />;
const traceTags: string[] | undefined = row.getValue("traceTags");
return (
- traceTags && (
+ traceTags &&
+ traceTags.length > 0 && (
<div
className={cn(
"flex gap-x-2 gap-y-1",
diff --git a/web/src/components/table/use-cases/sessions.tsx b/web/src/components/table/use-cases/sessions.tsx
index 8e92eaa990..c2e5d007eb 100644
--- a/web/src/components/table/use-cases/sessions.tsx
+++ b/web/src/components/table/use-cases/sessions.tsx
@@ -755,7 +755,8 @@ export default function SessionsTable({
return <TableTextLoadingCell />;
}
return (
- value && (
+ value &&
+ value.length > 0 && (
<div
className={cn(
"flex gap-x-2 gap-y-1",
diff --git a/web/src/components/table/use-cases/traces.tsx b/web/src/components/table/use-cases/traces.tsx
index 565c6ecf2a..0c77093c3b 100644
--- a/web/src/components/table/use-cases/traces.tsx
+++ b/web/src/components/table/use-cases/traces.tsx
@@ -858,7 +858,8 @@ export default function TracesTable({
cell: ({ row }) => {
const traceTags: string[] | undefined = row.getValue("tags");
return (
- traceTags && (
+ traceTags &&
+ traceTags.length > 0 && (
<div
className={cn(
"flex gap-x-2 gap-y-1",
diff --git a/web/src/features/filters/filter-integration.clienttest.ts b/web/src/features/filters/filter-integration.clienttest.ts
index f28c655eef..90b2a2151d 100644
--- a/web/src/features/filters/filter-integration.clienttest.ts
+++ b/web/src/features/filters/filter-integration.clienttest.ts
@@ -13,6 +13,7 @@ import {
import {
encodeFiltersGeneric,
decodeFiltersGeneric,
+ computeSelectedValues,
} from "./lib/filter-query-encoding";
import { validateFilters } from "@/src/components/table/table-view-presets/validation";
import { traceFilterConfig } from "./config/traces-config";
@@ -618,6 +619,19 @@ describe("Filter Flow: URL → Decode → Normalize → Transform", () => {
expect(result[0]?.column).toBe("traceTags");
});
+ it("should preserve empty arrayOptions none-of filters through complete URL flow", () => {
+ const filters: FilterState = [
+ {
+ column: "tags",
+ type: "arrayOptions",
+ operator: "none of",
+ value: [],
+ },
+ ];
+
+ expect(simulateUrlFlow(filters)).toEqual(filters);
+ });
+
it("should discard stale positionInTrace URL filters on the general events table", () => {
const urlFilter = "positionInTrace;positionInTrace;last;=;";
@@ -722,7 +736,7 @@ describe("resolveCheckboxOperator (arrayOptions vs stringOptions)", () => {
});
});
- it('should switch from "none of" to "any of" for arrayOptions', () => {
+ it('should preserve "none of" for arrayOptions', () => {
const result = resolveCheckboxOperator({
colType: "arrayOptions",
existingFilter: {
@@ -735,9 +749,8 @@ describe("resolveCheckboxOperator (arrayOptions vs stringOptions)", () => {
availableValues,
});
- // Must NOT keep "none of" — it gives wrong results for multi-valued arrays
expect(result).toEqual({
- finalOperator: "any of",
+ finalOperator: "none of",
finalValues: ["tag-1", "tag-2"],
});
});
@@ -837,6 +850,28 @@ describe("resolveCheckboxOperator (arrayOptions vs stringOptions)", () => {
});
});
+describe("computeSelectedValues", () => {
+ it('should keep excluded values checked for arrayOptions "none of" filters', () => {
+ const result = computeSelectedValues(["tag-1", "tag-2", "tag-3"], {
+ type: "arrayOptions",
+ operator: "none of",
+ value: ["tag-2"],
+ });
+
+ expect(result).toEqual(["tag-2"]);
+ });
+
+ it('should continue to invert "none of" for stringOptions filters', () => {
+ const result = computeSelectedValues(["prod", "staging", "dev"], {
+ type: "stringOptions",
+ operator: "none of",
+ value: ["dev"],
+ });
+
+ expect(result).toEqual(["prod", "staging"]);
+ });
+});
+
describe("Implicit Environment Defaults (sidebar only)", () => {
const hiddenEnvironments = [...DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS];
const availableValues = [
diff --git a/web/src/features/filters/hooks/useSidebarFilterState.tsx b/web/src/features/filters/hooks/useSidebarFilterState.tsx
index 7109cbe649..d07ff59b93 100644
--- a/web/src/features/filters/hooks/useSidebarFilterState.tsx
+++ b/web/src/features/filters/hooks/useSidebarFilterState.tsx
@@ -148,14 +148,15 @@ export interface CategoricalUIFilter extends BaseUIFilter {
* Current operator for arrayOptions columns (tags, labels, etc.)
* - "any of": OR logic - match if item has ANY selected value
* - "all of": AND logic - match if item has ALL selected values
+ * - "none of": exclude items with ANY selected value
* undefined for non-arrayOptions columns
*/
- operator?: "any of" | "all of";
+ operator?: "any of" | "all of" | "none of";
/**
* Callback to change the operator. Only provided for arrayOptions columns.
* When called, updates the filter to use the specified operator.
*/
- onOperatorChange?: (operator: "any of" | "all of") => void;
+ onOperatorChange?: (operator: "any of" | "all of" | "none of") => void;
/**
* Active text filters (contains/does not contain) for this column
* Mutually exclusive with checkbox selections
@@ -321,8 +322,10 @@ const DEFAULT_HOOK_OPTIONS: UseSidebarFilterStateOptions = {
* For arrayOptions (e.g., tags), "none of" inversion is NOT semantically
* equivalent because a single trace can have multiple tags. For example,
* a trace with tags [tag-1, tag-3] matches "any of [tag-1, tag-2]" but does NOT match
- * "none of [tag-3, tag-4, tag-5]" (because it contains tag-3). So we always use positive
- * matching ("any of" / "all of") for array columns.
+ * "none of [tag-3, tag-4, tag-5]" (because it contains tag-3). Because of that, we never
+ * derive array filters by inverting the deselected set. Instead, we keep the user's explicit
+ * array operator when one already exists ("all of" / "none of"), and otherwise default new
+ * checkbox selections to positive matching ("any of").
*
* For stringOptions (e.g., environment), each row has a single value,
* so "none of [deselected]" is semantically equivalent to "any of [selected]".
@@ -339,13 +342,18 @@ export function resolveCheckboxOperator(params: {
const { colType, existingFilter, values, availableValues } = params;
if (colType === "arrayOptions") {
- // For array columns, always use positive matching.
if (
existingFilter?.operator === "all of" &&
existingFilter.type === "arrayOptions"
) {
return { finalOperator: "all of", finalValues: values };
}
+ if (
+ existingFilter?.operator === "none of" &&
+ existingFilter.type === "arrayOptions"
+ ) {
+ return { finalOperator: "none of", finalValues: values };
+ }
return { finalOperator: "any of", finalValues: values };
}
@@ -716,6 +724,11 @@ export function useSidebarFilterState(
// Determine operator and values based on context
let finalOperator: "any of" | "none of" | "all of";
let finalValues: string[];
+ const existingFilter = current.find((f) => f.column === column);
+ const preserveArrayNoneOfOperator =
+ colType === "arrayOptions" &&
+ existingFilter?.type === "arrayOptions" &&
+ existingFilter.operator === "none of";
if (operator !== undefined) {
// Explicit operator provided (e.g., from "Only" button or operator toggle) - use as-is
@@ -725,9 +738,10 @@ export function useSidebarFilterState(
// If all items selected or none selected, remove filter
// (only for implicit/checkbox-based selection, not when operator is explicitly set)
if (
- values.length === 0 ||
- (values.length === availableValues.length &&
- availableValues.every((v) => values.includes(v)))
+ !preserveArrayNoneOfOperator &&
+ (values.length === 0 ||
+ (values.length === availableValues.length &&
+ availableValues.every((v) => values.includes(v))))
) {
const isManagedEnvironmentColumn =
column === managedEnvironmentColumn &&
@@ -748,7 +762,6 @@ export function useSidebarFilterState(
return other;
}
// Checkbox interaction - smart operator selection
- const existingFilter = current.find((f) => f.column === column);
({ finalOperator, finalValues } = resolveCheckboxOperator({
colType,
existingFilter,
@@ -825,19 +838,35 @@ export function useSidebarFilterState(
// Only apply for array-type options (not nested objects)
const optionValue = options[column];
if (!Array.isArray(optionValue)) return;
- updateFilter(column, [value], "any of");
+ const columnType = config.columnDefinitions.find(
+ (columnDefinition) => columnDefinition.id === column,
+ )?.type;
+ const existingFilter = filterState.find((f) => f.column === column);
+ const operator =
+ columnType === "arrayOptions" &&
+ existingFilter?.type === "arrayOptions" &&
+ (existingFilter.operator === "any of" ||
+ existingFilter.operator === "all of" ||
+ existingFilter.operator === "none of")
+ ? existingFilter.operator
+ : "any of";
+ updateFilter(column, [value], operator);
},
- [config.facets, options, updateFilter],
+ [
+ config.columnDefinitions,
+ config.facets,
+ filterState,
+ options,
+ updateFilter,
+ ],
);
const updateOperator = useCallback(
- (column: string, newOperator: "any of" | "all of") => {
+ (column: string, newOperator: "any of" | "all of" | "none of") => {
// Find the existing filter for this column
const existingFilter = filterState.find((f) => f.column === column);
if (!existingFilter) {
- // Create a filter with the operator and empty values
- // important so users set the operator preference before selecting values,
- // in case for ALL on TAGS filter
+ // Without selected values there is no valid persisted filter yet.
updateFilter(column, [], newOperator);
return;
}
@@ -861,9 +890,12 @@ export function useSidebarFilterState(
let currentValues: string[];
if (existingFilter.operator === "none of") {
- // Convert "none of [excluded]" to selected values
- const excluded = new Set(existingFilter.value);
- currentValues = availableValues.filter((v) => !excluded.has(v));
+ currentValues =
+ existingFilter.type === "arrayOptions"
+ ? existingFilter.value
+ : availableValues.filter(
+ (v) => !new Set(existingFilter.value).has(v),
+ );
} else {
currentValues = existingFilter.value;
}
@@ -1473,13 +1505,14 @@ export function useSidebarFilterState(
// - "any of" (OR logic): match if item has ANY selected value
// - "all of" (AND logic): match if item has ALL selected values
// This operator is persisted in the filter state and URL
- let currentOperator: "any of" | "all of" | undefined;
+ let currentOperator: "any of" | "all of" | "none of" | undefined;
if (
checkboxFilter &&
(checkboxFilter.type === "arrayOptions" ||
checkboxFilter.type === "stringOptions") &&
(checkboxFilter.operator === "any of" ||
- checkboxFilter.operator === "all of")
+ checkboxFilter.operator === "all of" ||
+ checkboxFilter.operator === "none of")
) {
currentOperator = checkboxFilter.operator;
} else if (isArrayOptions && selectedValues.length > 0) {
@@ -1532,6 +1565,7 @@ export function useSidebarFilterState(
? hasManagedEnvironmentSelectionOverride
: (currentOperator === "all of" &&
selectedValues.length === availableValues.length) ||
+ (currentOperator === "none of" && selectedValues.length > 0) ||
hasCheckboxSelections);
const disableState = getFacetDisabledState(facet);
@@ -1581,7 +1615,8 @@ export function useSidebarFilterState(
// Only add operator toggle for arrayOptions columns
operator: isArrayOptions ? currentOperator : undefined,
onOperatorChange: isArrayOptions
- ? (op: "any of" | "all of") => updateOperator(facet.column, op)
+ ? (op: "any of" | "all of" | "none of") =>
+ updateOperator(facet.column, op)
: undefined,
// Text filter support - ONLY for stringOptions, NOT arrayOptions or boolean
textFilters: !isArrayOptions ? textFilters : undefined,
diff --git a/web/src/features/filters/lib/filter-query-encoding-decoding.clienttest.ts b/web/src/features/filters/lib/filter-query-encoding-decoding.clienttest.ts
index 60cbe17359..de263d492e 100644
--- a/web/src/features/filters/lib/filter-query-encoding-decoding.clienttest.ts
+++ b/web/src/features/filters/lib/filter-query-encoding-decoding.clienttest.ts
@@ -421,6 +421,19 @@ describe("Filter Query Encoding & Decoding (Legacy Format)", () => {
},
]);
});
+
+ it("should decode arrayOptions none-of filter with empty values", () => {
+ const result = decodeFilters("tags;arrayOptions;;none of;");
+
+ expect(result).toEqual([
+ {
+ column: "tags",
+ type: "arrayOptions",
+ operator: "none of",
+ value: [],
+ },
+ ]);
+ });
});
describe("Round-trip consistency", () => {
@@ -497,6 +510,22 @@ describe("Filter Query Encoding & Decoding (Legacy Format)", () => {
expect(deserialized).toEqual(filterWithEmptyString);
});
+ it("should maintain consistency for empty arrayOptions none-of filters", () => {
+ const filterWithPendingNoneSelection: FilterState = [
+ {
+ column: "tags",
+ type: "arrayOptions",
+ operator: "none of",
+ value: [],
+ },
+ ];
+
+ const serialized = encodeFilters(filterWithPendingNoneSelection);
+ const deserialized = decodeFilters(serialized);
+
+ expect(deserialized).toEqual(filterWithPendingNoneSelection);
+ });
+
it("should maintain consistency for values containing pipes", () => {
// Issue #11757: values with literal | should round-trip correctly
const cases: FilterState[] = [
diff --git a/web/src/features/filters/lib/filter-query-encoding.ts b/web/src/features/filters/lib/filter-query-encoding.ts
index ff1ef64340..35deafc7bd 100644
--- a/web/src/features/filters/lib/filter-query-encoding.ts
+++ b/web/src/features/filters/lib/filter-query-encoding.ts
@@ -51,10 +51,15 @@ export type GenericFilterOptions = Record<
// Pure helper: compute UI-selected values from a filter entry and available values
export function computeSelectedValues(
availableValues: string[],
- filterEntry: { operator?: string; value?: unknown } | undefined,
+ filterEntry:
+ | { operator?: string; value?: unknown; type?: string }
+ | undefined,
): string[] {
if (!filterEntry) return availableValues;
const values = (filterEntry.value as string[]) ?? [];
+ if (filterEntry.type === "arrayOptions") {
+ return values;
+ }
if (filterEntry.operator === "none of") {
const excluded = new Set(values);
return availableValues.filter((v) => !excluded.has(v));