Skip to main content

AI agent to chat with Snowflake database

Workflow preview

Workflow preview
100%
AI agent to chat with Snowflake database preview
Open on n8n.io

Important notice

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

1. Workflow Overview

Video Guide I prepared a detailed guide showcasing the process of building an AI agent that interacts with a Snowflake database using n8n. This setup enables conversational querying, secure executi...

Best for

  • Internal Wiki automation workflows
  • AI Chatbot automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.chattrigger, @n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.lmchatopenai, @n8n/n8n-nodes-langchain.memorybufferwindow, n8n-nodes-base.snowflaketool, n8n-nodes-base.webhook, n8n-nodes-base.set, n8n-nodes-base.respondtowebhook

Source and attribution

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

Original n8n.io source

1.1 Workflow description

Title
AI agent to chat with Snowflake database
Workflow name
AI agent to chat with Snowflake database

Video Guide

I prepared a detailed guide showcasing the process of building an AI agent that interacts with a Snowflake database using n8n. This setup enables conversational querying, secure execution of SQL queries, and dynamic report generation with rich visualization capabilities.

Youtube Link

Who is this for?

This workflow is designed for developers, data analysts, and business professionals who want to interact with their Snowflake data conversationally. It suits users looking to automate SQL query generation with AI, manage large datasets efficiently, and produce interactive reports without deep technical knowledge.

What problem does this workflow solve?

Querying Snowflake databases typically requires SQL proficiency and can lead to heavy token usage if large datasets are sent to AI models directly. This workflow addresses these challenges by:

  • Guiding AI to generate accurate SQL queries based on user chat input while referencing live database schema to avoid errors.
  • Executing queries safely on Snowflake with proper credential management.
  • Aggregating large result sets to reduce token consumption.
  • Offering a user-friendly report link with pagination, filtering, charts, and CSV export instead of returning overwhelming raw data.
  • Providing an error-resilient environment that prompts regenerations for SQL errors or connectivity issues.

What this workflow does

The scenario consists of multiple focused n8n workflows orchestrated for smooth, secure, and scalable interactions:

  1. Agent Workflow

    • Starts with a chat node and sets the system role as "Snowflake SQL assistant."
    • AI generates SQL after verifying database schema and table definitions to avoid hallucinations.
    • Reinforcement rules ensure schema validation before query creation.
  2. Data Retrieval Workflow

    • Receives SQL queries from the agent workflow.
    • Executes them against the Snowflake database using user-provided credentials (hostname, account, warehouse, database, schema, username, password).
    • Optionally applies safety checks on SQL to prevent injection attacks.
  3. Aggregation and Reporting Decision

    • Aggregates returned data into arrays for efficient processing.
    • Applies a threshold (default 100 records) to decide whether to return raw data or generate a dynamic report link.
    • Prepares report links embedding URL-encoded SQL queries to securely invoke a separate report workflow.
  4. Report Viewing Workflow

    • Triggered via webhook from the report link.
    • Re-executes SQL queries to fetch fresh data.
    • Displays data with pagination, column filtering, and selectable chart visualizations.
    • Supports CSV export and custom HTML layouts for tailored user experience.
    • Provides proper error pages in case of SQL or data issues.
  5. Schema and Table Definition Retrieval Tools

    • Two helper workflows that fetch the list of tables and column metadata from Snowflake.
    • Require the user to replace placeholders with actual database and data source names.
    • Crucial for AI to maintain accurate understanding of the database structure.

N8N Workflow

Preparation

  • Create your Snowflake credentials in n8n with required host and account details, warehouse (e.g., "computer_warehouse"), database, schema, username, and password.
  • Replace placeholder variables in schema retrieval workflows with your actual database and data source names.
  • Verify the credentials by testing the connection; reset passwords if needed.

Workflow Logic

  • The Agent Workflow listens to user chats, employs system role "Snowflake SQL assistant," and ensures schema validation before generating SQL queries.
  • Generated SQL queries pass to the Data Retrieval Workflow, which executes them against Snowflake securely.
  • Retrieved data is aggregated and evaluated against a configurable threshold to decide between returning raw data or creating a report link.
  • When a report link is generated, the Report Viewing Workflow renders a dynamic interactive HTML-based report webpage, including pagination, filters, charts, and CSV export options.
  • Helper workflows periodically fetch or update the current database schema and table definitions to maintain AI accuracy and prevent hallucinations in SQL generation.
  • Error handling mechanisms provide user-friendly messages both in the agent chat and report pages when issues arise with SQL or connectivity.

This modular, secure, and extensible setup empowers you to build intelligent AI-driven data interactions with Snowflake through n8n automations and custom reporting.

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 - When chat message received

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

Block 2 - AI Agent1

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

Block 3 - OpenAI Chat Model1

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

Block 4 - Simple Memory

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

Block 5 - DB Schema1

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

Block 6 - Get table definition

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

Block 7 - Webhook

Type / Role
n8n-nodes-base.webhook - webhook
Config choices
Version 2

Block 8 - Set HTML

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 9 - Respond to Webhook

Type / Role
n8n-nodes-base.respondToWebhook - respondToWebhook
Config choices
Version 1.1

Block 10 - Snowflake1

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

Block 11 - Aggregate1

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

Block 12 - When Executed by Another Workflow

Type / Role
n8n-nodes-base.executeWorkflowTrigger - executeWorkflowTrigger
Config choices
Version 1.1

Block 13 - Retrieve Data

Type / Role
@n8n/n8n-nodes-langchain.toolWorkflow - toolWorkflow
Config choices
Version 2.2

Block 14 - Sticky Note

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

Block 15 - Sticky Note1

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

Block 16 - Sticky Note2

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

Block 17 - Execute SQL

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

Block 18 - Aggregate Data

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

Block 19 - If Count>100

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 20 - Link to Report

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 21 - Return Data

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 22 - Return Error

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 23 - Error page

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 24 - Sticky Note4

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

Showing the first 24 of 28 workflow blocks. Download the JSON for the full node graph.

3. Summary Table

Workflow AI agent to chat with Snowflake database
Complexity advanced
Nodes 28
Categories Internal Wiki, AI Chatbot
Author Mark Shcherbakov
Published 28 Jun 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/5435/5435.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 AI agent to chat with Snowflake database do?

Video Guide I prepared a detailed guide showcasing the process of building an AI agent that interacts with a Snowflake database using n8n. This setup enables conversational querying, secure executi...

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 Internal Wiki, AI Chatbot use case.