{"record":{"id":"96af2835c2f5baab","repo":"windmill-labs/windmill","slug":"code-parameter-is-required-and-must-be-a-string","errorCode":null,"errorMessage":"Code parameter is required and must be a string","messagePattern":"Code parameter is required and must be a string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/src/lib/components/copilot/chat/script/core.ts","lineNumber":861,"sourceCode":"\tfn: async function ({ args, helpers, toolCallbacks, toolId }) {\n\t\tconst scriptOptions = helpers.getScriptOptions()\n\n\t\tif (!scriptOptions) {\n\t\t\ttoolCallbacks.setToolStatus(toolId, {\n\t\t\t\tcontent: 'No script available to edit',\n\t\t\t\terror: 'No script found in current context'\n\t\t\t})\n\t\t\tthrow new Error(\n\t\t\t\t'No script code available to edit. Please ensure you have a script open in the editor.'\n\t\t\t)\n\t\t}\n\n\t\tif (!args.code || typeof args.code !== 'string') {\n\t\t\ttoolCallbacks.setToolStatus(toolId, {\n\t\t\t\tcontent: 'Invalid code provided',\n\t\t\t\terror: 'Code parameter is required and must be a string'\n\t\t\t})\n\t\t\tthrow new Error('Code parameter is required and must be a string')\n\t\t}\n\n\t\ttry {\n\t\t\t// Save old code\n\t\t\tconst oldCode = scriptOptions.code\n\n\t\t\t// Apply the code changes directly\n\t\t\tawait helpers.applyCode(args.code, { applyAll: true, mode: 'apply' })\n\n\t\t\t// Show revert mode\n\t\t\tawait helpers.applyCode(oldCode, { mode: 'revert' })\n\n\t\t\ttoolCallbacks.setToolStatus(toolId, {\n\t\t\t\tcontent: 'Code changes applied',\n\t\t\t\tresult: 'Success'\n\t\t\t})\n\t\t\treturn 'Code has been applied to the script editor.'\n\t\t} catch (error) {","sourceCodeStart":843,"sourceCodeEnd":879,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/components/copilot/chat/script/core.ts#L843-L879","documentation":"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.","triggerScenarios":"Model omits code, sends it as a JSON-encoded object/stringified payload mismatch, or passes empty string (falsy) which also fails the check.","commonSituations":"Prompt like 'clear the script' yielding empty string; model returning structured output where code is nested; serialization layer turning code into an object.","solutions":["Re-invoke with code as a plain non-empty string containing the full new script","If the model nested the code, extract it to the top-level code field before calling","Re-prompt the model to return the complete script as raw text in the code parameter"],"exampleFix":"// before\n{ code: { script: 'export function main() {}' } } // object, not string\n// after\n{ code: 'export function main() {}' }","handlingStrategy":"validation","validationCode":"if (typeof args.code !== 'string' || args.code.length === 0) {\n  // obtain the full script as a plain string before calling\n}","typeGuard":"function isNonEmptyString(v) {\n  return typeof v === 'string' && v.length > 0\n}","tryCatchPattern":null,"preventionTips":["Require the model to return the complete script as a raw string in code","Reject empty-string rewrites explicitly (ask for the full replacement)","Unwrap nested/structured outputs to a top-level string before dispatch"],"tags":["validation","ai-copilot","arguments","type-error"],"backgroundTag":"invalid-tool-arguments","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"}