Automatic Structured Document Analysis with GPT-4o and Slack Alerts - n8n Workflow

Automate PDF and TXT summarization using a powerful n8n workflow. Extract structured summaries and Q&A using GPT-4o and receive instant Slack alerts. This n8n template ensures reliable AI output validation.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Teams requiring automated document insights without manual reading.
Users looking for advanced n8n templates that combine AI, file processing, and webhook delivery.
Developers needing a robust n8n workflow example for AI output validation and error logging.
Anyone needing to quickly summarize large documents (PDFs or TXT files) using an n8n node approach.

Overview

This powerful n8n workflow is designed to solve the critical business need of quickly processing and understanding documents at scale. By leveraging the versatility of an n8n trigger (a webhook), it accepts binary file uploads (PDFs and TXT files). The n8n automation then expertly extracts the text content and feeds it to GPT-4o, ensuring that the AI output is always highly structured, featuring a concise summary and five relevant Q&A pairs.

A key feature of this n8n workflow is its robust error handling. If the AI fails to produce a valid, non-empty JSON structure, the system logs the error to a Google Sheet instead of sending broken data, maintaining system integrity. Successfully processed documents trigger both a fast JSON response back to the originating system and an immediate notification to Slack, providing vital visibility into the document analysis pipeline. This n8n template provides a professional, end-to-end solution for document intelligence.

How it Works

The flow begins with the Receive Document Upload via Webhook n8n trigger, waiting for a POST request containing a document file.


  1. File Routing: The binary file is immediately routed through two If n8n node branches: one checking for a .pdf extension and the other checking for a .txt extension.

  2. Text Extraction: The relevant Extract Text from File n8n node converts the document binary data into usable plain text.

  3. AI Setup: The n8n workflow connects the text content to the LangChain Agent, configuring it with the Azure Open AI n8n node (using GPT-4o) and the Structured Output Parser n8n node to mandate a specific JSON schema for the summary and Q&A.

  4. AI Generation: The Generate Summary & Q&A Using AI n8n node processes the text, adhering to the strict system prompt to produce a summary and 5 Q&A pairs.

  5. Validation: The Validate AI Output Before Processing n8n node checks if the resulting AI output is valid JSON and not empty.

  6. Error Logging: If validation fails (False branch), the error is logged using the Google Sheets n8n node for later review.

  7. Success Path: If successful (True branch), the output is unwrapped and prepared for delivery.

  8. Notification & Response: The Prepare Final Response Payload n8n node formats the data. The n8n workflow then simultaneously uses the Slack n8n node to send a preview alert and the Respond to Webhook n8n node to deliver the complete, structured JSON analysis back to the calling application.

Installation Guide


  1. Importing the n8n template: Copy the provided JSON and import it directly into your n8n instance using the "New" -> "Import from JSON" option.

  2. Setting up the Webhook n8n trigger: After importing, activate the Receive Document Upload via Webhook n8n trigger node to generate a unique URL. This URL is where you must send your binary file uploads.

  3. Configuring Credentials:

Azure Open AI: Connect your Azure OpenAI account credentials to the Provide LLM Engine for Document Analysis n8n node. Ensure you select the gpt-4o model.
Google Sheets: Connect your Google Sheets credentials to the Log Invalid AI Output to Google Sheet n8n node and update the Document ID and Sheet Name to point to your error logging sheet.
* Slack: Connect your Slack credentials to the Send Summary Preview to Slack n8n node and configure the target user or channel ID.

  1. Testing: Run the n8n workflow manually by sending a test PDF or TXT file to the generated webhook URL to ensure all connections and the AI parsing logic function correctly.

Node Details

Receive Document Upload via Webhook (n8n trigger): The starting n8n node. It listens for a POST request containing a binary file upload, triggering the document analysis sequence.
Check If Uploaded File Is PDF / TXT (If n8n node): These nodes determine the file type by checking the fileExtension property of the binary data, routing the document to the correct extraction path.
Extract Text from PDF/TXT File (Extract From File n8n node): Performs the crucial function of converting binary document content (PDF or TXT) into readable text that the downstream AI n8n node can process.
Provide LLM Engine for Document Analysis (LangChain LM Chat n8n node): Configures the connection to the large language model, specifically utilizing GPT-4o via Azure OpenAI credentials.
Generate Summary & Q&A Using AI (LangChain Agent n8n node): The core intelligence n8n node. It executes the detailed prompt to generate the structured summary and Q&A, following strict output rules defined in the system message.
Parse AI Summary and Q&A into Structured JSON (LangChain Output Parser n8n node): Guarantees that the AI's natural language response is converted into a reliable, predictable JSON object, essential for downstream processing in the n8n workflow.
Validate AI Output Before Processing (If n8n node): A critical n8n node for quality control, ensuring the output property received from the AI is not empty before proceeding.
Log Invalid AI Output to Google Sheet (Google Sheets n8n node): Handles errors by appending details of failed or malformed AI outputs to a designated Google Sheet.
Send Summary Preview to Slack (Slack n8n node): Provides instant internal notification, sharing a short snippet of the generated summary via a Slack message.
Send Final Summary & Q&A Response to Webhook (Respond to Webhook n8n node): Concludes the n8n workflow by sending the final, structured analysis JSON back to the system that initiated the request.

Related n8n Workflows

Free

Nodes: 12 Nodes
Updated: December 26 2025
View all
Created by

Rahul Joshi is a seasoned technology leader specializing in the n8n automation tool and AI-driven workflow automation. With deep expertise in building open-source workflow automation and self-hosted automation platforms, he helps organizations eliminate manual processes through intelligent n8n ai agent automation solutions.

Featured*