{"record":{"id":"0413e28425ce577f","repo":"n8n-io/n8n","slug":"message-exceeds-maximum-length-of-max-ai-builder","errorCode":null,"errorMessage":"Message exceeds maximum length of ${MAX_AI_BUILDER_PROMPT_LENGTH} characters","messagePattern":"Message exceeds maximum length of (.+?) characters","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"warning","filePath":"packages/@n8n/ai-workflow-builder.ee/src/workflow-builder-agent.ts","lineNumber":470,"sourceCode":"\t\t\texternalCallbacks,\n\t\t);\n\n\t\ttry {\n\t\t\tconst stream = await this.createAgentStream(payload, streamConfig, agent, historicalMessages);\n\t\t\tyield* this.processAgentStream(stream, agent, threadConfig);\n\t\t} catch (error: unknown) {\n\t\t\tthis.handleStreamError(error);\n\t\t}\n\t}\n\n\tprivate validateMessageLength(message: string): void {\n\t\tif (message.length > MAX_AI_BUILDER_PROMPT_LENGTH) {\n\t\t\tthis.logger?.warn('Message exceeds maximum length', {\n\t\t\t\tmessageLength: message.length,\n\t\t\t\tmaxLength: MAX_AI_BUILDER_PROMPT_LENGTH,\n\t\t\t});\n\n\t\t\tthrow new ValidationError(\n\t\t\t\t`Message exceeds maximum length of ${MAX_AI_BUILDER_PROMPT_LENGTH} characters`,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate setupAgentAndConfigs(\n\t\tpayload: ChatPayload,\n\t\tuserId?: string,\n\t\tabortSignal?: AbortSignal,\n\t\texternalCallbacks?: Callbacks,\n\t) {\n\t\t// Store feature flags from the first call; reuse for all subsequent calls\n\t\t// to prevent mid-session flag changes from causing inconsistency\n\t\tif (!this.sessionFeatureFlags && payload.featureFlags) {\n\t\t\tthis.sessionFeatureFlags = payload.featureFlags;\n\t\t}\n\t\tconst agent = this.createWorkflow(this.sessionFeatureFlags ?? payload.featureFlags);\n\t\tconst workflowId = payload.workflowContext?.currentWorkflow?.id;","sourceCodeStart":452,"sourceCodeEnd":488,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/ai-workflow-builder.ee/src/workflow-builder-agent.ts#L452-L488","documentation":"ValidationError thrown by validateMessageLength when the user's chat message exceeds MAX_AI_BUILDER_PROMPT_LENGTH (5000 characters, defined in constants.ts). It is a deliberate pre-flight check before the message is sent to the LLM, so the user gets a clear, synchronous error instead of a provider-side rejection.","triggerScenarios":"Any call to the AI workflow builder whose payload.message string is longer than 5000 chars. The check runs in validateMessageLength before setupAgentAndConfigs, so very large pasted prompts, base64 blobs, or concatenated instruction text trip it.","commonSituations":"User pastes a huge spec, log dump, or JSON workflow into the AI assistant chat; an integration builds the prompt programmatically and forgets to truncate; a user attaches a long error trace expecting the AI to fix it.","solutions":["Shorten the message to under 5000 characters.","Split the request into multiple smaller turns, letting the assistant build incrementally.","Remove pasted binary/base64/large JSON and describe it instead.","If a higher cap is genuinely needed, change MAX_AI_BUILDER_PROMPT_LENGTH in constants.ts and rerun tests."],"exampleFix":"// before\nsendMessage(hugeSpec); // 12000 chars -> ValidationError\n\n// after\nconst chunk = hugeSpec.slice(0, 4800);\nawait sendMessage(chunk);","handlingStrategy":"validation","validationCode":"const MAX = 5000;\nfunction fitMessage(message: string): string {\n  return message.length > MAX ? message.slice(0, MAX - 1) : message;\n}","typeGuard":"const withinPromptLimit = (message: string) => message.length <= 5000;","tryCatchPattern":"try {\n  await builder.chat({ message });\n} catch (e) {\n  if (e instanceof ValidationError && /maximum length/.test(e.message)) {\n    // truncate or ask user to shorten, then retry\n  }\n  throw e;\n}","preventionTips":["Truncate user input client-side before sending to the AI assistant.","Strip base64 / large JSON blobs from prompts.","Surface a live character counter in the chat UI tied to the 5000 limit."],"tags":["ai-workflow-builder","validation","llm","input-validation"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}