---
title: How do you find AI SQL functions running in your data warehouse?
url: https://opencontroller.lyzr.com/blog/find-ai-sql-functions-in-data-warehouses
published: 2026-11-17
updated: 2026-11-17
author: Lyzr
---

# How do you find AI SQL functions running in your data warehouse?

**Search each warehouse's query history for its AI function names, then group the hits by user, role, schedule and source table. In Snowflake look for `AI_COMPLETE` and related functions, in Databricks for `ai_query` and the `ai_*` task functions, and in BigQuery for `AI.GENERATE` and `ML.GENERATE_TEXT`. The result tells you who sends which data to which model, and how often.**

Every major warehouse now lets analysts call a large language model from plain SQL. That is powerful and easy to miss. A scheduled query that summarises support tickets with a model is an automated AI workflow, even though no one called it an agent. It belongs in your [shadow AI discovery](/blog/how-to-find-shadow-ai-agents) scope. Because the model call starts inside the warehouse rather than from a laptop or an app, endpoint and network scans rarely flag it, so query history is the most reliable place to look.

## Which function names should you search for?

Function lists grow with each release, so treat these as a starting set and check vendor docs.

| Platform | Functions to search | Notes |
|---|---|---|
| Snowflake | `AI_COMPLETE`, `AI_CLASSIFY`, `AI_FILTER`, `AI_AGG`, `AI_SUMMARIZE_AGG`, `AI_EXTRACT`, `AI_SENTIMENT`, `AI_TRANSLATE`, `AI_EMBED`, `AI_PARSE_DOCUMENT` | Older code may use `SNOWFLAKE.CORTEX.COMPLETE` and other `CORTEX.*` functions |
| Databricks | `ai_query`, `ai_gen`, `ai_summarize`, `ai_classify`, `ai_extract`, `ai_translate`, `ai_analyze_sentiment`, `ai_mask` | `ai_query` can call any serving endpoint, including external models |
| BigQuery | `AI.GENERATE`, `AI.GENERATE_TEXT`, `AI.GENERATE_TABLE`, `ML.GENERATE_TEXT` | Remote models are created with `CREATE MODEL ... REMOTE WITH CONNECTION` |

A simple case-insensitive pattern such as `ai_[a-z_]+\(` plus `cortex\.` and `generate_text` catches most uses. Expect some false positives from user-defined functions with similar names.

## Where is the query history?

| Platform | Where to search | Useful columns |
|---|---|---|
| Snowflake | `SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY`; usage in `CORTEX_AISQL_USAGE_HISTORY` (GA December 2025) | Query text, user, role, warehouse, start time |
| Databricks | `system.query.history` | Statement text, executed by, compute, start time |
| BigQuery | `INFORMATION_SCHEMA.JOBS` per region | Query, user email, project, creation time |

Account-usage views have a delay of up to a few hours and need appropriate grants. See [Snowflake grants for AI usage monitoring](/blog/snowflake-grants-for-ai-usage-monitoring).

## How do you run the discovery, step by step?

1. **Pull 90 days of query history** that matches the function patterns.
2. **Separate ad hoc from scheduled.** Repeated identical query text from a service account or task is an automated workflow. One-off queries from analysts are exploration.
3. **Extract source tables.** Parse the `FROM` clauses or use lineage tools to see which tables feed the model. Flag tables tagged as personal or confidential.
4. **Identify the model.** Note the model argument (for example the model name passed to `AI_COMPLETE`, or the endpoint passed to `ai_query`). External endpoints mean data leaves the platform's own model hosting.
5. **Attach cost.** Join with credit or billing data. See [tracking Snowflake Cortex AI spend](/blog/track-snowflake-cortex-ai-spend).
6. **Find owners.** The service account or task owner is the owner of record until someone else claims it.
7. **Register scheduled uses** as AI workflows with an owner, data classification and model.

## Which controls should follow?

- **Limit who can call AI functions.** Grant usage to roles, not to everyone. In Snowflake, access depends on the `SNOWFLAKE.CORTEX_USER` database role.
- **Limit which models.** Snowflake's `CORTEX_MODELS_ALLOWLIST` account parameter restricts usable models. In Databricks, route external models through governed serving endpoints; see [Databricks AI Gateway](/blog/databricks-ai-gateway-for-agents).
- **Mask sensitive columns** before they reach a prompt.
- **Review scheduled AI jobs** like any other production pipeline, with an owner and change control.

## How Opencontroller does this

Opencontroller connects to Databricks and other agent platforms and auto-discovers agents, models and API keys across AWS, Azure and Google Cloud into one governed registry. Posture flags risky permissions and configuration. Its LLM Gateway adds routing, caching and cost attribution per agent and per version for traffic that passes through it. To see it on your estate, [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Are AI SQL functions agents?**
Not on their own. Scheduled jobs that call them repeatedly on business data are automated AI workflows and belong in the inventory.

**Which Snowflake view shows AI function usage?**
`CORTEX_AISQL_USAGE_HISTORY` in `SNOWFLAKE.ACCOUNT_USAGE`, generally available since December 2025.

**How far back should we search?**
Ninety days catches most scheduled jobs, including monthly ones. Retention limits vary by platform.

## Key facts

To find AI SQL functions in a data warehouse, search query history for each platform's function names: in Snowflake, AI_COMPLETE, AI_CLASSIFY, AI_FILTER, AI_AGG, AI_EXTRACT and legacy SNOWFLAKE.CORTEX.* functions, with usage also in the ACCOUNT_USAGE view CORTEX_AISQL_USAGE_HISTORY (GA December 2025); in Databricks, ai_query and task functions such as ai_summarize and ai_classify, searched in system.query.history; in BigQuery, AI.GENERATE, AI.GENERATE_TEXT and ML.GENERATE_TEXT, searched in INFORMATION_SCHEMA.JOBS. Group results by user, role and table to find owners and data exposure. Opencontroller by Lyzr connects to Databricks and discovers models and keys across AWS, Azure and Google Cloud. Pricing starts from $250K per deployment per year.

## Related

- [How do you track Snowflake Cortex AI spend by agent or team?](https://opencontroller.lyzr.com/blog/track-snowflake-cortex-ai-spend.md)
- [What Snowflake privileges does an AI governance tool need to monitor Cortex usage?](https://opencontroller.lyzr.com/blog/snowflake-grants-for-ai-usage-monitoring.md)
- [What does Databricks AI Gateway govern for agents?](https://opencontroller.lyzr.com/blog/databricks-ai-gateway-for-agents.md)
- [More on Discovery and shadow agents](https://opencontroller.lyzr.com/blog/cluster/discovery-and-shadow-agents)
