{"record":{"id":"404ae9baafed90af","repo":"FlowiseAI/Flowise","slug":"maximum-recursion-depth-reached-in-parsewithtypeco","errorCode":null,"errorMessage":"Maximum recursion depth reached in parseWithTypeConversion","messagePattern":"Maximum recursion depth reached in parseWithTypeConversion","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/components/src/utils.ts","lineNumber":1970,"sourceCode":"                    )\n                }\n            }\n        }\n    }\n}\n\n/**\n * Parse a value against a Zod schema with automatic type conversion for common type mismatches\n * @param schema - The Zod schema to parse against\n * @param arg - The value to parse\n * @param maxDepth - Maximum recursion depth to prevent infinite loops (default: 10)\n * @returns The parsed value\n * @throws Error if parsing fails after attempting type conversions\n */\nexport async function parseWithTypeConversion<T extends z.ZodTypeAny>(schema: T, arg: unknown, maxDepth: number = 10): Promise<z.infer<T>> {\n    // Safety check: prevent infinite recursion\n    if (maxDepth <= 0) {\n        throw new Error('Maximum recursion depth reached in parseWithTypeConversion')\n    }\n\n    try {\n        return await schema.parseAsync(arg)\n    } catch (e) {\n        // Check if it's a ZodError and try to fix type mismatches\n        if (z.ZodError && e instanceof z.ZodError) {\n            const zodError = e as z.ZodError\n            // Deep clone the arg to avoid mutating the original\n            const modifiedArg = typeof arg === 'object' && arg !== null ? cloneDeep(arg) : arg\n            let hasModification = false\n\n            // Helper function to set a value at a nested path\n            const setValueAtPath = (obj: any, path: (string | number)[], value: any): void => {\n                let current = obj\n                for (let i = 0; i < path.length - 1; i++) {\n                    const key = path[i]\n                    if (current && typeof current === 'object' && key in current) {","sourceCodeStart":1952,"sourceCodeEnd":1988,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/src/utils.ts#L1952-L1988","documentation":"Safety guard in parseWithTypeConversion: when the recursive type-conversion attempts exhaust maxDepth (default 10) without producing a schema-valid value, it stops recursing and throws. This prevents stack overflow from self-referential Zod schemas or conversion loops that never converge.","triggerScenarios":"A deeply nested or recursive Zod schema (z.object referencing itself) where each conversion attempt generates another ZodError; input so mis-typed that no conversion path resolves within 10 attempts; a bug in the conversion logic that re-introduces the same error each recursion.","commonSituations":"Using z.lazy() recursive schemas with heavily mismatched input; API payloads with nested arrays-of-arrays that the converter keeps restructuring; a Zod schema with transforms that conflict with the converter's type coercion.","solutions":["Inspect the Zod schema for recursion (z.lazy, deeply nested objects) and simplify or pre-validate the input.","Fix the upstream payload so it already matches the schema's expected types, eliminating the need for deep conversion.","Increase maxDepth only if the schema legitimately needs more conversion passes (rare).","Add a pre-parse normalization step that flattens the input before parseWithTypeConversion."],"exampleFix":"// before\nexport async function parseWithTypeConversion<T extends z.ZodTypeAny>(schema: T, arg: unknown, maxDepth = 10) {\n  if (maxDepth <= 0) throw new Error('Maximum recursion depth reached in parseWithTypeConversion')\n  ...\n}\n\n// after — include the failing path and last ZodError for diagnosis\nif (maxDepth <= 0) {\n  throw new Error(\n    `Maximum recursion depth reached in parseWithTypeConversion. The input likely does not conform to the schema after coercion. ` +\n    `Last issue path: ${lastZodError?.issues?.[0]?.path?.join('.') ?? 'unknown'}`\n  )\n}","handlingStrategy":"validation","validationCode":"function isSafeDepth(maxDepth: number): boolean {\n  return Number.isInteger(maxDepth) && maxDepth > 0 && maxDepth <= 50\n}","typeGuard":"function isZodSchema(v: unknown): v is import('zod').ZodTypeAny {\n  return v != null && typeof (v as any).parseAsync === 'function' && typeof (v as any)._def === 'object'\n}","tryCatchPattern":"if (maxDepth <= 0) {\n  throw new Error(`parseWithTypeConversion exhausted conversion attempts; input does not conform after coercion (last path: ${lastPath ?? 'unknown'})`)\n}","preventionTips":["Pre-normalise input types to match the Zod schema before calling parseWithTypeConversion.","Avoid deeply recursive Zod schemas (z.lazy) where possible.","Log the last ZodError path when recursion is exhausted to diagnose the non-converging field."],"tags":["zod","validation","recursion","schema","safety-guard"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}