windmill-labs/windmill · error

Invalid ${field}:\n${errors.join('\n')}

Error message

Invalid ${field}:\n${errors.join('\n')}

What it means

validateSpecialFlowModule runs flowModuleSchema.safeParse on a special flow module and throws an Error listing up to 5 Zod issues (path: message) when the module shape is invalid. Used to validate designated flow modules (e.g. approval/loop sub-fields) supplied via parsedModule or flowTools.

Source

Thrown at frontend/src/lib/components/copilot/chat/flow/core.ts:268

		throw new Error(`Invalid JSON for ${field}: ${errorMessage}`)
	}
}

function validateSpecialFlowModule(
	module: unknown,
	field: SpecialFlowModuleField
): FlowModule | null | undefined {
	if (module === undefined || module === null) {
		return module
	}

	const result = flowModuleSchema.safeParse(module)
	if (!result.success) {
		const errors = result.error.issues.slice(0, 5).map((issue) => {
			const path = issue.path.length > 0 ? issue.path.join('.') : field
			return `${path}: ${issue.message}`
		})
		throw new Error(`Invalid ${field}:\n${errors.join('\n')}`)
	}

	const parsedModule = result.data
	const expectedId = specialFlowModuleFields[field]
	if (parsedModule.id !== expectedId) {
		throw new Error(`Invalid ${field}: id must be "${expectedId}"`)
	}

	if (parsedModule.value.type !== 'rawscript' && parsedModule.value.type !== 'script') {
		throw new Error(`Invalid ${field}: only "rawscript" and "script" modules are supported`)
	}

	return parsedModule
}

const patchFlowJsonSchema = z.object({
	old_string: z.string().min(1).describe('Exact text to find in the current compact flow JSON'),
	new_string: z.string().describe('Replacement JSON text'),

View on GitHub (pinned to e474e8803c)

Solutions

  1. Fix each listed path in the error (up to 5 issues shown) to satisfy flowModuleSchema.
  2. Compare against a known-good module of the same special type and copy its shape.
  3. Validate the whole flow JSON with the flow schema first, then extract the special module.

Example fix

// before
{ "id": "approval", "summary": "ok" }
// after
{ "id": "approval", "value": { "type": "rawscript", "content": "...", "language": "python" } }
Defensive patterns

Strategy: validation

Validate before calling

const check = flowModuleSchema.safeParse(module)
if (!check.success) {
  console.error(check.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`))
  return
}

Type guard

function isFlowModule(m: unknown): m is FlowModule {
  return flowModuleSchema.safeParse(m).success
}

Try / catch

try {
  await tool.updateSpecialModule(field, module)
} catch (e) {
  if (String(e.message).startsWith(`Invalid ${field}`)) {
    return requestModelRetry(e.message)
  }
  throw e
}

Prevention

When it happens

Trigger: The module passed for `field` fails flowModuleSchema: missing required keys (id/value), wrong value.type, invalid input/output schema, or extra unknown fields, producing result.success === false.

Common situations: Model-generated flow JSON omits `value` or uses a wrong module type; hand-written JSON has a typo'd property; schema drift after a Windmill version change added required fields.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/829dcca3f6bee4e0. Report an issue: GitHub.