Data Insights Agent

Inspiration

Every organization sits on mountains of data, but getting insights still requires a specialized analyst who knows SQL, understands the schema, and can pick the right visualization. I asked: what if anyone — a nurse, a branch manager, a plant supervisor — could just describe what they're curious about and get a complete visual analysis back in seconds?

The hackathon prompt — "Use AI to uncover valuable meaning from data and create visual analyses that would be difficult or impossible to complete in five hours without AI" — aligned perfectly. A single analyst exploring three domains with rows across 40+ tables would need hours just to write the SQL, let alone chart and interpret the results.

What It Does

The Data Insights Agent is a conversational AI analyst built entirely on Snowflake. It works in three phases:

  1. Discovery — The agent interviews the user to sharpen a vague question into a specific, answerable analysis.
  2. Execution — It generates SQL, runs queries across Healthcare, Financial Services, and Auto Manufacturing, and selects the best visualization types.
  3. Narration — It renders charts and writes a plain-English summary highlighting key findings with specific numbers.

One conversation turn replaces hours of manual analyst work.

How I Built It

Architecture:

$$ \text{User Question} \xrightarrow{\text{Cortex AI}} \text{SQL Queries} \xrightarrow{\text{Snowpark}} \text{Data} \xrightarrow{\text{Vega-Lite}} \text{Charts + Narrative} $$

  • LLM Engine: Snowflake Cortex AI (SNOWFLAKE.CORTEX.COMPLETE with claude-sonnet-4-6) handles conversation, SQL generation, and insight narration — all via SQL calls, no Python SDK needed.
  • Data Layer: Snowpark via st.connection("snowflake") for query execution against 3 databases and 40+ tables with verified schemas.
  • Visualization: 15 chart types rendered through Vega-Lite (built into Streamlit) — bar, stacked bar, heatmap, scatter, pie, arc/sunburst, network graph, histogram, box plot, and more.
  • UI: Streamlit-in-Snowflake with a chat interface, suggestion pills for onboarding, and token usage tracking.
  • Zero external dependencies: No PyPI packages, no API keys, no external access integrations. Everything runs natively inside Snowflake.

Tech Stack: Python, Streamlit-in-Snowflake, Snowflake Cortex AI, Snowpark, Vega-Lite, Snowflake SQL

Challenges I Faced

1. Runtime constraints. The Streamlit-in-Snowflake container doesn't include the snowflake.cortex Python module or plotly. I pivoted to SQL-based Cortex calls:

SELECT SNOWFLAKE.CORTEX.COMPLETE(
    'claude-sonnet-4-6',
    PARSE_JSON(:messages)::ARRAY,
    OBJECT_CONSTRUCT('max_tokens', 4096)
) AS response

and replaced all Plotly charts with Vega-Lite specs — both zero-dependency approaches.

2. Schema accuracy. The LLM generated SQL with wrong column names because our initial catalog was based on metadata, not the actual tables. For example, INSURANCE_TYPE didn't exist — the real column was PRIMARY_INSURANCE. I queried every table with SELECT * LIMIT 1 to build a verified catalog.

3. Response parsing. The multi-turn COMPLETE function returns a nested JSON structure where the content lives at choices[0].messages (a string), not choices[0].message.content (an object) — a subtle difference that required careful parsing.

What I Learned

  • Snowflake Cortex AI is powerful enough to build a full agentic workflow entirely in SQL — no external LLM APIs required.
  • Constraints drive creativity: not having Plotly forced us to learn Vega-Lite, which produces lighter, faster charts with no dependency overhead.

What's Next

  • Semantic Views + Cortex Agent: Register as a proper Cortex Agent with semantic views, making it available through Snowflake CoWork for the entire organization.
  • Conversational memory: Let users say "now break that down by region" without restating context.
  • Automated reporting: Schedule recurring analyses delivered via email or Slack.
  • Self-improving catalog: Learn from successful and failed queries to refine schema understanding over time. ```

This is ready to paste directly into a hackathon submission form that supports Markdown and LaTeX.

Built With

  • cortexai
  • python
  • snowflake
  • snowflake-sql
  • streamlit
Share this project:

Updates

Submission history