Go To Top

← Back to Recent Systems

03 Independent build · 2026

Multi-Agent Customer Intelligence on Snowflake

Not every routing decision deserves an LLM call. I built a LangGraph supervisor over three Snowflake specialist agents combining Cortex Analyst text-to-SQL on governed Semantic Views with parameterized SQL, driven by a deterministic Python planner, two-way trace-to-query correlation between LangSmith and Snowflake, and offline evals with TruLens recording.

snowflakecortex-analystsemantic-viewslanggraphlangsmithtrulenssqlpython

Enterprise leadership rarely asks single-table questions. They ask things like: “Find customers complaining about API issues and analyze their churn rate and monthly revenue.” Answering that cleanly means crossing support tickets, customer behavior, and financial segmentation without letting an LLM invent its own churn or lifetime-value formula on the fly.

I built a hub-and-spoke LangGraph StateGraph over Snowflake (CUSTOMERS, USAGE_EVENTS, SUPPORT_TICKETS, and CHURN_EVENTS) that splits the work across three domain specialists sharing one typed state contract:

  • Support tickets specialist: runs parameterized Snowflake SQL against SUPPORT_TICKETS for keyword/customer matching, CSAT averages, priority breakdowns, and categories.
  • Behavior analyst specialist: calls Snowflake’s live Cortex Analyst REST API against a governed CUSTOMER_BEHAVIOR_ANALYST Semantic View for usage, engagement, and churn.
  • Strategic research specialist: calls Cortex Analyst against a governed STRATEGIC_RESEARCH_ANALYST Semantic View for MRR, customer lifetime, industry segmentation, and lost revenue.

Why a deterministic planner instead of LLM routing

The supervisor plans the route once in deterministic Python rather than asking an LLM router to guess which specialist comes next, routing step by step through LangGraph Command(goto=...) and falling back to the behavior analyst with a planner_fallback tag when no specialist rule matches.

That trade-off came straight out of real platform constraints (a Snowflake trial account blocks AI_COMPLETE, Cortex Search embeddings, and the Cortex Agent :run endpoint while allowing Semantic Views and Cortex Analyst REST text-to-SQL) — and it turned out to be better engineering anyway. The LLM runs only where it earns its cost (translating English into SQL over governed views), while routing costs zero tokens, stays repeatable, and is covered by an offline unit-test suite. For full Cortex accounts, a feature flag (SNOWFLAKE_USE_CORTEX_AGENTS=true) keeps the swap path ready for Snowflake-managed Cortex Agents on the same graph.

Why Semantic Views earn their keep

During evaluation, asking “What is the average customer lifetime value by industry?” initially failed — and that failure was a good thing. Cortex Analyst refused to guess a formula because CLV had no governed definition yet. Defining CUSTOMER_LIFETIME_VALUE once inside Snowflake’s Semantic View fixed it for every downstream agent: the formula lives under Snowflake governance instead of buried inside a prompt, and the eval suite caught the missing definition before a stakeholder ever saw a made-up number.

Two-way observability: LangSmith meets Snowflake

Most agent demos stop at the orchestrator trace. Here, every run correlates cleanly across both systems:

  • LangSmith side: @traceable spans wrap Cortex Analyst text-to-SQL (llm), ticket search (retriever), and SQL execution (tool), logging the Snowflake query ID (sfqid), Cortex Analyst request_id, row counts, SQL latency, and deterministic feedback scores (execution_success, non_empty_results, zero_errors, step_count).
  • Snowflake side: every SQL statement carries a structured JSON QUERY_TAG (app, trace_id, agent, step, tool), surfaced in AGENT_OBSERVABILITY_LOGS so a data platform team can inspect SQL duration and row counts per agent step directly inside Snowsight by LangSmith trace ID.

Catching silent bugs with evals and traces

I paired the graph with a 12-question offline LangSmith evaluation suite (route_match, sql_executed_with_rows, eval_zero_errors) and TruLens TruGraph OpenTelemetry recording. Even more useful was inspecting live traces on questions that technically “succeeded”: an intentionally loose OR keyword search for urgent API tickets returned zero errors and plenty of rows — including a password-reset ticket that happened to contain the word “urgently.” No error alert would ever fire on that; reading the SQL span in the trace is what exposed it and showed what evaluator to build next.

← Back to Recent Systems