Why a Backend Service?

Instead of letting the VS Code extension directly talk to Snowflake and Power BI, insert a small API service between them. This gives you one enforcement point instead of pushing security logic into the extension.

Request Flow
VS Code Chat Participant
    │
    ▼
Orchestration API          ← auth, validation, routing, caching, audit
    │         │
    ▼         ▼
Power BI   Snowflake

The orchestration API handles:

🔑

Auth Token Exchange

Exchange short-lived user tokens for service credentials. No raw secrets ever reach the extension.

🛡️

Query Validation

Validate every generated query against a policy engine. Block dangerous operations before they execute.

📋

Audit Logging

Log every request — who asked, what was generated, what ran, what was returned. Full traceability.

Response Caching

Cache metadata and frequent query results. Reduce latency and API call costs.

Four-Stage Pipeline

Every user question goes through four sequential stages:

Pipeline Stages
1. CLASSIFY  → Determine intent type and extract entities
2. ROUTE     → Pick data source (Power BI or Snowflake)
3. BUILD     → Construct prompt with metadata + validate output
4. EXECUTE   → Run query, format response, return to user

Stages are sequential and gated — if validation fails at stage 3, the query never reaches stage 4. The pipeline short-circuits with an explanation of what went wrong.

Intent Classification

The orchestration service classifies user questions into one of several intent types:

IntentDescriptionPreferred Source
kpi_lookupSingle KPI value (e.g., "What is current PMPM?")Power BI
kpi_trendKPI over time (e.g., "Show PMPM trend by month")Power BI
comparisonCompare segments (e.g., "PMPM by region")Power BI
explorationAd-hoc detail query (e.g., "List denied claims in Q3")Snowflake
reportGenerate/embed a full reportPower BI
exportExport data to CSV/fileEither

Prompt Building

Once the source is selected, the orchestration service constructs a targeted prompt:

Prompt Template (Power BI)DAX
SYSTEM:
You are a DAX expert. Generate a DAX EVALUATE query for the
semantic model below. Return ONLY the DAX, no explanation.

MODEL CONTEXT:
Tables: {relevant_tables}
Measures: {relevant_measures}
Business glossary: {term_definitions}

FEW-SHOT EXAMPLES:
Q: "current PMPM by LOB"
A: EVALUATE SUMMARIZECOLUMNS(...)

USER QUESTION:
{user_question}

Key principles:

  • Only include relevant metadata — not the entire model schema
  • Resolve business terms before they reach the LLM
  • Include few-shot examples to guide output format
  • Validate the generated query before execution

Execution Modes

Preview Mode (Default)

Execute with a row limit (e.g., 100 rows). Return a preview table and chart suggestion. No side effects.

Full Export

Execute the full query and export results to CSV or a Power BI embedded report URL. Requires explicit user confirmation.

Session Memory

The orchestration service maintains conversation context so follow-up questions resolve correctly:

Follow-up Resolution
Turn 1: "Show PMPM by region"
→ Executes: SUMMARIZECOLUMNS('Dim Region'[Region], "PMPM", [PMPM])

Turn 2: "Break that down by LOB"
→ Resolves "that" to previous PMPM-by-region query
→ Adds LOB dimension to the existing query

Memory is scoped to the session and automatically cleared when the chat window closes.