From 97f15796e89d375bb50e936ed84b5ea7dfe8da40 Mon Sep 17 00:00:00 2001 From: centdix <40307056+centdix@users.noreply.github.com> Date: Wed, 17 Dec 2025 13:46:27 +0100 Subject: [PATCH] remove null format (#7402) --- .../src/lib/components/copilot/chat/shared.ts | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/frontend/src/lib/components/copilot/chat/shared.ts b/frontend/src/lib/components/copilot/chat/shared.ts index ac92350a68..89db2ae389 100644 --- a/frontend/src/lib/components/copilot/chat/shared.ts +++ b/frontend/src/lib/components/copilot/chat/shared.ts @@ -571,6 +571,46 @@ export const createSearchHubScriptsTool = (withContent: boolean = false) => ({ } }) +/** + * Recursively removes format: null or format: '' from a JSON schema object + */ +function removeNullFormats(schema: Record | undefined): void { + if (!schema || typeof schema !== 'object') { + return + } + + // Remove format if it's null or empty string + if (schema.format === null || schema.format === '') { + delete schema.format + } + + // Recurse into properties + if (schema.properties && typeof schema.properties === 'object') { + for (const key of Object.keys(schema.properties)) { + removeNullFormats(schema.properties[key]) + } + } + + // Recurse into items (for arrays) + if (schema.items) { + removeNullFormats(schema.items) + } + + // Recurse into additionalProperties if it's an object schema + if (schema.additionalProperties && typeof schema.additionalProperties === 'object') { + removeNullFormats(schema.additionalProperties) + } + + // Recurse into allOf, anyOf, oneOf + for (const key of ['allOf', 'anyOf', 'oneOf']) { + if (Array.isArray(schema[key])) { + for (const subSchema of schema[key]) { + removeNullFormats(subSchema) + } + } + } +} + export async function buildSchemaForTool( toolDef: ChatCompletionFunctionTool, schemaBuilder: () => Promise @@ -588,6 +628,10 @@ export async function buildSchemaForTool( } toolDef.function.parameters = { ...schema, additionalProperties: false } + + // recursively remove any format: null or format: '' (empty string) from schema + removeNullFormats(toolDef.function.parameters) + // OPEN AI models don't support strict mode well with schema with complex properties, so we disable it const model = getCurrentModel() if (model.provider === 'openai' || model.provider === 'azure_openai') {