{"record":{"id":"6a8cec574e89430b","repo":"windmill-labs/windmill","slug":"invalid-flow-modules-n-errors-join-n","errorCode":null,"errorMessage":"Invalid flow modules:\\n${errors.join('\\n')}","messagePattern":"Invalid flow modules:\\\\n(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/src/lib/components/copilot/chat/flow/editableFlowJson.ts","lineNumber":251,"sourceCode":"\t\t\t\t\tmodulesSchema,\n\t\t\t\t\tpath as (string | number)[],\n\t\t\t\t\tparsedModules\n\t\t\t\t)\n\t\t\t\tif (targetSchema) {\n\t\t\t\t\tconst expectedFormat = getExpectedFormat(targetSchema)\n\t\t\t\t\tif (expectedFormat) {\n\t\t\t\t\t\tmessage += `\\n    Expected format: ${expectedFormat}`\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (moduleId) {\n\t\t\t\treturn `Module \"${moduleId}\" -> ${fieldPath}: ${message}`\n\t\t\t}\n\t\t\treturn `${path.join('.')}: ${message}`\n\t\t})\n\n\t\tthrow new Error(`Invalid flow modules:\\n${errors.join('\\n')}`)\n\t}\n\n\tconst ids = collectAllFlowModuleIdsFromModules(parsedModules)\n\tif (ids.length !== new Set(ids).size) {\n\t\tthrow new Error('Duplicate module IDs found in flow')\n\t}\n\n\tconst reservedIds = ids.filter(\n\t\t(id) => id === SPECIAL_MODULE_IDS.PREPROCESSOR || id === SPECIAL_MODULE_IDS.FAILURE\n\t)\n\tif (reservedIds.length > 0) {\n\t\tthrow new Error(\n\t\t\t'Special modules must be provided via preprocessor_module and failure_module, not inside modules'\n\t\t)\n\t}\n\n\t// Not expressible in the schema: `provider` is required only when the step is standalone, and\n\t// making AiAgent a conditional union breaks the FlowModuleValue discriminated union it belongs to.","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/components/copilot/chat/flow/editableFlowJson.ts#L233-L269","documentation":"After Array.isArray passes, validateFlowModules runs the modules through the Zod flowModulesSchema. On failure it formats up to 5 issues — attributing each to its module ID and field path where possible — and throws this aggregated error. It is the canonical 'your modules payload doesn't match the flow module schema' message.","triggerScenarios":"validateFlowModules receiving an array whose entries violate flowModulesSchema: missing id, unknown/invalid value.type discriminator, missing required fields for the module type (e.g. rawscript without content/language), wrong input_transform shape, or invalid nested fields.","commonSituations":"The AI invents a module type not in the discriminated union; a required field like 'value.content' or 'value.language' is omitted for rawscript; transforms use the wrong key (expression vs value); a field intended for one module kind is put on another.","solutions":["Read the per-module messages in the error (Module \"<id>\" -> <field>: <reason>) and fix exactly those fields.","Ensure every module has a unique 'id' and a 'value' whose 'type' matches the schema union (rawscript, script, flow, branch, etc.).","Supply all required fields for the chosen type — e.g. rawscript needs content, language, and tags/input_transforms in the right shapes.","Model the payload on the current editable flow JSON output, which is guaranteed schema-conformant."],"exampleFix":"// before: rawscript missing content\n{ id: 'm1', value: { type: 'rawscript', language: 'python3' } }\n// after\n{ id: 'm1', value: { type: 'rawscript', language: 'python3', content: 'print(1)' } }","handlingStrategy":"validation","validationCode":"import { flowModulesSchema } from './editableFlowJson'\nconst res = flowModulesSchema.safeParse(modules)\nif (!res.success) console.error(res.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`))","typeGuard":"function modulesMatchSchema(v: unknown): v is FlowModule[] {\n  return flowModulesSchema.safeParse(v).success\n}","tryCatchPattern":"try {\n  await setFlow({ modules })\n} catch (e) {\n  if (e.message.startsWith('Invalid flow modules:')) {\n    // error lists each bad module as Module \"<id>\" -> <field>: <reason>\n    fixListedFields(e.message)\n  } else throw e\n}","preventionTips":["Fix exactly the fields named in the error (module id -> field path)","Match each module's value.type to the schema union and supply its required fields","Copy module shapes from a known-good editable flow JSON","Run the Zod schema client-side before submitting"],"tags":["validation","zod","schema","flow-modules"],"backgroundTag":"schema-validation-failed","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}