AI Prompt Optimization Tool using Dynamic Forms and Gemini - n8n Workflow

Generate perfect, structured AI prompts using this advanced n8n workflow. It leverages the Google Gemini n8n node to refine user intent via dynamic forms, creating optimal AI prompts. Find this and more n8n templates for complex automation.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Prompt engineers and AI developers needing highly specific inputs.
n8n developers looking for advanced LLM design patterns.
SaaS builders who need dynamic user input collection tools.
Users seeking sophisticated n8n templates for complex, multi-stage AI automation.

Overview

The complexity of modern AI agents requires precise and highly structured prompting. This n8n workflow solves the problem of vague initial inputs by employing a multi-stage refinement loop. Instead of relying solely on the user's first attempt, this robust n8n workflow first gathers basic intent, uses a Large Language Model (LLM) to identify missing contextual information, presents clarifying questions via a dynamic n8n form, and finally uses all the enriched data to generate a perfect, structured prompt. This sophisticated use of the underlying n8n node system, particularly the LangChain integration and Form nodes, significantly improves the quality and reliability of the final prompt output. This example serves as one of the most useful n8n templates for demonstrating advanced AI automation and core logic flow control within n8n.

How it Works

This complex n8n workflow executes in several distinct stages:


  1. Initiation (The n8n trigger): The process begins with the 'On form submission' n8n trigger. Users provide initial, high-level details about the AI tool they wish to build via the 'BaseQuestions' n8n node.

  2. Question Generation: The initial data is passed to the RelatedQuestionAI (LangChain LLM) n8n node. This node, using the Google Gemini model, acts as an expert prompt refinement agent, analyzing the input and dynamically generating 3 critical follow-up questions in a structured JSON format to resolve ambiguities.

  3. Dynamic Form Creation: The output from the AI is processed by the SplitQuestions and LoopQuestions n8n node components, which structure the generated JSON array to dynamically configure the 'RelevantQuestions' n8n form.

  4. Refined Input Collection: The user answers the AI-generated clarifying questions in the dynamic form.

  5. Data Merge: The MergeUserIntent n8n node combines the data from the initial 'BaseQuestions' and the subsequent 'RelevantQuestions' into a single, comprehensive JSON payload.

  6. Final Prompt Generation: The entire merged dataset is fed into the PromptGenerator LangChain n8n node. Acting as an expert prompt engineer, this node crafts the final, highly structured master prompt using strict sections (Role, Constraints, Inputs, Tools, Instructions, Conclusions).

  7. Delivery: The final output is parsed and presented directly to the user via the 'SendingPrompt' n8n form, concluding the execution of this complex n8n workflow.

Installation Guide


  1. Import the n8n workflow: Copy the provided JSON code and paste it into your n8n canvas using the 'Import Workflow' function.

  2. Set up Credentials: This n8n workflow requires credentials for the Google Gemini (PaLM) API. Locate the Google Gemini Chat Model and Google Gemini Chat Model1 n8n node instances and configure your Google Gemini API key.

  3. Activate the n8n trigger: Activate the workflow. The 'On form submission' n8n trigger will generate a public URL for the initial form. Use this URL to start the automation.

  4. Test: Run the n8n workflow to ensure the dynamic forms load correctly and the AI nodes execute without credential errors. This n8n template is now ready for use.

Node Details

On form submission (n8n trigger): The starting point of the n8n workflow. It initiates the sequence by providing the initial form link to the user.
BaseQuestions & RelevantQuestions (Form n8n node): Used to collect user input. The 'RelevantQuestions' node is configured to dynamically define its fields based on the JSON output generated by the AI agent.
RelatedQuestionAI (LangChain Chain LLM n8n node): Uses the Google Gemini model to analyze vague user intent and generate 3 specific follow-up questions in a structured JSON schema, optimizing for clarity.
Google Gemini Chat Model / Google Gemini Chat Model1 (LLM n8n node): Provides the underlying large language model capability for both generating clarifying questions and, in the second instance, synthesizing the final structured prompt.
SplitQuestions & LoopQuestions (Logic n8n node): Essential core logic n8n nodes used to correctly format the AI-generated JSON array so that the subsequent n8n form node can render the fields dynamically.
MergeUserIntent (Merge n8n node): Crucial n8n node that combines the two distinct sets of user answers (base input + clarifying questions) into a single unified input for the final PromptGenerator.
PromptGenerator (LangChain Chain LLM n8n node): The final stage of this n8n workflow. It takes the complete user data and constructs a comprehensive, structured prompt adhering to the specified Role, Constraints, and Instructions format.
SendingPrompt (Form n8n node): Displays the final generated prompt as a completion message, allowing the user to copy the optimized text.

Related n8n Workflows

Free

Nodes: 10 Nodes
Updated: December 26 2025
View all
Created by
Anurag Srivastava
Anurag Srivastava

Featured*