How we use an AI coding agent inside Snowflake to track down delays, reconcile numbers, find missing data, and write queries, and where it falls short.
If you work on a data team, you know this message:
Hey, the numbers in the report look off. Yesterday's data is missing. Can you check?
It usually lands at the worst time, and the cause could be almost anything. A pipeline might have run late, a source system might have sent partial files, or a join could be quietly dropping rows. Sometimes the data is fine and the report is filtering on the wrong date.
Investigating these issues often feels like detective work. You check load timestamps, compare row counts across layers, review task history, and gradually narrow down the root cause. It's valuable work, but a large part of it is repetitive.
That's where Snowflake Cortex Code (CoCo) has become a valuable part of my daily workflow. CoCo is an AI coding agent built into Snowflake's Snowsight interface. It isn't a generic chatbot in a browser tab. It works next to your SQL worksheets and can run queries against your account, within your role's permissions.
This post covers how I use it, what it does well, where it frustrates me, and a short note on cost.
Caption: Actual Snowflake Cortex screenshot.
Think of CoCo as a junior data engineer sitting beside you. It can handle many of the repetitive tasks involved in investigation and query development, allowing you to focus on analysis and decision-making.
The key difference from copying SQL into a general AI tool is context. CoCo can see your schema, run a query, notice that a column doesn't exist, and fix its own mistake without you pasting error messages back and forth.
My work falls into two buckets: troubleshooting data issues and writing queries. Here's what each looks like in practice.
A user reports that "Today's data hasn't arrived yet." My first question is always: Did the pipeline run late, or did the source system deliver data late?
Instead of writing the diagnostic queries from scratch, I ask CoCo something like:
Check whether the task that loads the sales fact table ran successfully today and how long it took compared to the last 7 days.
CoCo will usually query task history and return something like this:
SELECT
name,
state,
scheduled_time,
completed_time,
DATEDIFF('minute', scheduled_time, completed_time) AS duration_min,
error_message
FROM TABLE(INFORMATION_SCHEMA.TASK_HISTORY(
SCHEDULED_TIME_RANGE_START => DATEADD('day', -7, CURRENT_TIMESTAMP()),
TASK_NAME => 'MY_LOAD_TASK'
))
ORDER BY scheduled_time DESC;
Then it tells me in plain language what it found: "The task succeeded but ran three times longer than usual," or "The task failed at 06:02 with a timeout error." That summary step saves real time, especially early in the morning with an inbox full of complaints.
Of all the use cases, reconciliation is where CoCo has delivered the biggest time savings for me. A typical case is the report showing one total while the source system shows another.
I describe the two sides and ask CoCo to build a comparison:
WITH source AS (
SELECT business_date, COUNT(*) AS src_rows, SUM(amount) AS src_amount
FROM my_db.raw.transactions
WHERE business_date >= DATEADD('day', -14, CURRENT_DATE())
GROUP BY business_date
),
target AS (
SELECT business_date, COUNT(*) AS tgt_rows, SUM(amount) AS tgt_amount
FROM my_db.mart.fact_transactions
WHERE business_date >= DATEADD('day', -14, CURRENT_DATE())
GROUP BY business_date
)
SELECT
COALESCE(s.business_date, t.business_date) AS business_date,
s.src_rows, t.tgt_rows, s.src_rows - t.tgt_rows AS row_diff,
s.src_amount, t.tgt_amount, s.src_amount - t.tgt_amount AS amount_diff
FROM source s
FULL OUTER JOIN target t ON s.business_date = t.business_date
WHERE row_diff <> 0 OR amount_diff <> 0 OR row_diff IS NULL
ORDER BY business_date DESC;
This is a pattern I've written a hundred times. CoCo writes it in seconds, adapts it to the real table structures and, importantly, runs it. When a specific day shows a gap, I can follow up immediately: "Drill into that date and find which records exist in source but not in target."
Missing data is often a matter of finding the exact gap. I'll ask:
Find any dates in the last 60 days where we have no rows for a given store/region combination.
CoCo generates a date spine and anti-join, which is tedious to write by hand:
WITH dates AS (
SELECT DATEADD('day', -SEQ4(), CURRENT_DATE()) AS d
FROM TABLE(GENERATOR(ROWCOUNT => 60))
),
keys AS (
SELECT DISTINCT region_id FROM my_db.mart.dim_region
)
SELECT k.region_id, dt.d AS missing_date
FROM dates dt
CROSS JOIN keys k
LEFT JOIN my_db.mart.fact_sales f
ON f.region_id = k.region_id AND f.business_date = dt.d
WHERE f.region_id IS NULL
ORDER BY missing_date DESC, k.region_id;
Caption: Using Snowflake Cortex Code to develop and refine SQL directly within Snowsight.
Outside of incident response and troubleshooting, I also use CoCo as a query-writing partner for:
Real-Time Savings on Repetitive Investigation
Most data troubleshooting follows a few patterns: check freshness, check counts, compare layers, find the gap. CoCo handles the boilerplate so I can spend my time on the reasoning. Investigations that once required an hour of writing, testing and refining SQL can often be completed in 15-20 minutes.
It Can Execute, Evaluate and Refine
CoCo doesn't just hand over SQL and hope. It executes the query, reads the result or error and adjusts. That feedback loop is the biggest difference from a general-purpose AI assistant.
Snowflake-Native Knowledge
It knows Snowflake functions and system views (TASK_HISTORY, QUERY_HISTORY, ACCOUNT_USAGE) and idioms like QUALIFY, FLATTEN and GENERATOR. You don't have to explain what a Snowflake task is.
Particularly useful for onboarding and Unfamiliar Areas
When I'm working in a schema I don't know well, CoCo can explore the objects, describe the columns and suggest likely join keys. It's like having a guide in an unfamiliar codebase.
Natural-Language Summaries for Stakeholders
After an investigation, I often ask CoCo to "summarise the root cause in two sentences for a business user." The result is a decent first draft of the reply to whoever raised the issue.
No tool is perfect, and pretending otherwise doesn't help anyone. Here's what I've run into.
It Can Be Confidently Wrong
CoCo sometimes guesses a column meaning, assumes the wrong date field or picks a similarly named table. The SQL runs fine and the results look plausible, but the answer is wrong. Always sanity-check the logic, especially for reconciliation. A query that runs isn't necessarily correct.
Roles and Permissions Matter
CoCo works within the permissions of the role it runs under. If your role can't see a table, neither can CoCo. That's correct behaviour, but it can be confusing. A few times I switched roles in the editor and expected CoCo to follow, but the chat session was still using the original role. When results look odd, it's worth asking it to run SELECT CURRENT_ROLE();.
The Usage Limits Can Interrupt Investigations
This was my biggest frustration. CoCo usage consumes credits, and organisations can set usage limits or quotas. Several times I hit my limit in the middle of an investigation and was blocked from using CoCo until the limit reset or an admin adjusted it.
Being cut off halfway through debugging a production issue isn't fun. My lessons:
Context Isn't Unlimited
In very long conversations, CoCo may summarise earlier context and lose some detail. For complex investigations, starting a fresh, focused chat often works better.
It Doesn't Know Your Business Rules
CoCo knows SQL. It doesn't know that "net sales" in your company excludes a certain transaction type, or that one region's fiscal week starts on a different day. You have to provide that domain knowledge.
CoCo isn't free to run. Its usage is billed through Snowflake consumption, so it shows up in your organization's costs, and any queries CoCo runs also use warehouse compute, just like queries you run yourself.
Some practical points:
Rates and limits vary by agreement and change over time, so check Snowflake's official documentation and your account team for current pricing.
Like most AI tools, the quality of the output depends heavily on the quality of the prompt. These practices have helped me get the most value from CoCo while avoiding unnecessary usage.
CoCo hasn't replaced the critical thinking that data engineering and analytics require, but it has significantly reduced the effort involved in getting to an answer. Tasks that once started with writing diagnostic SQL can now begin with a conversation.
The biggest benefit isn't that CoCo writes queries. Plenty of tools can do that. The real value comes from its ability to understand your Snowflake environment, execute investigations, interpret results, and help you iterate more quickly.
Like any AI assistant, it's not infallible. It can make incorrect assumptions, misunderstand business logic, or return plausible but incorrect answers. The best results come when it's treated as a collaborator rather than an authority.
If you work with data in Snowflake and spend a lot of time answering "why is this number wrong?", CoCo is worth trying. For help with this, please contact us.