Automate legal and business document creation using this advanced n8n workflow. Integrates Google Gemini, Drive, and Apps Script to generate custom, ready-to-sign PDFs instantly from Google Docs templates.
Download this n8n workflow template and start using it instantly.
Legal Professionals & HR: Need to generate contracts, NDAs, or employment forms quickly and without errors.
Technical Writers/Integrators: Looking for advanced n8n templates that showcase LangChain agents, custom tooling, and deep Google service integration.
Business Owners: Seeking to automate repetitive administrative tasks involving document generation.
n8n Automation Specialists: Users who want to implement a highly reliable, two-stage document processing n8n workflow.
This comprehensive n8n workflow, dubbed 'DocAgent', solves the costly and error-prone problem of manual document filling. Instead of copying templates, this automation uses a conversational AI agent to intelligently collect all necessary dynamic data from the user.
The core of this powerful n8n workflow involves a Gemini agent that orchestrates the entire process, using tools to fetch template metadata (placeholders and conditional blocks) before initiating the final document assembly via a dedicated sub-workflow. Every new Google Doc template placed in your Drive folder becomes instantly available for use without editing the main n8n node logic. This ensures a scalable solution, turning Google Docs into dynamic, ready-to-sign PDFs instantly. This specific n8n workflow is a prime example of leveraging custom code (Google Apps Script) alongside standard n8n nodes for complex, file-based operations.
The entire process is initiated by the When chat message received n8n trigger, activating the document agent.
When chat message received n8n trigger starts the chat. The DocAgent (a LangChain Agent) retrieves the list of available document templates (pre-fetched via the Template List n8n node and injected into the prompt).GetMetaData tool. This tool, an HTTP request to Google Apps Script, retrieves the document's structure, including mandatory placeholders and optional conditional blocks. This is a crucial n8n node for dynamic data processing.DocProcess tool, which is an n8n workflow reference, passing the collected data and template IDs to the sub-workflow.When Executed by Another Workflow n8n trigger. It first uses the User Choice Match Check n8n node (powered by Gemini) to validate that the Agent correctly matched the template name with its ID.Format Control n8n node uses Gemini again to ensure the collected user data is perfectly formatted into the required JSON structure dictated by the template's metadata. The Formatting Correction n8n node (Code node) cleans the LLM output.CopyTemplate Google Drive n8n node duplicates the original template into a designated output folder.FillDocument HTTP Request n8n node sends the copied document ID and the prepared JSON data to the Google Apps Script endpoint. This script performs the actual document modification (placeholder substitution and removal of excluded conditional blocks).if n8n node checks the status. On success, the Generate Download Link n8n node retrieves the application/pdf export link. On failure, a Switch n8n node routes errors (e.g., missing fields) back to the Agent so it can re-prompt the user, making this a highly resilient n8n workflow structure.To deploy this advanced n8n workflow, follow these steps:
PARENTID> ).Template List n8n node. Update the URL query parameter '%3CYOURPARENTID%3E' with your actual template folder ID. Execute this n8n node and manually copy the resulting JSON list.DocAgent n8n node and the User Choice Match Check n8n node (where it says {{ YOURMANUALTOADDTEMPLATELIST }}). This optimizes token usage.GetMetaData.gs and FillDocument.gs) as a Web App (access: 'Anyone', execute as: 'Me'). Note the Web App URL (DEPLOY_ID> ).GetMetaData, FillDocument, and GetMetaData2 n8n nodes with your GAS Web App URL.DocProcess n8n node (in the main workflow) references the correct ID of the sub-workflow that starts with the When Executed by Another Workflow n8n trigger.This complex n8n workflow utilizes several specialized n8n nodes:
When chat message received (n8n trigger): The starting n8n trigger for the conversational agent flow, exposing a public webhook.
DocAgent (LangChain Agent n8n node): The core intelligence, using the Gemini model and a detailed system prompt defining the step-by-step Turkish legal drafting process.
Google Gemini Chat Model (n8n node): Provides the large language model capabilities (using models/gemini-2.5-pro) for the agent and for structured data validation.
Postgres Chat Memory (n8n node): Used by the DocAgent to maintain context and conversation history across multiple messages.
GetMetaData (n8n node) & GetMetaData2 (n8n node): HTTP Request nodes calling the Google Apps Script to dynamically fetch placeholders and conditional block structures of the selected document template.
DocProcess (toolWorkflow n8n node): The link that delegates the document filling task to the dedicated sub-workflow, passing inputs via the workflow's n8n trigger mechanism.
User Choice Match Check (LangChain Chain LLM n8n node): Uses Gemini for AI-based validation of the user's template selection against the internal template catalog.
Format Control (LangChain Chain LLM n8n node): A critical n8n node that uses the LLM to structure the raw user inputs into the precise JSON format required by the document filling script.
CopyTemplate (Google Drive n8n node): Performs the necessary operation of duplicating the chosen template before filling.
FillDocument (n8n node): The final HTTP request n8n node that sends the structured data payload to the Apps Script service to generate the final document.
Generate custom ASMR sound effects using this powerful n8n workflow. Input a prompt via a web form, generate high-quality audio with ElevenLabs, and save the MP3 file directly to Google Drive. Find more useful n8n templates.

Use this powerful n8n workflow to automatically curate, summarize, and format engaging newsletters from niche Reddit discussions using GPT-4o Mini and Gmail. Perfect for rapid content creation.

Use this advanced n8n workflow to deploy dual AI agents for content research. It leverages SerpApi for data, GPT-4 for strategy, and saves insights to Google Sheets.

Use this advanced n8n workflow to build conversational AI agents that leverage structured knowledge graphs (Graph RAG). Integrate specialized reasoning ontologies via a custom n8n node tool to achieve expert-level advice.

Use this powerful n8n workflow to automate cold outreach. Ingest CSV lead lists, create dynamic Google Sheets, and generate personalized Google Slides presentations for every prospect.









































