Snowflake SQL
Execute SQL queries on Snowflake data warehouse with secure OAuth 2.0 authentication.
Author: langgenius
Version: 0.0.1
Type: Tool Plugin
Overview
The Snowflake SQL plugin enables seamless integration between Dify AI applications and Snowflake data warehouse. Execute any SQL query securely using OAuth 2.0 authentication, with support for all major SQL operations including SELECT, INSERT, UPDATE, DELETE, and DDL statements.
Key Features
- 🔐 OAuth 2.0 Authentication - Secure, industry-standard authentication
- 🚀 Full SQL Support - Execute SELECT, INSERT, UPDATE, DELETE, CREATE, and more
- 📊 Rich Output Formats - Results displayed as formatted Markdown tables
- ⚡ Performance Tracking - Monitor query execution time
- 🎯 Flexible Configuration - Per-query warehouse, database, and schema selection
- 🛡️ Type-Safe Operations - Explicit SQL type selection for accurate result handling
Installation
Prerequisites
You need a Snowflake account with appropriate permissions to create OAuth integrations. Follow these steps to set up OAuth authentication:
1. Create OAuth Integration in Snowflake
Run the following SQL commands in Snowflake (requires role):
2. Retrieve OAuth Credentials
Copy the and values - you'll need these for plugin configuration.
3. Grant Necessary Privileges
Install in Dify
- Navigate to Tools > Manage Tools in your Dify workspace
- Search for "Snowflake SQL" in the marketplace
- Click Install to add the plugin
- Configure OAuth credentials (see Configuration section below)
Configuration
OAuth Setup
After installation, configure the following OAuth parameters:
| Parameter | Type | Required | Description |
|---|
| Account Name | Text | Yes | Your Snowflake account identifier (e.g., ) |
| OAuth Client ID | Secret | Yes | Client ID from |
| OAuth Client Secret | Secret | Yes | Client Secret from |
| OAuth Scope | Text | No | Optional OAuth scope (e.g., ) |
Authentication Flow
- Click Connect with OAuth in the plugin configuration
- You'll be redirected to Snowflake's authentication page
- Log in with your Snowflake credentials
- Authorize the application to access your Snowflake account
- You'll be redirected back to Dify with the connection established
The OAuth token is automatically managed and refreshed by the plugin.
Usage
Tool Parameters
| Parameter | Type | Required | Default | Description |
|---|
| SQL Query | String | Yes | - | The SQL statement to execute |
| SQL Type | Select | Yes | SELECT | Type of SQL operation |
| Warehouse | String | No | COMPUTE_WH | Snowflake warehouse name |
| Database | String | No | - | Target database |
| Schema | String | No | PUBLIC | Target schema |
| Max Rows | Number | No | 100 | Maximum rows to return (SELECT only) |
SQL Types
Select the appropriate SQL type for your query:
- SELECT - Retrieve data (returns rows and columns)
- INSERT - Add new records (returns affected row count)
- UPDATE - Modify existing records (returns affected row count)
- DELETE - Remove records (returns affected row count)
- MERGE - Upsert operations (returns affected row count)
- CREATE - Create database objects (returns execution status)
- DROP - Remove database objects (returns execution status)
- ALTER - Modify database objects (returns execution status)
- TRUNCATE - Clear table data (returns execution status)
- SHOW - Display metadata (returns rows and columns)
- DESCRIBE - Describe objects (returns rows and columns)
- OTHER - Other SQL statements
💡 Tip: Always specify the correct SQL type, especially for queries with WITH clauses, as they can be used with INSERT, UPDATE, or DELETE operations.
Examples
Example 1: Query Customer Data
Input:
Output:
Example 2: Insert Order Record
Input:
Output:
Example 3: Complex Analytics Query
Input:
Integration Scenarios
1. AI-Powered Data Analysis
Use with Dify Agent to create an intelligent data analyst that can query your database and explain results in natural language.
2. Automated Reporting Workflow
Create workflows that generate daily/weekly reports by querying Snowflake and formatting results.
3. Customer Support Chatbot
Build chatbots that can look up customer information, order status, and other data in real-time.
Output Schema
All queries return structured JSON data:
Best Practices
Security
- ✅ Use OAuth with minimum required privileges
- ✅ Create dedicated service roles for integration
- ✅ Block privileged roles in OAuth integration
- ❌ Don't grant unnecessary permissions
Performance
- ✅ Use clauses to reduce data transfer
- ✅ Specify appropriate parameter
- ❌ Avoid on large tables
Query Design
- ✅ Always specify SQL type correctly
- ✅ Test queries in Snowflake before production use
- ❌ Don't use dynamic SQL from untrusted input
Troubleshooting
Authentication Errors
Error: "OAuth authentication required"
Solution: Reconnect OAuth in plugin settings.
Query Errors
Error: "SQL compilation error: Object does not exist"
Solution: Verify database, schema, and table names. Check permissions.
Permission Errors
Error: "Insufficient privileges to operate on table"
Solution: Grant necessary permissions to your OAuth role.
Support
Development Notes
Plugin Structure
Local Development
Key Implementation Details
Provider ():
- Implements OAuth 2.0 authorization code flow
- Handles token exchange and refresh
- Validates credentials by testing Snowflake connection
Tool ():
- Executes SQL queries using OAuth token
- Supports multiple SQL types (SELECT, INSERT, UPDATE, etc.)
- Formats results as Markdown tables and JSON
- Handles errors gracefully with detailed messages
License
Apache License 2.0
This plugin uses the following open-source libraries: