Files
n8nworkflows.xyz/workflows/Generate workflow JSON files from webhook prompts using Azure OpenAI GPT-4o-mini-13787/13787-generate-workflow-json-files-from-webhook-prompts-using-azure-openai-gpt-4o-mini.webp
nusquama f2c6242b9f creation
2026-03-10 12:09:22 +08:00

1 line
9.3 KiB
Plaintext

{"id":"HzCoQz3rqyIpSYRr","meta":{"instanceId":"8443f10082278c46aa5cf3acf8ff0f70061a2c58bce76efac814b16290845177","templateCredsSetupCompleted":true},"name":"AI Workflow Generator","tags":[],"nodes":[{"id":"cb9054f7-a792-4f88-98b7-7f34509d8084","name":"Receive Workflow Prompt","type":"n8n-nodes-base.webhook","position":[-112,544],"webhookId":"7b183879-9ca9-45ba-815c-3c7e9b908f88","parameters":{"path":"7b183879-9ca9-45ba-815c-3c7e9b908f88","options":{},"httpMethod":"POST","responseMode":"responseNode"},"typeVersion":2.1},{"id":"6e8c9b64-c8b6-4125-a7ca-4718ea746aff","name":"Sanitize & Normalize Prompt","type":"n8n-nodes-base.code","position":[96,544],"parameters":{"jsCode":"// Extract prompt safely\nlet prompt = $json.body?.prompt || \"\";\n\n// Normalize formatting\nprompt = prompt\n .replace(/\\r\\n/g, \"\\n\") // normalize Windows line breaks\n .replace(/\\n\\s+\\n/g, \"\\n\\n\") // remove excessive spacing\n .trim(); // remove leading/trailing spaces\n\nreturn [\n {\n json: {\n prompt: prompt\n }\n }\n];"},"typeVersion":2},{"id":"78b4c991-ee4d-4376-93e3-711b06b3a21b","name":"Generate Workflow via AI Agent","type":"@n8n/n8n-nodes-langchain.agent","position":[304,544],"parameters":{"text":"=Generate a complete production-ready n8n workflow JSON for the following automation:\n\n{{ $json.prompt }}\n\nRequirements:\n\nInclude proper triggers\n\nInclude required logic\n\nInclude error handling IF needed\n\nEnsure all nodes are connected\n\nEnsure import-ready JSON\n\nSet workflow active to false\n\nProvide realistic node positions\n\nUse best-practice structure\n\nReturn ONLY pure JSON.","options":{"systemMessage":"=You are a senior n8n workflow architect.\n\nYour task is to generate a COMPLETE, IMPORT-READY, VALID n8n workflow JSON.\n\nCRITICAL RULES:\n\nOutput ONLY raw JSON.\n\nDo NOT wrap in markdown.\n\nDo NOT explain anything.\n\nDo NOT include comments.\n\nDo NOT include backticks.\n\nDo NOT include extra text before or after JSON.\n\nThe response must start with { and end with }.\n\nJSON must be valid and parsable.\n\nAll nodes must be properly connected.\n\nAll required properties must exist.\n\nREQUIRED WORKFLOW STRUCTURE\n\nYou MUST return a valid n8n workflow object with:\n\nname\n\nnodes (array)\n\nconnections (object)\n\nactive (false)\n\nsettings (object)\n\nversionId\n\nmeta (object)\n\nid (null)\n\nNODE RULES\n\nEach node must include:\n\nid (unique string)\n\nname\n\ntype\n\ntypeVersion\n\nposition [x, y]\n\nparameters (object)\n\nAll nodes must be connected correctly in the connections object.\n\nNo orphan nodes.\n\nConnection format must follow n8n standard:\n\nExample:\n\"connections\": {\n\"Schedule Trigger\": {\n\"main\": [\n[\n{\n\"node\": \"HTTP Request\",\n\"type\": \"main\",\n\"index\": 0\n}\n]\n]\n}\n}\n\nLOGIC RULES\n\nIf user mentions time → use Schedule Trigger node\n\nIf user mentions email → use Gmail node\n\nIf user mentions spreadsheet → use Google Sheets node\n\nIf user mentions webhook → use Webhook node\n\nIf summarization or AI needed → use OpenAI node\n\nIf condition required → use IF node\n\nIf data transformation needed → use Function node\n\nAlways choose correct official n8n node types like:\n\nn8n-nodes-base.scheduleTrigger\n\nn8n-nodes-base.gmail\n\nn8n-nodes-base.googleSheets\n\nn8n-nodes-base.httpRequest\n\nn8n-nodes-base.if\n\nn8n-nodes-base.function\n\nn8n-nodes-base.webhook\n\nn8n-nodes-base.openAi\n\nVALIDATION RULES\n\nEnsure connections match node names exactly.\n\nEnsure positions are spaced (e.g., 200px apart horizontally).\n\nEnsure no missing commas.\n\nEnsure valid JSON formatting.\n\nEnsure workflow can be directly imported into n8n without edits.\n\nIf user input is unclear, intelligently infer a logical automation flow.\n\nReturn ONLY valid n8n JSON."},"promptType":"define"},"typeVersion":3},{"id":"b719e9dc-bbb5-4945-9ffc-7b81f63efc49","name":"Parse & Validate AI JSON Output","type":"n8n-nodes-base.code","position":[656,544],"parameters":{"jsCode":"// Step 1: Get the raw output string\nlet rawOutput = $json.output;\n\n// Step 2: Ensure it's a string\nif (typeof rawOutput !== \"string\") {\n throw new Error(\"Output is not a string\");\n}\n\n// Step 3: Parse JSON safely\nlet parsedWorkflow;\n\ntry {\n parsedWorkflow = JSON.parse(rawOutput);\n} catch (error) {\n throw new Error(\"Invalid JSON returned by AI: \" + error.message);\n}\n\n// Step 4: Return clean normalized JSON\nreturn [\n {\n json: parsedWorkflow\n }\n];"},"typeVersion":2},{"id":"ac81bb2e-33a4-4d1c-95b8-44d4afbdef57","name":"Convert Workflow to JSON File","type":"n8n-nodes-base.convertToFile","position":[864,544],"parameters":{"options":{},"operation":"toJson"},"typeVersion":1.1},{"id":"450fe5e9-2ae4-4923-9ee8-f295003f0240","name":"Return JSON File to Caller","type":"n8n-nodes-base.respondToWebhook","position":[1088,544],"parameters":{"options":{},"respondWith":"binary"},"typeVersion":1.5},{"id":"ab863cf3-3f1c-42df-8927-fd1881870ae3","name":"📋 Overview","type":"n8n-nodes-base.stickyNote","position":[-688,288],"parameters":{"color":3,"width":500,"height":836,"content":"## 🧠 AI Workflow Generator\n\n### How it works\nThis workflow accepts a plain-text automation description via a POST webhook and uses an Azure OpenAI-powered AI Agent to generate a fully valid, import-ready n8n workflow JSON. The generated JSON is then parsed, validated, converted to a downloadable file, and returned to the caller as a binary response.\n\n**Data flow:**\n1. **Receive Workflow Prompt** — Accepts POST request with a `prompt` field describing the desired automation.\n2. **Sanitize & Normalize Prompt** — Cleans whitespace and line breaks to ensure consistent input.\n3. **Generate Workflow via AI Agent** — Sends the prompt to Azure OpenAI GPT-4o-mini with strict system instructions to return only raw JSON.\n4. **Parse & Validate AI JSON Output** — Parses the AI's string output into a structured JSON object, throwing errors on invalid responses.\n5. **Convert Workflow to JSON File** — Wraps the parsed JSON into a downloadable `.json` binary file.\n6. **Return JSON File to Caller** — Sends the binary file back as the webhook HTTP response.\n\n### Setup steps\n1. Configure your **Azure OpenAI credentials** (`azureOpenAiApi`) in n8n credentials.\n2. Ensure your Azure deployment uses the `gpt-4o-mini` model name.\n3. Activate the workflow and copy the webhook URL.\n4. Send a POST request with body: `{ \"prompt\": \"Your automation description here\" }`\n\n### Customization\n- Swap `gpt-4o-mini` with another Azure deployment for higher quality output.\n- Extend the AI system prompt to enforce additional n8n node types or coding standards."},"typeVersion":1},{"id":"d11fd04b-a949-4429-9770-dfd4505ea824","name":"📥 Section: Input & Prompt Prep","type":"n8n-nodes-base.stickyNote","position":[-144,352],"parameters":{"width":420,"height":200,"content":"## 📥 Input & Prompt Preparation\nReceives the raw POST request and extracts the `prompt` field. Normalizes line breaks and trims whitespace so the AI always gets clean, consistent input."},"typeVersion":1},{"id":"0997a823-87c3-48bb-a350-c5f98de409db","name":"🤖 Section: AI Generation","type":"n8n-nodes-base.stickyNote","position":[304,336],"parameters":{"width":420,"height":200,"content":"## 🤖 AI Workflow Generation\nThe AI Agent uses Azure OpenAI GPT-4o-mini with a strict system prompt to produce a complete, import-ready n8n workflow JSON. No markdown, no explanations — raw JSON only."},"typeVersion":1},{"id":"107a24ff-7a90-42ae-9f78-9a85f91f9a54","name":"📤 Section: Output Processing","type":"n8n-nodes-base.stickyNote","position":[752,352],"parameters":{"width":560,"height":200,"content":"## 📤 Output Processing & Response\nParses and validates the AI's raw string output into structured JSON, converts it to a downloadable file, and returns it to the caller as a binary HTTP response."},"typeVersion":1},{"id":"97f124e8-c0ff-406d-8d04-97239f0eb207","name":"⚠️ Warning: Azure OpenAI Credentials","type":"n8n-nodes-base.stickyNote","position":[48,896],"parameters":{"color":2,"width":300,"height":150,"content":"⚠️ **Azure OpenAI Credentials Required**\nThis node requires a valid `azureOpenAiApi` credential with an active deployment named `gpt-4o-mini`. Misconfiguration will cause all AI generation to fail."},"typeVersion":1},{"id":"ac57db68-8517-4840-b125-4a5a6a634dbf","name":"Azure OpenAI Chat Model1","type":"@n8n/n8n-nodes-langchain.lmChatAzureOpenAi","position":[176,752],"parameters":{"model":"gpt-4o-mini","options":{}},"credentials":{"azureOpenAiApi":{"id":"C3WzT18XqF8OdVM6","name":"Azure Open AI account"}},"typeVersion":1}],"active":false,"pinData":{},"settings":{"executionOrder":"v1"},"versionId":"959dcb1e-528e-498b-9928-4e5531958286","connections":{"Receive Workflow Prompt":{"main":[[{"node":"Sanitize & Normalize Prompt","type":"main","index":0}]]},"Azure OpenAI Chat Model1":{"ai_languageModel":[[{"node":"Generate Workflow via AI Agent","type":"ai_languageModel","index":0}]]},"Sanitize & Normalize Prompt":{"main":[[{"node":"Generate Workflow via AI Agent","type":"main","index":0}]]},"Convert Workflow to JSON File":{"main":[[{"node":"Return JSON File to Caller","type":"main","index":0}]]},"Generate Workflow via AI Agent":{"main":[[{"node":"Parse & Validate AI JSON Output","type":"main","index":0}]]},"Parse & Validate AI JSON Output":{"main":[[{"node":"Convert Workflow to JSON File","type":"main","index":0}]]}}}