Skip to main content

Chat-based financial analysis of P&L and balance sheets with GPT-4 & PostgreSQL

Workflow preview

Workflow preview
100%
Chat-based financial analysis of P&L and balance sheets with GPT-4 & PostgreSQL preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

Who’s it for This workflow is designed for finance teams , accountants , and data analysts who want to interact with financial data from two PostgreSQL databases — one containing Profit & Los...

Best for

  • Document Extraction automation workflows
  • Multimodal AI automation workflows
  • intermediate n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.agent, n8n-nodes-base.postgrestool, @n8n/n8n-nodes-langchain.memorybufferwindow, @n8n/n8n-nodes-langchain.lmchatopenai, n8n-nodes-base.stickynote, @n8n/n8n-nodes-langchain.chattrigger

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Zain Ali.

Original n8n.io source

1.1 Workflow description

Title
Chat-based financial analysis of P&L and balance sheets with GPT-4 & PostgreSQL
Workflow name
Chat-based financial analysis of P&L and balance sheets with GPT-4 & PostgreSQL

🧾 Who’s it for

This workflow is designed for finance teams, accountants, and data analysts 📊 who want to interact with financial data from two PostgreSQL databases — one containing Profit & Loss data and another containing Balance Sheet data — using natural language chat.
It’s perfect for those who need quick, AI-powered insights with the correct database automatically selected based on the question.


⚙️ How it works / What it does

  1. Chat Trigger 💬 – Starts the workflow when a chat message is received.
  2. AI Agent 🤖 – Processes the user’s question and decides:
    • Profit & Loss DB → If the question is about revenue, costs, expenses, or profit.
    • Balance Sheet DB → If the question is about assets, liabilities, or equity.
  3. PostgreSQL Query Nodes 🗄️
    • P_L_Reports queries the financial_agent_pl_reports table.
    • Balance_Sheets queries the financial_agent_balancesheets table.
  4. AI Model (OpenAI) 🧠 – Uses gpt-4.1-nano to interpret results and provide an easy-to-read answer.
  5. Memory Buffer 📝 – Keeps recent conversation context for a smoother chat experience.
  6. Table Output 📋 – Always formats the results as a clean, readable table with two decimal precision.

🛠️ How to set up

  1. Prepare Your Databases

    • Feed your Profit & Loss and Balance Sheet data into PostgreSQL.
    • Ensure the correct table structures are used:
      • financial_agent_pl_reports → P&L data.
      • financial_agent_balancesheets → Balance Sheet data.
  2. Configure the PostgreSQL Nodes

    • Add connection credentials for both databases.
    • Link P_L_Reports and Balance_Sheets nodes to the correct tables.
  3. Set Up the AI Agent

    • Paste the provided system message into the AI Agent node (already configured in your workflow).
  4. Connect the Nodes

    • Ensure Chat Trigger → AI Agent → DB Nodes → AI Model connections match your workflow.
  5. Deploy

    • Save and activate the workflow.
    • Start sending finance-related queries to test.

📋 Requirements

  • n8n (latest version recommended)
  • PostgreSQL databases with:
    • financial_agent_pl_reports table (P&L data).
    • financial_agent_balancesheets table (Balance Sheet data).
  • OpenAI API credentials with access to gpt-4.1-nano.
  • Active Webhook/Chat Trigger for receiving queries.

🎨 How to customize

  • Expand AI Instructions 🗒️ – Add more rules in the system message for different data sources or formatting styles.
  • Change AI Model 🧠 – Switch to a different OpenAI model for faster or more accurate results.
  • Add More Databases 🗄️ – Connect extra financial datasets, e.g., cash flow, sales analytics.
  • Enhance Table Styling 📊 – Use Markdown or HTML formatting for richer outputs.
  • Refine Query Logic 🔍 – Modify filtering logic to better match your reporting needs.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - AI Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 2.1

Block 2 - P_L_Reports

Type / Role
n8n-nodes-base.postgresTool - postgresTool
Config choices
Version 2.6

Block 3 - Balance_Sheets

Type / Role
n8n-nodes-base.postgresTool - postgresTool
Config choices
Version 2.6

Block 4 - Simple Memory

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.3

Block 5 - OpenAI Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 6 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 7 - When chat message received

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.3

3. Summary Table

Workflow Chat-based financial analysis of P&L and balance sheets with GPT-4 & PostgreSQL
Complexity intermediate
Nodes 7
Categories Document Extraction, Multimodal AI
Author Zain Ali
Published 09 Aug 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/7197/7197.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Chat-based financial analysis of P&L and balance sheets with GPT-4 & PostgreSQL do?

Who’s it for This workflow is designed for finance teams , accountants , and data analysts who want to interact with financial data from two PostgreSQL databases — one containing Profit & Los...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Document Extraction, Multimodal AI use case.