windmill-labs/windmill · error

Code parameter is required and must be a string

Error message

Code parameter is required and must be a string

What it means

The overwrite-code tool requires a code argument that is a non-empty string of the new script contents. Missing code or a non-string type (number, object, array) triggers this error before any write happens.

Source

Thrown at frontend/src/lib/components/copilot/chat/script/core.ts:861

	fn: async function ({ args, helpers, toolCallbacks, toolId }) {
		const scriptOptions = helpers.getScriptOptions()

		if (!scriptOptions) {
			toolCallbacks.setToolStatus(toolId, {
				content: 'No script available to edit',
				error: 'No script found in current context'
			})
			throw new Error(
				'No script code available to edit. Please ensure you have a script open in the editor.'
			)
		}

		if (!args.code || typeof args.code !== 'string') {
			toolCallbacks.setToolStatus(toolId, {
				content: 'Invalid code provided',
				error: 'Code parameter is required and must be a string'
			})
			throw new Error('Code parameter is required and must be a string')
		}

		try {
			// Save old code
			const oldCode = scriptOptions.code

			// Apply the code changes directly
			await helpers.applyCode(args.code, { applyAll: true, mode: 'apply' })

			// Show revert mode
			await helpers.applyCode(oldCode, { mode: 'revert' })

			toolCallbacks.setToolStatus(toolId, {
				content: 'Code changes applied',
				result: 'Success'
			})
			return 'Code has been applied to the script editor.'
		} catch (error) {

View on GitHub (pinned to e474e8803c)

Solutions

  1. Re-invoke with code as a plain non-empty string containing the full new script
  2. If the model nested the code, extract it to the top-level code field before calling
  3. Re-prompt the model to return the complete script as raw text in the code parameter

Example fix

// before
{ code: { script: 'export function main() {}' } } // object, not string
// after
{ code: 'export function main() {}' }
Defensive patterns

Strategy: validation

Validate before calling

if (typeof args.code !== 'string' || args.code.length === 0) {
  // obtain the full script as a plain string before calling
}

Type guard

function isNonEmptyString(v) {
  return typeof v === 'string' && v.length > 0
}

Prevention

When it happens

Trigger: Model omits code, sends it as a JSON-encoded object/stringified payload mismatch, or passes empty string (falsy) which also fails the check.

Common situations: Prompt like 'clear the script' yielding empty string; model returning structured output where code is nested; serialization layer turning code into an object.

Related errors


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