{"record":{"id":"d0ca7e66665fd696","repo":"FlowiseAI/Flowise","slug":"failed-to-parse-zod-schema-error-message","errorCode":null,"errorMessage":"Failed to parse Zod schema: ${error.message}","messagePattern":"Failed to parse Zod schema: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/src/secureZodParser.ts","lineNumber":40,"sourceCode":"\n    /**\n     * Safely parse a Zod schema string into a Zod schema object\n     * @param schemaString The Zod schema as a string (e.g., \"z.object({name: z.string()})\")\n     * @returns A Zod schema object\n     * @throws Error if the schema is invalid or contains unsafe patterns\n     */\n    static parseZodSchema(schemaString: string): z.ZodTypeAny {\n        try {\n            // Remove comments and normalize whitespace\n            const cleanedSchema = this.cleanSchemaString(schemaString)\n\n            // Parse the schema structure\n            const parsed = this.parseSchemaStructure(cleanedSchema)\n\n            // Build the Zod schema securely\n            return this.buildZodSchema(parsed)\n        } catch (error) {\n            throw new Error(`Failed to parse Zod schema: ${error.message}`)\n        }\n    }\n\n    private static cleanSchemaString(schema: string): string {\n        // Remove single-line comments\n        schema = schema.replace(/\\/\\/.*$/gm, '')\n\n        // Remove multi-line comments\n        schema = schema.replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n\n        // Normalize whitespace\n        schema = schema.replace(/\\s+/g, ' ').trim()\n\n        return schema\n    }\n\n    private static parseSchemaStructure(schema: string): any {\n        // This is a simplified parser that handles common Zod patterns safely","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/src/secureZodParser.ts#L22-L58","documentation":"parseZodSchema is the single public entry of SecureZodSchemaParser. Its try-block runs cleanSchemaString -> parseSchemaStructure -> buildZodSchema; any error is caught and rethrown as 'Failed to parse Zod schema: <error.message>'. This nests the inner message (which is itself one of errors 608-619) and discards the original stack, hiding the precise throw site. To find the real cause, read the suffix after the colon.","triggerScenarios":"Any malformed or unsupported schema string passed to SecureZodSchemaParser.parseZodSchema — the specific reason is the suffix (e.g. '... Schema must start with z.object()', '... Unsupported type: bigint').","commonSituations":"User-defined tool/input schema stored as a string and parsed at runtime; schema written against full Zod but the secure parser only supports a subset; copy-pasting a Zod schema from docs that uses unsupported types/modifiers.","solutions":["Read the suffix after 'Failed to parse Zod schema: ' to identify the underlying error (608-619) and fix that.","Simplify the schema to the supported subset: top-level z.object, base types in ALLOWED_TYPES, modifiers in ALLOWED_TYPES.","As a maintainer: preserve the original error via 'throw new Error(msg, { cause: error })' so the stack survives."],"exampleFix":"// before: caller loses the underlying cause\ntry { SecureZodSchemaParser.parseZodSchema(str) } catch (e) { console.log(e.message) }\n// -> 'Failed to parse Zod schema: Unsupported type: bigint'  (read the suffix)\n\n// fix the schema: replace unsupported type\n// before: 'z.object({ id: z.bigint() })'\n// after:  'z.object({ id: z.string() })'","handlingStrategy":"try-catch","validationCode":"// Validate shape before parsing using the same rules the parser enforces.\nfunction looksParsable(s: string): boolean {\n  const c = s.replace(/\\/\\/.*$/gm, '').replace(/\\/\\*[\\s\\S]*?\\*\\//g, '').replace(/\\s+/g, ' ').trim()\n  return c.startsWith('z.object(') && /z\\.object\\(\\s*\\{[\\s\\S]*\\}\\s*\\)/.test(c)\n}","typeGuard":"const isZodSchemaString = (s: unknown): s is string =>\n  typeof s === 'string' && s.replace(/\\s+/g, ' ').trim().startsWith('z.object(')","tryCatchPattern":"try {\n  return SecureZodSchemaParser.parseZodSchema(schemaString)\n} catch (e) {\n  // the suffix after 'Failed to parse Zod schema: ' is the real cause\n  const cause = (e as Error).message.replace(/^Failed to parse Zod schema: /, '')\n  throw new Error(`Schema rejected (${cause})`, { cause: e })\n}","preventionTips":["Read the suffix of the wrapped message to find the underlying parse error (608-619).","Restrict authoring to the supported subset: top-level z.object, ALLOWED_TYPES bases and modifiers.","Preserve the original error via { cause } when rethrowing so the stack is not lost."],"tags":["zod","parsing","schema","error-wrapping"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}