FlowiseAI/Flowise · warning · Error
Maximum recursion depth reached in parseWithTypeConversion
Error message
Maximum recursion depth reached in parseWithTypeConversion
What it means
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.
Source
Thrown at packages/components/src/utils.ts:1970
)
}
}
}
}
}
/**
* Parse a value against a Zod schema with automatic type conversion for common type mismatches
* @param schema - The Zod schema to parse against
* @param arg - The value to parse
* @param maxDepth - Maximum recursion depth to prevent infinite loops (default: 10)
* @returns The parsed value
* @throws Error if parsing fails after attempting type conversions
*/
export async function parseWithTypeConversion<T extends z.ZodTypeAny>(schema: T, arg: unknown, maxDepth: number = 10): Promise<z.infer<T>> {
// Safety check: prevent infinite recursion
if (maxDepth <= 0) {
throw new Error('Maximum recursion depth reached in parseWithTypeConversion')
}
try {
return await schema.parseAsync(arg)
} catch (e) {
// Check if it's a ZodError and try to fix type mismatches
if (z.ZodError && e instanceof z.ZodError) {
const zodError = e as z.ZodError
// Deep clone the arg to avoid mutating the original
const modifiedArg = typeof arg === 'object' && arg !== null ? cloneDeep(arg) : arg
let hasModification = false
// Helper function to set a value at a nested path
const setValueAtPath = (obj: any, path: (string | number)[], value: any): void => {
let current = obj
for (let i = 0; i < path.length - 1; i++) {
const key = path[i]
if (current && typeof current === 'object' && key in current) {View on GitHub (pinned to abe4a8601a)
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.
Example fix
// before
export async function parseWithTypeConversion<T extends z.ZodTypeAny>(schema: T, arg: unknown, maxDepth = 10) {
if (maxDepth <= 0) throw new Error('Maximum recursion depth reached in parseWithTypeConversion')
...
}
// after — include the failing path and last ZodError for diagnosis
if (maxDepth <= 0) {
throw new Error(
`Maximum recursion depth reached in parseWithTypeConversion. The input likely does not conform to the schema after coercion. ` +
`Last issue path: ${lastZodError?.issues?.[0]?.path?.join('.') ?? 'unknown'}`
)
} Defensive patterns
Strategy: validation
Validate before calling
function isSafeDepth(maxDepth: number): boolean {
return Number.isInteger(maxDepth) && maxDepth > 0 && maxDepth <= 50
} Type guard
function isZodSchema(v: unknown): v is import('zod').ZodTypeAny {
return v != null && typeof (v as any).parseAsync === 'function' && typeof (v as any)._def === 'object'
} Try / catch
if (maxDepth <= 0) {
throw new Error(`parseWithTypeConversion exhausted conversion attempts; input does not conform after coercion (last path: ${lastPath ?? 'unknown'})`)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Error parsing Zod Schema: ${exception}
- Received tool input did not match expected schema: ${JSON.st
- Received tool input did not match expected schema: ${JSON.st
- Received tool input did not match expected schema
- Received tool input did not match expected schema ${e}
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/404ae9baafed90af.
Report an issue: GitHub.