ChatGPTSalesRevenue growthAI score · PendingAI-assisted edit · no obvious prompt-injection riskn8n.io

Chat with Snowflake via n8n AI Agent and Generate Dynamic Reports

Natural language question → AI generates and executes SQL → aggregates results → returns small data directly / generates an interactive report link for large datasets

ExperiencedStepsWorkflowPrompt
Who
Developers and data analysts who have a Snowflake database and want to query it via natural language in n8n, with automated visual report generation
You get
Query Snowflake through a chat interface; AI auto-generates and executes SQL. Results under 100 rows are returned directly; larger sets produce a dynamic report link with pagination, filtering, charts, and CSV export
You need
n8n

Constraints

Prerequisites: an n8n instance; Snowflake account credentials (host, account, warehouse, database, schema, username, password); OpenAI API Key. Create openAiApi and snowflake credentials in n8n. Replace placeholder schema names (e.g., TPCH_SF1) and the webhook address with your actual values. Default threshold is 100 records to decide report link generation.

What they did

Author lowcodingdev (Mark Shcherbakov) published this workflow template on the n8n official template gallery. It comprises four coordinated n8n workflows: Agent Workflow (chat trigger + AI Agent + schema tools), Data Retrieval Workflow (SQL execution), Aggregation and Reporting Decision (threshold-based routing), and Report Viewing Workflow (webhook-triggered HTML report). The template uses gpt-4o-mini as the language model and Simple Memory for session context.

How it went

Author-reported (author_report) outcomes: users can ask natural-language questions via chat; the AI references live database schema to generate SQL and executes it safely; large result sets are aggregated and routed to a dynamic report link with pagination, filtering, charts, and CSV export, avoiding high token costs from sending full datasets to the LLM; error recovery prompts regeneration on SQL or connectivity issues.

Worth knowing

1) Schema queries hardcode 'TPCH_SF1' and must be replaced with your actual schema name; 2) The report link webhook address (n8n.lowcoding.dev) must be replaced with your actual n8n instance URL; 3) The default 100-row threshold can be adjusted in the 'If Count>100' node; 4) Requires pre-configured openAiApi and snowflake credentials in n8n; 5) 'Get table definition' uses $fromAI('table_name') to dynamically receive table names, relying on the AI to extract the correct name; 6) The Report Viewing Workflow HTML report depends on Chart.js CDN, requiring external network access; 7) This site has not tested the template; actual results depend on Snowflake data volume, network latency, and correct credential configuration.

n8n workflow template

Structure checked · Not run-tested

Use “Import from File” in n8n, or copy the JSON and paste it into the editor. Connect your own accounts, then try test data. The template is inactive by default.

Setup and test checklist

Credentials to connect

  • OpenAI Chat Model1 node: connect OpenAI API credentials.
  • DB Schema1 node: connect snowflake credentials.
  • Get table definition node: connect snowflake credentials.
  • Snowflake1 node: connect snowflake credentials.
  • Execute SQL node: connect snowflake credentials.

Configuration to replace

  • Source template is n8n public workflow #5435 (~28 nodes). Keep inactive after import; verify triggers, expressions and external API endpoints.
  • Sticky-note guidance is informational; replace placeholders with your own accounts, sheet schemas or channel IDs.

Test input and expected output

  • Manually run the main path once in a test workspace and confirm credentialed nodes authenticate without errors.
  • Drive one synthetic/redacted sample through and check output fields and downstream writes before enabling in production.

Template changes

  • Author credential bindings, webhookId and execution data are removed; the workflow is inactive. Nodes, connections and original prompts are preserved. Not run-tested in n8n.
  • No business-logic edits; verify keys, quotas and privacy compliance before use.

Template retrieved: 2026-10-25

Steps

  1. Configure Agent and Database Schema Tools

    After importing the template, configure the Agent Workflow: 1) 'When chat message received' as the trigger; 2) 'AI Agent1' using OpenAI gpt-4o-mini with Simple Memory attached (sessionKey from the chat trigger's sessionId); 3) Attach 'DB Schema1' and 'Get table definition' Snowflake Tool nodes as AI tools. 'DB Schema1' queries information_schema.tables for table lists; 'Get table definition' queries information_schema.columns for column metadata. Both use snowflake credentials, and the schema name in queries must be replaced with your actual schema.

    Execution prompt · Source text。AI Agent1 node systemMessage field

    You are Snowflake SQL assistant.
    
    Use tools to retrieve data from Snowflake and answer user.
    
    IMPORTANT Always check database schema and table definition for preparing SQL query.
  2. Configure Data Retrieval Sub-Workflow

    Configure the 'Retrieve Data' tool node (Call n8n Workflow Tool), which passes AI-generated SQL to the Data Retrieval Workflow for execution. In 'Retrieve Data' parameters: workflowId points to your Data Retrieval sub-workflow; the description field contains the tool description telling the AI how to generate SQL; workflowInputs defines the input variable 'query', dynamically filled by the AI. The Data Retrieval Workflow itself uses 'When Executed by Another Workflow' as trigger, receives the query parameter, executes it via the 'Execute SQL' Snowflake node, with error output handled by 'Return Error'.

    Execution prompt · Source text。Retrieve Data tool node description field (AI tool description)

    Generate custom SQL queries using knowledge about DB schema and table definitions to provide needed response for user request.
    Use ->> operator to extract JSON data.
    
    Supported functions for big data analysis:
    • GROUP BY – for grouping data
    • SUM() – for summing values
    • AVG() – for calculating averages
    • COUNT() – for counting records
    • MIN() – for finding the minimum value
    • MAX() – for finding the maximum value
    • MEDIAN() – for median calculation
    • STDDEV() – for standard deviation
    • VARIANCE() – for variance calculation
    • PERCENTILE_CONT() – for percentile calculations
    • MODE() – for most frequent value
    • TREND() – for trend analysis over time
    • WINDOW FUNCTIONS – for advanced analytics (e.g., ROW_NUMBER(), RANK(), PARTITION BY)
    
    Query example:
    SELECT * FROM FILES
  3. Configure Aggregation and Reporting Decision Branch

    In the Data Retrieval Workflow, after 'Execute SQL', connect to 'Aggregate Data' (aggregateAllItemData), then to 'If Count>100' condition node. The condition checks whether the aggregated data array length exceeds 100: if yes, route to 'Link to Report' to generate a webhook link with URL-encoded SQL; if no, route to 'Return Data' to return raw results to the Agent. The 100 threshold can be adjusted in the If node.

  4. Configure Report Viewing Workflow

    Configure the Report Viewing Workflow: entry via 'Webhook' node (responseMode=responseNode), receiving the sql parameter from the report link. 'Snowflake1' re-executes the SQL (query from $json.query.sql), with error output routed to 'Error page'; normal results pass through 'Aggregate1' to 'Set HTML', which generates a complete HTML report page (pagination, column filtering, sorting, chart view, CSV export), finally returned by 'Respond to Webhook'. Replace the webhook address in 'Link to Report' with your actual n8n instance Webhook URL.

Prompt you can copy

Setup guidance · Editorial suggestion。Hand to setup assistant; confirm inputs and permissions first, then guide step-by-step reproduction

This block is the prompt. Ads are never placed here.

You are an n8n workflow setup assistant. The user wants to reproduce the 'AI Agent chat with Snowflake and dynamic reports' template. First confirm the user has: 1) an accessible n8n instance; 2) Snowflake connection details (host, account, warehouse, database, schema, username, password); 3) an OpenAI API Key. Then guide them to: import template → create openAiApi and snowflake credentials → replace schema and database placeholders → replace webhook address → test connection → start chatting. If SQL generation fails, check whether the AI Agent's systemMessage is complete and whether schema tools return correct table structures.

Confirm credentials and permissions first, replace placeholders, then test.

Source

AI agent to chat with Snowflake database · lowcodingdev · n8n.io · 2025-06-28

Comments & feedback

Tried this method? Share results, problems or improvements. Comments appear after moderation. Please avoid sensitive information.

Loading…

    Related