diff --git a/ui/litellm-dashboard/src/components/templates/keyEditFieldNormalizers.test.ts b/ui/litellm-dashboard/src/components/templates/keyEditFieldNormalizers.test.ts index 9ae0cbee589..9223cc6dbc8 100644 --- a/ui/litellm-dashboard/src/components/templates/keyEditFieldNormalizers.test.ts +++ b/ui/litellm-dashboard/src/components/templates/keyEditFieldNormalizers.test.ts @@ -19,6 +19,14 @@ describe("moveTagsOutOfMetadataJson", () => { }); }); + it("trims whitespace and drops blank entries the same way the Tags control does", () => { + expect(moveTagsOutOfMetadataJson('{"tags": [" a ", "a", " ", "", " ui-tag"]}', ["ui-tag"])).toEqual({ + metadata: "{}", + tags: ["ui-tag", "a"], + movedTags: ["a"], + }); + }); + it("strips an empty tags array while moving nothing", () => { expect(moveTagsOutOfMetadataJson('{"tags": []}', undefined)).toEqual({ metadata: "{}", diff --git a/ui/litellm-dashboard/src/components/templates/keyEditFieldNormalizers.ts b/ui/litellm-dashboard/src/components/templates/keyEditFieldNormalizers.ts index 208b7c033ac..1cfd1ae35f7 100644 --- a/ui/litellm-dashboard/src/components/templates/keyEditFieldNormalizers.ts +++ b/ui/litellm-dashboard/src/components/templates/keyEditFieldNormalizers.ts @@ -60,10 +60,10 @@ export const moveTagsOutOfMetadataJson = ( const { tags: metadataTags, ...rest } = parsed; if (!Array.isArray(metadataTags)) return null; const existing = currentTags ?? []; - const movedTags = metadataTags.filter( - (tag: unknown, index: number): tag is string => - typeof tag === "string" && !existing.includes(tag) && metadataTags.indexOf(tag) === index, - ); + const movedTags = metadataTags + .filter((tag: unknown): tag is string => typeof tag === "string") + .map((tag) => tag.trim()) + .filter((tag, index, all) => tag.length > 0 && !existing.includes(tag) && all.indexOf(tag) === index); return { metadata: JSON.stringify(rest, null, 2), tags: [...existing, ...movedTags], movedTags }; };