# spendguard

> Cost estimation and budget governance for AI agents using BigQuery, Snowflake, and Databricks.

spendguard is a free AI agent skill on Agensi by Tanveer Rajput, in Data & Databases. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [Tanveer Rajput](https://www.agensi.io/creators/tanveer-rajput)
- Category: [Data & Databases](https://www.agensi.io/skills/data-databases)
- Uses: 2
- Version: 1.0
- Last updated: 2026-10-12
- Security: scan passed (2026-10-12); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/spendguard
- Tags: api, database, llm-ops, bigquery, snowflake, sql

## About this skill

Uncontrolled AI agents with SQL access can quickly drain cloud budgets by executing inefficient queries on massive datasets. spendguard acts as a governance layer between your agent and your data warehouse, preventing accidental overspend before it happens. It provides precise cost estimation for BigQuery and heuristic bounds for Snowflake and Databricks, ensuring agents stay within defined financial guardrails.

### What it does
- **Pre-flight estimation** provides a dollar-cost preview of SQL queries without executing them.
- **Budget enforcement** blocks query execution automatically if the estimated cost exceeds a per-call USD cap.
- **Cost reconciliation** tracks actual billed costs in a local ledger to maintain a verifiable source of truth.
- **Query optimization** generates cheaper SQL alternatives by injecting limits, pruning columns, and applying partition filters.
- **Spend reporting** analyzes total engine spend and evaluates the accuracy of previous estimations.

### How it works
1. **Estimate** calls `estimate_query_cost` to check the price and accuracy tier of a specific SQL statement.
2. **Gate** executes queries via `run_query_bounded` to enforce strict USD limits before the warehouse is hit.
3. **Rewrite** uses `suggest_cheaper_query` to fix queries that were blocked for being too expensive.
4. **Report** pulls the `spend_report` to audit usage and calibrate future spending expectations.

### Frameworks & tools
This skill is delivered as an MCP server compatible with Claude Code, Cursor, and GitHub Copilot. It supports Google BigQuery, Snowflake, and Databricks via `uvx spendguard-mcp`.

### Why this beats prompting it yourself
LLMs cannot natively calculate cloud billing rates or scan table metadata to predict costs accurately. This skill uses the warehouse's own dry-run APIs and metadata to provide hard numbers that a system prompt alone would simply hallucinate.

### Use cases
- Prevent agents from running `SELECT *` on multi-terabyte BigQuery tables.
- Enforce daily or per-query spend limits for automated analytics agents.
- Audit agent-driven warehouse spend across multi-cloud environments.
- Automatically optimize expensive SQL generated by non-technical agents.

### Known limitations
Estimates for Snowflake and Databricks use upper-bound heuristics rather than the precise dry-runs available in BigQuery. Actual billed costs are only available after query completion.

## Requires

- Spendguard MCP
- uv (Python tool runner)

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the spendguard skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### How does spendguard prevent AI agents from draining my cloud budget?

spendguard acts as a financial firewall between your AI agents and your data warehouse, preventing runaway costs by estimating query prices and blocking executions that exceed your set USD budget before they hit the warehouse.

### Which AI agents and IDEs are compatible with spendguard?

The skill is delivered as an MCP server, making it natively compatible with popular AI development tools including Claude Code, Cursor, and GitHub Copilot.

### Does spendguard provide the same level of cost accuracy across all supported warehouses?

While it provides precise dry-run costs for BigQuery, it uses sophisticated upper-bound heuristics for Snowflake and Databricks to ensure your agents never exceed safe spending limits.

### What is required to install and configure the skill?

Setup is streamlined via `uvx spendguard-mcp`; you simply need to provide your warehouse credentials and set your desired USD limits to begin governing your agent's SQL execution.

### Why should I use this skill instead of just prompting my agent to be cost-conscious?

Unlike static system prompts, spendguard uses real-time warehouse metadata and billing APIs to provide factual cost data, eliminating the "hallucinated" estimates common with LLMs.

### What happens if an agent's query is blocked for exceeding the budget?

If a query is blocked for being too expensive, the `suggest_cheaper_query` function analyzes the SQL to inject limits, prune columns, or add filters to bring the cost within your budget.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
