Repository: n8n-io/n8n
File: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/responder.prompt.ts (TypeScript)

Code before:
 */

/** Guidance for recursion error when workflow was successfully created */
export function buildRecursionErrorWithWorkflowGuidance(nodeCount: number): string[] {
	return [
		`**Workflow Status:** ${nodeCount} node${nodeCount === 1 ? '' : 's'} ${nodeCount === 1 ? 'was' : 'were'} created before the complexity limit was reached.`,
		"Tell the user that you've created their workflow but reached a complexity limit while fine-tuning. " +
			'The workflow should work and they can test it. ' +
			'If they need adjustments or want to continue building, they can ask you to make specific changes.',
	];
}

/** Guidance for recursion error when no workflow was created */
export function buildRecursionErrorNoWorkflowGuidance(): string[] {
	return [
		'**Workflow Status:** No nodes were created - the request was too complex to process automatically.',
		'Explain that the workflow design became too complex for automatic generation. ' +
			'Suggest options: (1) Break the request into smaller steps, (2) Simplify the workflow, ' +
			'or (3) Start with a basic version and iteratively add complexity.',
	];
}

/** Guidance for other (non-recursion) errors */
export function buildGeneralErrorGuidance(): string {
	return (
		'Apologize and explain that a technical error occurred. ' +
		'Ask if they would like to try again or approach the problem differently.'
	);
}

/**
 * Build guidance for data table creation.
 * Data tables must be created manually - the AI workflow builder cannot create them automatically.
 */
export function buildDataTableCreationGuidance(dataTables: DataTableInfo[]): string {
	if (dataTables.length === 0) {
		return '';
	}

	const tableGuidance = dataTables.map((table) => {
		const isColumnOperation = isDataTableRowColumnOperation(table.operation);
		const columnInfo = buildColumnInfo(table, isColumnOperation);
		return `- **${table.nodeName}** (${table.operation}): ${columnInfo}`;
	});

	return prompt({ format: 'markdown' })
		.section(
			'Data Table Setup Required',
			`Data tables must be created manually before the workflow can run.
Do NOT tell the user that data tables will be created automatically.


Review comment (bug):
The use of the word "explain" could be a risk here, explanation usually comes along with technical details. It might be better to state "Tell the user something went wrong while building the workflow, do not offer explanation or mention specific technical errors."

Code after:
 */

/** Guidance for recursion error when workflow was successfully created */
export function buildRecursionErrorWithWorkflowGuidance(nodeCount: number): string[] {
	return [
		`**Workflow Status:** ${nodeCount} node${nodeCount === 1 ? '' : 's'} ${nodeCount === 1 ? 'was' : 'were'} created before the complexity limit was reached.`,
		"Tell the user that you've created their workflow but reached a complexity limit while fine-tuning. " +
			'The workflow should work and they can test it. ' +
			'If they need adjustments or want to continue building, they can ask you to make specific changes.',
	];
}

/** Guidance for recursion error when no workflow was created */
export function buildRecursionErrorNoWorkflowGuidance(): string[] {
	return [
		'**Workflow Status:** No nodes were created - the request was too complex to process automatically.',
		'Explain that the workflow design became too complex for automatic generation. ' +
			'Suggest options: (1) Break the request into smaller steps, (2) Simplify the workflow, ' +
			'or (3) Start with a basic version and iteratively add complexity.',
	];
}

/** Guidance for other (non-recursion) errors */
export function buildGeneralErrorGuidance(): string {
	return (
		'Apologize briefly and explain that something went wrong while building the workflow. ' +
		'Do NOT use the phrase "technical error". ' +
		'Suggest the user try again, and offer to help approach the problem differently if the issue persists.'
	);
}

/**
 * Build guidance for data table creation.
 * Data tables must be created manually - the AI workflow builder cannot create them automatically.
 */
export function buildDataTableCreationGuidance(dataTables: DataTableInfo[]): string {
	if (dataTables.length === 0) {
		return '';
	}

	const tableGuidance = dataTables.map((table) => {
		const isColumnOperation = isDataTableRowColumnOperation(table.operation);
		const columnInfo = buildColumnInfo(table, isColumnOperation);
		return `- **${table.nodeName}** (${table.operation}): ${columnInfo}`;
	});

	return prompt({ format: 'markdown' })
		.section(
			'Data Table Setup Required',
			`Data tables must be created manually before the workflow can run.
Do NOT tell the user that data tables will be created automatically.