AI Document Generator Workflow v2
Shared 12/10/2025
135 views
Visual Workflow
JSON Code
{
"id": "QXqMeZHJ8edO5yQy",
"meta": {
"instanceId": "9d644af8fe730dfb972042f018ed45ff1dc2e7905a8737d59584dbe5b8c7f571",
"templateCredsSetupCompleted": true
},
"name": "generate_full_word_documents_with_ai_v2",
"tags": [],
"nodes": [
{
"id": "65356130-882c-45b4-9e07-61b85cb92647",
"name": "On form submission",
"type": "n8n-nodes-base.formTrigger",
"position": [
560,
-800
],
"webhookId": "1d84b858-d1b8-4a9f-8319-3fb6f60c58aa",
"parameters": {
"options": {},
"formTitle": "Generate docx",
"formFields": {
"values": [
{
"fieldType": "textarea",
"fieldLabel": "Prompt",
"placeholder": "Generate a template for an annual report",
"requiredField": true
}
]
},
"formDescription": "Generate a Word file (docx) with company branding"
},
"typeVersion": 2.3
},
{
"id": "4bc0767f-e2c9-4df1-9d99-c3f1cb6649c0",
"name": "Download Docx",
"type": "n8n-nodes-base.httpRequest",
"position": [
2912,
-592
],
"parameters": {
"url": "=https://api.json2doc.com/api/v1/files/{{ $json.data.outputFileId }}/download",
"options": {
"redirect": {
"redirect": {}
}
},
"sendHeaders": true,
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"headerParameters": {
"parameters": [
{
"name": "Accept",
"value": "application/octet-stream"
}
]
}
},
"credentials": {
"httpHeaderAuth": {
"id": "h6bzgCoOBp1IylkJ",
"name": "Json2Doc Public"
}
},
"typeVersion": 4.3
},
{
"id": "ac64a403-fa1d-4b75-b477-89041d49c89a",
"name": "Wait for Document Generation",
"type": "n8n-nodes-base.wait",
"position": [
2416,
-592
],
"webhookId": "d70bc21e-ad89-4df2-929f-3dafa42eceee",
"parameters": {
"amount": 3
},
"typeVersion": 1.1
},
{
"id": "68a57c4c-ef5a-4d7e-b885-4b9111aed94e",
"name": "is Completed?",
"type": "n8n-nodes-base.if",
"position": [
2736,
-592
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "27c14f40-8e32-4115-88f7-56098d814e71",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.data.status }}",
"rightValue": "COMPLETED"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "7ef0c4c9-989d-4c6a-a1b6-e2069fcba878",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
464,
-880
],
"parameters": {
"color": 5,
"width": 256,
"height": 240,
"content": "## Input Form\nTakes a Promt and a logo URL as input"
},
"typeVersion": 1
},
{
"id": "f90f5211-b679-47e7-b255-60efdfcc6d99",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
752,
-880
],
"parameters": {
"width": 304,
"height": 288,
"content": "## Create Json2Doc Session with Styling\n"
},
"typeVersion": 1
},
{
"id": "a1c8162e-9774-4208-b2b3-c257196e6597",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
2016,
-672
],
"parameters": {
"color": 6,
"width": 1040,
"height": 224,
"content": "## **Create DOCX Document & Download**"
},
"typeVersion": 1
},
{
"id": "42b12d2d-1842-44fd-98e7-feb40ecebd8a",
"name": "Plan Document Structure",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
1360,
-336
],
"parameters": {
"text": "=The user wants to create a document with the following prompt:\n```\n {{ $('On form submission').item.json.Prompt }}\n```",
"options": {
"maxIterations": 10,
"systemMessage": "=You are a professional document creator using only the Json2Doc MCP tool to get the correct schemas and create documents.\n\nCheck the user input and contiue working here:\n\nCreate an outline based on the user’s input. The output must be a JSON array.\nEach item in the array must be an object with:\n\n\"heading\" — the title of the section (Only top level sections)\n\"description\" — a markdown string with a detailed description of what this chapter should contain (which subchapters, relevant tables, etc.) \n\nLIMIT TO 4 CHAPTERS\n\nRequirements:\n\nOnly produce the JSON array, no explanations.\nAll descriptions must be short and concise.\n\nuse as orientation the following data from a previous research:\n\n{{ $json.choices[0].message.content }}"
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 3
},
{
"id": "5c049544-4bee-4113-9d13-c599a148b207",
"name": "Structured Output Parser1",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
1440,
-128
],
"parameters": {
"autoFix": true,
"schemaType": "manual",
"inputSchema": "{\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"title\": \"SimpleOutline\",\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"required\": [\"heading\", \"description\"],\n \"properties\": {\n \"heading\": {\n \"type\": \"string\"\n },\n \"description\": {\n \"type\": \"string\"\n }\n }\n }\n}\n"
},
"typeVersion": 1.3
},
{
"id": "ed556a1d-246b-4551-999b-7863c3e3dc7d",
"name": "OpenRouter Chat Model1",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
"position": [
1440,
0
],
"parameters": {
"model": "openai/gpt-5-mini",
"options": {}
},
"credentials": {
"openRouterApi": {
"id": "xyUU2VsFqfh6K7OQ",
"name": "OpenRouter account"
}
},
"typeVersion": 1
},
{
"id": "8ddde46b-37cd-42f4-835b-d86ebcc74c53",
"name": "OpenRouter Chat Model2",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
"position": [
1328,
-128
],
"parameters": {
"model": "openai/gpt-5.1-chat",
"options": {}
},
"credentials": {
"openRouterApi": {
"id": "xyUU2VsFqfh6K7OQ",
"name": "OpenRouter account"
}
},
"typeVersion": 1
},
{
"id": "0450be07-4666-4d85-a4cd-a4e766b54168",
"name": "MCP Client",
"type": "@n8n/n8n-nodes-langchain.mcpClientTool",
"position": [
2992,
-80
],
"parameters": {
"include": "selected",
"options": {},
"endpointUrl": "https://mcp.json2doc.com/mcp",
"includeTools": [
"Get_section_schema",
"Add_a_section_to_the_document"
],
"authentication": "headerAuth"
},
"credentials": {
"httpHeaderAuth": {
"id": "h6bzgCoOBp1IylkJ",
"name": "Json2Doc Public"
}
},
"typeVersion": 1.2
},
{
"id": "8fba85a6-7bc8-4641-8ca5-f60465871caa",
"name": "Generate Document from Session",
"type": "n8n-nodes-base.httpRequest",
"position": [
2208,
-592
],
"parameters": {
"url": "=https://api.json2doc.com/api/v1/document-builder/{{ $('Create new Json2Doc Session').first().json.data.sessionId }}\n/build",
"method": "POST",
"options": {},
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"credentials": {
"httpHeaderAuth": {
"id": "h6bzgCoOBp1IylkJ",
"name": "Json2Doc Public"
}
},
"typeVersion": 4.3
},
{
"id": "7238b608-0e91-4f79-8b8f-e796d21e6f1c",
"name": "Anthropic Chat Model1",
"type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
"position": [
2832,
-80
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "claude-sonnet-4-5-20250929",
"cachedResultName": "Claude Sonnet 4.5"
},
"options": {
"maxTokensToSample": 8000
}
},
"credentials": {
"anthropicApi": {
"id": "Z42XVzspYjSpsh7A",
"name": "Anthropic account"
}
},
"typeVersion": 1.3
},
{
"id": "1af1ab88-a8dc-422e-aeb4-4aab034f3e60",
"name": "Get Job Status",
"type": "n8n-nodes-base.httpRequest",
"position": [
2576,
-592
],
"parameters": {
"url": "=https://api.json2doc.com/api/v1/jobs/{{ $('Generate Document from Session').item.json.data.jobId }}",
"options": {
"redirect": {
"redirect": {}
}
},
"sendHeaders": true,
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"headerParameters": {
"parameters": [
{}
]
}
},
"credentials": {
"httpHeaderAuth": {
"id": "h6bzgCoOBp1IylkJ",
"name": "Json2Doc Public"
}
},
"typeVersion": 4.3
},
{
"id": "b42257d8-be76-4051-9b68-1ab7ea66344e",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
1088,
-432
],
"parameters": {
"color": 3,
"width": 2032,
"height": 560,
"content": "# Research & Generate the Chapters"
},
"typeVersion": 1
},
{
"id": "d6d49488-7bdb-49d0-9920-a38ac4a83f44",
"name": "When Executed by Another Workflow",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
1152,
208
],
"parameters": {
"workflowInputs": {
"values": [
{
"name": "prompt"
}
]
}
},
"typeVersion": 1.1
},
{
"id": "d5f5fe34-0ea3-449d-b861-6c3ed2e4d6c0",
"name": "Generate an image",
"type": "@n8n/n8n-nodes-langchain.googleGemini",
"position": [
1328,
208
],
"parameters": {
"prompt": "={{ $json.prompt }}, (format 16:9, white background, no text)",
"modelId": {
"__rl": true,
"mode": "list",
"value": "models/imagen-4.0-generate-001",
"cachedResultName": "models/imagen-4.0-generate-001"
},
"options": {},
"resource": "image"
},
"credentials": {
"googlePalmApi": {
"id": "VZnYI5accyfwkzyk",
"name": "Google Gemini(PaLM) Api account (new)"
}
},
"typeVersion": 1
},
{
"id": "bc013fce-9a3a-4838-9d22-5b28942c015f",
"name": "Upload Image",
"type": "n8n-nodes-base.httpRequest",
"position": [
1504,
208
],
"parameters": {
"url": "https://api.json2doc.com/api/v1/files/upload",
"method": "POST",
"options": {},
"sendBody": true,
"contentType": "multipart-form-data",
"authentication": "genericCredentialType",
"bodyParameters": {
"parameters": [
{
"name": "ttlHours",
"value": "1"
},
{
"name": "file",
"parameterType": "formBinaryData",
"inputDataFieldName": "data"
}
]
},
"genericAuthType": "httpHeaderAuth"
},
"credentials": {
"httpHeaderAuth": {
"id": "h6bzgCoOBp1IylkJ",
"name": "Json2Doc Public"
}
},
"typeVersion": 4.3
},
{
"id": "a9eea821-732b-4488-ba35-79e8950ca213",
"name": "Edit Fields",
"type": "n8n-nodes-base.set",
"position": [
1680,
208
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "f7cd820b-d554-4e3e-a60e-f311de6db783",
"name": "data.storageUrl",
"type": "string",
"value": "={{ $json.data.storageUrl }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "e5b172d5-8615-44bb-b718-c5500f17665d",
"name": "Create new Json2Doc Session",
"type": "n8n-nodes-base.httpRequest",
"position": [
848,
-800
],
"parameters": {
"url": "https://api.json2doc.com/api/v1/document-builder",
"method": "POST",
"options": {
"redirect": {
"redirect": {}
}
},
"jsonBody": "{\n \"config\": {\n \"document\": {\n \"type\": \"docx\",\n \"filename\": \"sustainable-report\",\n \"title\": \"Sustainable Report\",\n \"marginTop\": 2,\n \"marginBottom\": 2,\n \"marginLeft\": 2,\n \"marginRight\": 2,\n \"size\": \"A4\",\n \"orientation\": \"portrait\"\n },\n \"defaults\": {\n \"fontFamily\": \"Segoe UI\",\n \"fontSize\": 11,\n \"color\": \"#2d5016\",\n \"lineHeight\": 1.5,\n \"spacing\": {\n \"before\": {\n \"h1\": 24,\n \"h2\": 18,\n \"h3\": 14,\n \"text\": 0,\n \"table\": 15,\n \"list\": 10,\n \"image\": 15,\n \"chart\": 15,\n \"h4\": 14,\n \"h5\": 12,\n \"h6\": 10,\n \"text2\": 0,\n \"qrcode\": 10,\n \"code\": 10\n },\n \"after\": {\n \"h1\": 18,\n \"h2\": 14,\n \"h3\": 10,\n \"text\": 12,\n \"table\": 15,\n \"list\": 10,\n \"image\": 15,\n \"chart\": 15,\n \"h4\": 8,\n \"h5\": 6,\n \"h6\": 5,\n \"text2\": 10,\n \"qrcode\": 15,\n \"code\": 15\n }\n },\n \"styles\": {\n \"h1\": {\n \"fontSize\": 28,\n \"fontWeight\": \"bold\",\n \"color\": \"#1b5e20\",\n \"align\": \"center\"\n },\n \"h2\": {\n \"fontSize\": 22,\n \"fontWeight\": \"bold\",\n \"color\": \"#2d5016\"\n },\n \"h3\": {\n \"fontSize\": 18,\n \"fontWeight\": \"bold\",\n \"color\": \"#558b2f\"\n },\n \"text\": {\n \"fontSize\": 11,\n \"lineHeight\": 1.4,\n \"align\": \"justify\",\n \"color\": \"#2d5016\"\n },\n \"text2\": {\n \"fontSize\": 9,\n \"color\": \"#7cb342\",\n \"align\": \"center\"\n },\n \"table\": {\n \"borders\": {\n \"outer\": {\n \"width\": 1.5,\n \"color\": \"#1b5e20\",\n \"style\": \"solid\"\n },\n \"inner\": {\n \"width\": 0.5,\n \"color\": \"#c5e1a5\",\n \"style\": \"solid\"\n }\n },\n \"header\": {\n \"backgroundColor\": \"#1b5e20\",\n \"color\": \"#ffffff\",\n \"fontSize\": 12,\n \"fontWeight\": \"bold\",\n \"fontStyle\": \"normal\",\n \"align\": \"center\"\n },\n \"rows\": {\n \"backgroundColor\": \"#f1f8e9\",\n \"color\": \"#2d5016\",\n \"fontSize\": 11,\n \"fontWeight\": \"normal\",\n \"fontStyle\": \"normal\",\n \"align\": \"left\",\n \"alternateBackgroundColor\": \"#dcedc8\"\n },\n \"cellPadding\": {\n \"top\": 8,\n \"right\": 8,\n \"bottom\": 8,\n \"left\": 8\n }\n }\n },\n \"chart\": {\n \"colors\": [\n \"#1b5e20\",\n \"#558b2f\",\n \"#7cb342\",\n \"#9ccc65\",\n \"#c5e1a5\"\n ],\n \"borderColors\": [\n \"#1b5e20\",\n \"#2d5016\",\n \"#558b2f\",\n \"#7cb342\",\n \"#9ccc65\"\n ]\n },\n \"header\": {\n \"left\": \"Sustainability LLC\",\n \"right\": {\n \"type\": \"image\",\n \"src\": \"https://img.icons8.com/external-vitaliy-gorbachev-lineal-color-vitaly-gorbachev/60/external-sustainable-ecology-vitaliy-gorbachev-lineal-color-vitaly-gorbachev.png\",\n \"width\": 32,\n \"alt\": \"Sustainability Logo\"\n },\n \"excludeFirstPage\": false\n },\n \"footer\": {\n \"center\": \"Page {{pageNumber}} of {{totalPages}}\",\n \"align\": \"center\",\n \"excludeFirstPage\": false\n }\n },\n \"sections\": [\n ]\n}\n}",
"sendBody": true,
"specifyBody": "json",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth"
},
"credentials": {
"httpHeaderAuth": {
"id": "h6bzgCoOBp1IylkJ",
"name": "Json2Doc Public"
}
},
"typeVersion": 4.3
},
{
"id": "b1e5fc20-4afa-4c10-bf4b-93bd16a69e95",
"name": "Loop Over Items",
"type": "n8n-nodes-base.splitInBatches",
"position": [
1856,
-336
],
"parameters": {
"options": {
"reset": false
}
},
"typeVersion": 3
},
{
"id": "f0f502d7-5d29-4f2c-8d20-938e0edabc3f",
"name": "Split Out",
"type": "n8n-nodes-base.splitOut",
"position": [
1648,
-336
],
"parameters": {
"include": "allOtherFields",
"options": {},
"fieldToSplitOut": "output"
},
"typeVersion": 1
},
{
"id": "8561a003-dbdf-440e-9a5f-72c60352749e",
"name": "Aggregate",
"type": "n8n-nodes-base.aggregate",
"position": [
2064,
-592
],
"parameters": {
"options": {},
"aggregate": "aggregateAllItemData"
},
"typeVersion": 1
},
{
"id": "88242a0b-3cb7-4910-86c0-0c8c51e7d457",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
1088,
160
],
"parameters": {
"width": 816,
"height": 224,
"content": "## Image Generation for Agent"
},
"typeVersion": 1
},
{
"id": "b5a7b38e-0c67-4199-92da-f5473fcb422f",
"name": "MCP Client1",
"type": "@n8n/n8n-nodes-langchain.mcpClientTool",
"position": [
1808,
-624
],
"parameters": {
"include": "selected",
"options": {},
"endpointUrl": "https://mcp.json2doc.com/mcp",
"includeTools": [
"Add_a_section_to_the_document"
],
"authentication": "headerAuth"
},
"credentials": {
"httpHeaderAuth": {
"id": "h6bzgCoOBp1IylkJ",
"name": "Json2Doc Public"
}
},
"typeVersion": 1.2
},
{
"id": "76806b7b-bc1a-41f0-857a-bae489c7e78e",
"name": "Anthropic Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
"position": [
1648,
-624
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "claude-haiku-4-5-20251001",
"cachedResultName": "Claude Haiku 4.5"
},
"options": {
"maxTokensToSample": 8000
}
},
"credentials": {
"anthropicApi": {
"id": "Z42XVzspYjSpsh7A",
"name": "Anthropic account"
}
},
"typeVersion": 1.3
},
{
"id": "4f38e16b-4ac1-474c-a064-9b5ed744ac73",
"name": "Generate Title Page",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
1664,
-800
],
"parameters": {
"text": "=The user wants to create a document with the following prompt:\n```\n {{ $('On form submission').item.json.Prompt }}\n```\n\nfor the title page Image use the following StorageUrl:\n```\n{{ $json.data.storageUrl }}\n```",
"options": {
"maxIterations": 6,
"systemMessage": "=You are a professional document creator using only the Json2Doc MCP tool to get the correct schemas and create sections. Your job is it to create one section based on the user Input and add this section to the jobSession. You only genereate the Title page With centered Content and a Title Image\n\nCheck the user input and generate based on the information a new Section that should be added to the session with the id:\n```\n{{ $('Create new Json2Doc Session').first().json.data.sessionId }}\n```\n\n\nhow to proceed :\n1. generate ONE Json Definition for the section based on the schema below containing a headline and a sub header as well as an image for the title page. Use the type \"page\" for this section.\nHere is an example:\n```\n{\n \"type\": \"page\",\n \"align\": \"center\",\n \"content\": [\n {\n \"type\": \"h1\",\n \"text\": \"company name\",\n \"fontSize\": 28,\n \"color\": \"#0066cc\",\n \"align\": \"center\"\n },\n {\n \"type\": \"h2\",\n \"text\": \"sub heading\",\n \"fontSize\": 20,\n \"color\": \"#333333\",\n \"align\": \"center\"\n },\n {\n \"type\": \"text\",\n \"text\": \"*more informations*\",\n \"fontSize\": 16,\n \"color\": \"#666666\",\n \"align\": \"center\"\n },\n {\n \"type\": \"image\",\n \"src\": \"/image/2025-10-31/cmh107bik0001116um9xyurjo/efa92fae-411c-489b-b71e-d6fca197ca65.png\",\n \"height\": 100,\n \"align\": \"center\"\n }\n ]\n }\n```\n\n2. Add the new section to the session with the json from 1 (if vaidation returns invalid retry until its valid and you get the job id).\n3. return just \"success\" after the response of 4\n\nBE STRICT FOLLOWING THESE STEPS\n\nSCHEMA (As TS interfaces):\n```\n{{ $json.data }}\n```\n"
},
"promptType": "define"
},
"executeOnce": false,
"typeVersion": 3
},
{
"id": "07017202-d5ca-442c-9015-9f4c1cc94b60",
"name": "Message a model",
"type": "n8n-nodes-base.perplexity",
"position": [
2080,
-384
],
"parameters": {
"options": {},
"messages": {
"message": [
{
"content": "=Get the most important information ONLY for the following chapter:\n```\nheading: {{ $json.output.heading }}\ndescription: {{ $json.output.description }}\n```\nfor document context:\nfull prompt as reference only:\n```\n{{ $('On form submission').first().json.Prompt }}\n```\nall chapters (DO NOT ADD INFORMATIONS THAT MAY BE ALREADY IN ANOTHER CHAPTER):\n```\n{{ $('Plan Document Structure').first().json.output.toJsonString() }}\n```"
}
]
},
"simplify": true,
"requestOptions": {}
},
"credentials": {
"perplexityApi": {
"id": "o5GrteFg4GzuN29u",
"name": "Perplexity account"
}
},
"typeVersion": 1
},
{
"id": "19ad9d99-8963-4507-8be8-775d6e1265e7",
"name": "Sticky Note6",
"type": "n8n-nodes-base.stickyNote",
"position": [
1072,
-880
],
"parameters": {
"width": 304,
"height": 400,
"content": "## Get the Json schema"
},
"typeVersion": 1
},
{
"id": "c42899ca-8354-4ba0-9d1c-d58222093ec6",
"name": "Get Document Schema",
"type": "n8n-nodes-base.httpRequest",
"position": [
1168,
-832
],
"parameters": {
"url": "https://api.json2doc.com/api/v1/schemas/document?type=ts",
"options": {}
},
"typeVersion": 4.3
},
{
"id": "0ea71e00-f72d-46b8-8573-8b21b94f2e8c",
"name": "Create Title Image",
"type": "n8n-nodes-base.executeWorkflow",
"position": [
1488,
-800
],
"parameters": {
"options": {},
"workflowId": {
"__rl": true,
"mode": "list",
"value": "QXqMeZHJ8edO5yQy",
"cachedResultUrl": "/workflow/QXqMeZHJ8edO5yQy",
"cachedResultName": "2r_generate_full_word_documents_with_ai_v2"
},
"workflowInputs": {
"value": {
"prompt": "=Create a clean, modern headline image with a white background. The image must visually represent only the overarching theme of:\n\n```\n{{ $('On form submission').item.json.Prompt }}\n```\n\nUse abstract, symbolic, or conceptual elements—not people, faces, headshots, characters, or any portrait-style imagery.\nDo not depict documents, pages, screens, or any user interface elements.\nAim for a minimalistic yet expressive visual style with soft lighting and a balanced composition.\nThe artwork should function as a cover-appropriate thematic image for the beginning of a document.\nDO NOT USE TEXT IN THE IMAGE."
},
"schema": [
{
"id": "prompt",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "prompt",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"prompt"
],
"attemptToConvertTypes": false,
"convertFieldsToString": true
}
},
"typeVersion": 1.3
},
{
"id": "5cf1e049-0a6b-4e9c-98b7-63c6cef41221",
"name": "Sticky Note7",
"type": "n8n-nodes-base.stickyNote",
"position": [
1408,
-880
],
"parameters": {
"color": 3,
"width": 560,
"height": 400,
"content": "## Generate Title Image & First Page"
},
"typeVersion": 1
},
{
"id": "952a8db9-3ef3-4926-befb-4358f52e7d55",
"name": "determine content and required image",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
2304,
-384
],
"parameters": {
"text": "=Determine for the following chapter:\n{{ $('Loop Over Items').item.json.output.toJsonString() }}",
"options": {
"systemMessage": "=**Task Overview:** \nYou are an AI agent responsible for deciding whether an image should be generated for a given section of a document. You receive three inputs: \n1. **Headline** – the title of the current section \n2. **Perplexity research input**:\n\n```\n{{ $json.message }}\n```\n\n3. **Chapter overview**:\n\n```\n{{ $('Plan Document Structure').first().json.output.toJsonString() }}\n```\n\n**Your job:** \n1. **Determine whether an image is useful at this point in the document.** \n An image is useful if it adds meaningful visual value, enhances understanding of the section’s overarching theme, or improves the document’s structure or clarity. Use the chapter overview to avoid repeating visuals for themes that have already appeared.\n\n2. **If an image *is* useful:** \n - Extract the overarching theme from the headline and research context. \n - Generate the image using the MCP image-generation tool. Include: **DO NOT USE TEXT IN IMAGE**\n - After generating, output the following JSON object:\n\n \n {\n \"should_generate_image\": true,\n \"image_theme\": \"<extracted_theme>\",\n \"image_generation_prompt\": \"<final_prompt_used>\",\n \"output_path\": \"<mcp_output_path>\"\n }\n \n\n3. **If an image is *not* useful:** \n Output the following JSON object (all other fields must be empty strings):\n\n \n {\n \"should_generate_image\": false,\n \"image_theme\": \"\",\n \"image_generation_prompt\": \"\",\n \"output_path\": \"\"\n }\n \n\n**Requirements:** \n- Extract and use only the overarching theme—do not use detailed subtopics. \n- Avoid generating duplicate or redundant images based on the chapter overview. \n- Always follow the exact JSON structures shown above. "
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 3
},
{
"id": "79595ddd-17bb-4fac-a1ed-6fcc33b3b3ee",
"name": "Structured Output Parser",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
2496,
-256
],
"parameters": {
"autoFix": true,
"jsonSchemaExample": "{\n \"should_generate_image\": true,\n \"image_theme\": \"\",\n \"image_generation_prompt\": \"\",\n \"output_path\": \"\"\n}"
},
"typeVersion": 1.3
},
{
"id": "27cd61aa-b6a9-445d-b3d0-ffa21e45e652",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
2240,
-256
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-5-mini",
"cachedResultName": "gpt-5-mini"
},
"options": {},
"builtInTools": {}
},
"credentials": {
"openAiApi": {
"id": "nthYYcpDIou7MYYb",
"name": "OpenAi account"
}
},
"typeVersion": 1.3
},
{
"id": "1a36115f-e614-4d94-b70e-439b5fbb7ec0",
"name": "Generate Image",
"type": "@n8n/n8n-nodes-langchain.toolWorkflow",
"position": [
2400,
-256
],
"parameters": {
"workflowId": {
"__rl": true,
"mode": "list",
"value": "QXqMeZHJ8edO5yQy",
"cachedResultUrl": "/workflow/QXqMeZHJ8edO5yQy",
"cachedResultName": "2r_generate_full_word_documents_with_ai_v2"
},
"description": "Call this tool to generate an image and get its local path",
"workflowInputs": {
"value": {
"prompt": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('prompt', ``, 'string') }}"
},
"schema": [
{
"id": "prompt",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "prompt",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"prompt"
],
"attemptToConvertTypes": false,
"convertFieldsToString": false
}
},
"typeVersion": 2.2
},
{
"id": "d06917a7-c566-4144-90b3-2c864a758f5b",
"name": "Section Generator",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
2848,
-288
],
"parameters": {
"text": "=Now add the next chapter with the following headline and comprehensive content that matches the description. If necessary, subchapters may also be created:\n\nHeading: {{ $('Loop Over Items').item.json.output.heading }}\nDescription: {{ $('Loop Over Items').item.json.output.description }}\n\ncontext information from research (use as orientation and for correct numbers):\n\n```\n{{ $('Message a model').item.json.message }}\n```\n",
"options": {
"maxIterations": 8,
"systemMessage": "=You are a professional document creator using only the Json2Doc MCP tool to get the correct schemas and create sections. Your job is it to create one section based on the user Input and add this section to the jobSession\n\nCheck the user input and generate based on the information a new Section that should be added to the session with the id:\n```\n{{ $('Create new Json2Doc Session').first().json.data.sessionId }}\n```\n\n\nhow to proceed :\n\n1. generate ONE Json Definition for the section based on the schema below containing all relevant elements and informations for this section. Always add numbering of headings. use ordered and undordered list when useful but make a natural mix of paragraphs, lists, tables, charts and images. NOTE: DONT ADD CUSTOM STYLING, AS THIS IS ALREADY DEFINED GLOBAL (also applies to image width and height)\n\n2. Add the new section to the session with the json from 1 (if vaidation returns invalid retry until its valid and you get the job id). USE 99 AS INDEX\n5. return just \"success\" after the response of 3\n\nBE STRICT FOLLOWING THESE STEPS\n\nfor context, here the complete planned document structure. Ensure that you do not create duplicate content form this refrence:\n```\n{{ $('Plan Document Structure').first().json.output.toJsonString() }}\n```\n\nSchema for Section generation (as TS interfaces):\n```\n{{ $('Get Section Schema').first().json.data }}\n```"
},
"promptType": "define"
},
"executeOnce": false,
"typeVersion": 3
},
{
"id": "7a59ce7e-39c8-406e-a621-246deb8f1105",
"name": "Get Section Schema",
"type": "n8n-nodes-base.httpRequest",
"position": [
1168,
-656
],
"parameters": {
"url": "https://api.json2doc.com/api/v1/schemas/section?type=ts",
"options": {}
},
"typeVersion": 4.3
},
{
"id": "d8c03cf0-fe9b-4c10-b003-a8d820f129f3",
"name": "Research content",
"type": "n8n-nodes-base.perplexity",
"position": [
1184,
-336
],
"parameters": {
"options": {},
"messages": {
"message": [
{
"content": "=Research and list possible topics, sections, and key points that could be included in a document based on the following prompt:\n\n{{ $('On form submission').item.json.Prompt }}\n\nFocus on relevant, structured, and informative content ideas.\n"
}
]
},
"requestOptions": {}
},
"credentials": {
"perplexityApi": {
"id": "o5GrteFg4GzuN29u",
"name": "Perplexity account"
}
},
"typeVersion": 1
}
],
"active": true,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "d100cdd0-6810-43e6-96cb-d6248f5e0d9e",
"connections": {
"Aggregate": {
"main": [
[
{
"node": "Generate Document from Session",
"type": "main",
"index": 0
}
]
]
},
"Split Out": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"MCP Client": {
"ai_tool": [
[
{
"node": "Section Generator",
"type": "ai_tool",
"index": 0
}
]
]
},
"MCP Client1": {
"ai_tool": [
[
{
"node": "Generate Title Page",
"type": "ai_tool",
"index": 0
}
]
]
},
"Upload Image": {
"main": [
[
{
"node": "Edit Fields",
"type": "main",
"index": 0
}
]
]
},
"is Completed?": {
"main": [
[
{
"node": "Download Docx",
"type": "main",
"index": 0
}
],
[
{
"node": "Wait for Document Generation",
"type": "main",
"index": 0
}
]
]
},
"Generate Image": {
"ai_tool": [
[
{
"node": "determine content and required image",
"type": "ai_tool",
"index": 0
}
]
]
},
"Get Job Status": {
"main": [
[
{
"node": "is Completed?",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items": {
"main": [
[
{
"node": "Aggregate",
"type": "main",
"index": 0
}
],
[
{
"node": "Message a model",
"type": "main",
"index": 0
}
]
]
},
"Message a model": {
"main": [
[
{
"node": "determine content and required image",
"type": "main",
"index": 0
}
]
]
},
"Research content": {
"main": [
[
{
"node": "Plan Document Structure",
"type": "main",
"index": 0
}
]
]
},
"Generate an image": {
"main": [
[
{
"node": "Upload Image",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "Structured Output Parser",
"type": "ai_languageModel",
"index": 0
},
{
"node": "determine content and required image",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Section Generator": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Create Title Image": {
"main": [
[
{
"node": "Generate Title Page",
"type": "main",
"index": 0
}
]
]
},
"Get Section Schema": {
"main": [
[
{
"node": "Create Title Image",
"type": "main",
"index": 0
}
]
]
},
"On form submission": {
"main": [
[
{
"node": "Create new Json2Doc Session",
"type": "main",
"index": 0
}
]
]
},
"Generate Title Page": {
"main": [
[
{
"node": "Research content",
"type": "main",
"index": 0
}
]
]
},
"Get Document Schema": {
"main": [
[
{
"node": "Get Section Schema",
"type": "main",
"index": 0
}
]
]
},
"Anthropic Chat Model": {
"ai_languageModel": [
[
{
"node": "Generate Title Page",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Anthropic Chat Model1": {
"ai_languageModel": [
[
{
"node": "Section Generator",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"OpenRouter Chat Model1": {
"ai_languageModel": [
[
{
"node": "Structured Output Parser1",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"OpenRouter Chat Model2": {
"ai_languageModel": [
[
{
"node": "Plan Document Structure",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Plan Document Structure": {
"main": [
[
{
"node": "Split Out",
"type": "main",
"index": 0
}
]
]
},
"Structured Output Parser": {
"ai_outputParser": [
[
{
"node": "determine content and required image",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Structured Output Parser1": {
"ai_outputParser": [
[
{
"node": "Plan Document Structure",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Create new Json2Doc Session": {
"main": [
[
{
"node": "Get Document Schema",
"type": "main",
"index": 0
}
]
]
},
"Wait for Document Generation": {
"main": [
[
{
"node": "Get Job Status",
"type": "main",
"index": 0
}
]
]
},
"Generate Document from Session": {
"main": [
[
{
"node": "Wait for Document Generation",
"type": "main",
"index": 0
}
]
]
},
"When Executed by Another Workflow": {
"main": [
[
{
"node": "Generate an image",
"type": "main",
"index": 0
}
]
]
},
"determine content and required image": {
"main": [
[
{
"node": "Section Generator",
"type": "main",
"index": 0
}
]
]
}
}
}