Cost Report
Requirements
Agent: any (read-only analysis)
Tools used: sql_execute, sql_analyze, finops_analyze_credits, finops_expensive_queries, finops_warehouse_advice, finops_unused_resources, finops_query_history
Analyze Snowflake warehouse query costs, identify the most expensive queries, detect anti-patterns, and recommend optimizations.
Workflow
Query SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY for the top 20 most expensive queries by credits used:
SELECT
query_id,
query_text,
user_name,
warehouse_name,
query_type,
credits_used_cloud_services,
bytes_scanned,
rows_produced,
total_elapsed_time,
execution_status,
start_time
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
WHERE start_time >= DATEADD('day', -30, CURRENT_TIMESTAMP())
AND execution_status = 'SUCCESS'
AND credits_used_cloud_services > 0
ORDER BY credits_used_cloud_services DESC
LIMIT 20;
Use sql_execute to run this query against the connected Snowflake warehouse.
Group and summarize the results by:
- User: Which users are driving the most cost?
- Warehouse: Which warehouses consume the most credits?
- Query type: SELECT vs INSERT vs CREATE TABLE AS SELECT vs MERGE, etc.
Present each grouping as a markdown table.
Analyze the top offenders - For each of the top 10 most expensive queries:
- Run
sql_analyze on the query text to detect anti-patterns (SELECT *, missing LIMIT, cartesian products, correlated subqueries, etc.)
- Summarize anti-patterns found and their severity
Classify each query into a cost tier:
| Tier |
Credits |
Label |
Action |
| 1 |
< $0.01 |
Cheap |
No action needed |
| 2 |
$0.01 - $1.00 |
Moderate |
Review if frequent |
| 3 |
$1.00 - $100.00 |
Expensive |
Optimize or review warehouse sizing |
| 4 |
> $100.00 |
Dangerous |
Immediate review required |
Warehouse analysis - Run finops_warehouse_advice to check if warehouses used by the top offenders are right-sized.
Unused resource detection - Run finops_unused_resources to find:
- Stale tables: Tables not accessed in the last 30+ days (candidates for archival/drop)
- Idle warehouses: Warehouses with no query activity (candidates for suspension/removal)
Include findings in the report under a "Waste Detection" section.
Query history enrichment - Run finops_query_history to fetch recent execution patterns:
- Identify frequently-run expensive queries (high frequency × high cost = top optimization target)
- Find queries that could benefit from result caching or materialization
Output the final report as a structured markdown document:
# Snowflake Cost Report (Last 30 Days)
## Summary
- Total credits consumed: X
- Number of unique queries: Y
- Most expensive query: Z credits
## Cost by User
| User | Total Credits | Query Count | Avg Credits/Query |
|------|--------------|-------------|-------------------|
## Cost by Warehouse
| Warehouse | Total Credits | Query Count | Avg Credits/Query |
|-----------|--------------|-------------|-------------------|
## Cost by Query Type
| Query Type | Total Credits | Query Count | Avg Credits/Query |
|------------|--------------|-------------|-------------------|
## Top 10 Expensive Queries (Detailed Analysis)
### Query 1 (X credits) - DANGEROUS
**User:** user_name | **Warehouse:** wh_name | **Type:** SELECT
**Anti-patterns found:**
- SELECT_STAR (warning): Query uses SELECT * ...
- MISSING_LIMIT (info): ...
**Optimization suggestions:**
1. Select only needed columns
2. Add LIMIT clause
3. Consider partitioning strategy
**Cost tier:** Tier 1 (based on credits used)
...
## Waste Detection
### Unused Tables
| Table | Last Accessed | Size | Recommendation |
|-------|--------------|------|----------------|
### Idle Warehouses
| Warehouse | Last Query | Size | Recommendation |
|-----------|-----------|------|----------------|
## Recommendations
1. Top priority optimizations
2. Warehouse sizing suggestions
3. Unused resource cleanup
4. Scheduling recommendations
Usage
The user invokes this skill with:
/cost-report -- Analyze the last 30 days
/cost-report 7 -- Analyze the last 7 days (adjust the DATEADD interval)
Use the tools: sql_execute, sql_analyze, finops_analyze_credits, finops_expensive_queries, finops_warehouse_advice, finops_unused_resources, finops_query_history.
1---2name: cost-report3description: Analyze Snowflake query costs and identify optimization opportunities4---56# Cost Report78## Requirements9**Agent:** any (read-only analysis)10**Tools used:** sql_execute, sql_analyze, finops_analyze_credits, finops_expensive_queries, finops_warehouse_advice, finops_unused_resources, finops_query_history1112Analyze Snowflake warehouse query costs, identify the most expensive queries, detect anti-patterns, and recommend optimizations.1314## Workflow15161. **Query SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY** for the top 20 most expensive queries by credits used:1718 ```sql19 SELECT20 query_id,21 query_text,22 user_name,23 warehouse_name,24 query_type,25 credits_used_cloud_services,26 bytes_scanned,27 rows_produced,28 total_elapsed_time,29 execution_status,30 start_time31 FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY32 WHERE start_time >= DATEADD('day', -30, CURRENT_TIMESTAMP())33 AND execution_status = 'SUCCESS'34 AND credits_used_cloud_services > 035 ORDER BY credits_used_cloud_services DESC36 LIMIT 20;37 ```3839 Use `sql_execute` to run this query against the connected Snowflake warehouse.40412. **Group and summarize** the results by:42 - **User**: Which users are driving the most cost?43 - **Warehouse**: Which warehouses consume the most credits?44 - **Query type**: SELECT vs INSERT vs CREATE TABLE AS SELECT vs MERGE, etc.4546 Present each grouping as a markdown table.47483. **Analyze the top offenders** - For each of the top 10 most expensive queries:49 - Run `sql_analyze` on the query text to detect anti-patterns (SELECT *, missing LIMIT, cartesian products, correlated subqueries, etc.)50 - Summarize anti-patterns found and their severity51524. **Classify each query into a cost tier**:5354 | Tier | Credits | Label | Action |55 |------|---------|-------|--------|56 | 1 | < $0.01 | Cheap | No action needed |57 | 2 | $0.01 - $1.00 | Moderate | Review if frequent |58 | 3 | $1.00 - $100.00 | Expensive | Optimize or review warehouse sizing |59 | 4 | > $100.00 | Dangerous | Immediate review required |60615. **Warehouse analysis** - Run `finops_warehouse_advice` to check if warehouses used by the top offenders are right-sized.62636. **Unused resource detection** - Run `finops_unused_resources` to find:64 - **Stale tables**: Tables not accessed in the last 30+ days (candidates for archival/drop)65 - **Idle warehouses**: Warehouses with no query activity (candidates for suspension/removal)6667 Include findings in the report under a "Waste Detection" section.68697. **Query history enrichment** - Run `finops_query_history` to fetch recent execution patterns:70 - Identify frequently-run expensive queries (high frequency × high cost = top optimization target)71 - Find queries that could benefit from result caching or materialization72738. **Output the final report** as a structured markdown document:7475 ```76 # Snowflake Cost Report (Last 30 Days)7778 ## Summary79 - Total credits consumed: X80 - Number of unique queries: Y81 - Most expensive query: Z credits8283 ## Cost by User84 | User | Total Credits | Query Count | Avg Credits/Query |85 |------|--------------|-------------|-------------------|8687 ## Cost by Warehouse88 | Warehouse | Total Credits | Query Count | Avg Credits/Query |89 |-----------|--------------|-------------|-------------------|9091 ## Cost by Query Type92 | Query Type | Total Credits | Query Count | Avg Credits/Query |93 |------------|--------------|-------------|-------------------|9495 ## Top 10 Expensive Queries (Detailed Analysis)9697 ### Query 1 (X credits) - DANGEROUS98 **User:** user_name | **Warehouse:** wh_name | **Type:** SELECT99 **Anti-patterns found:**100 - SELECT_STAR (warning): Query uses SELECT * ...101 - MISSING_LIMIT (info): ...102103 **Optimization suggestions:**104 1. Select only needed columns105 2. Add LIMIT clause106 3. Consider partitioning strategy107108 **Cost tier:** Tier 1 (based on credits used)109110 ...111112 ## Waste Detection113 ### Unused Tables114 | Table | Last Accessed | Size | Recommendation |115 |-------|--------------|------|----------------|116117 ### Idle Warehouses118 | Warehouse | Last Query | Size | Recommendation |119 |-----------|-----------|------|----------------|120121 ## Recommendations122 1. Top priority optimizations123 2. Warehouse sizing suggestions124 3. Unused resource cleanup125 4. Scheduling recommendations126 ```127128## Usage129130The user invokes this skill with:131- `/cost-report` -- Analyze the last 30 days132- `/cost-report 7` -- Analyze the last 7 days (adjust the DATEADD interval)133134Use the tools: `sql_execute`, `sql_analyze`, `finops_analyze_credits`, `finops_expensive_queries`, `finops_warehouse_advice`, `finops_unused_resources`, `finops_query_history`.