Skip to main content
skill CX Codex

answering-natural-language-questions-with-dbt — Claude Code skill

Answers business questions about metrics and data: checks the dbt Semantic Layer first, then writes and runs SQL. Useful when you want numbers, not model work.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add dbt-labs/dbt-agent-skills --skill answering-natural-language-questions-with-dbt -a claude-code
Open on GitHub

What answering-natural-language-questions-with-dbt does

The skill takes a question like "what were total sales last quarter" and walks four levels. First the Semantic Layer: list_metrics, get_dimensions, query_metrics. If the metric exists but a dimension is missing or you need a custom filter, it pulls the compiled SQL with get_metrics_compiled_sql, edits it and runs it through execute_sql.

With no Semantic Layer it moves to model discovery: get_mart_models, get_model_details, then SQL written against {{ ref('model_name') }} and executed via show --inline or execute_sql. If there is no MCP server but you are inside a dbt project, it reads target/manifest.json and target/catalog.json and tells you to filter them with jq because the files get large. It cannot run the query in that case — no warehouse access, so you execute the SQL yourself.

The skill is not for development. Validating model logic, dbt test, dbt build and editing models are out of scope. After answering it may suggest a semantic layer change when a metric or dimension was missing, but it stays away from warehouse schema and ETL.

What it helps with

  • get last quarter's sales total without opening a BI tool
  • find the right metric in the dbt Semantic Layer
  • add a missing dimension to an existing metric
  • read mart model schemas and write SQL against them
  • pull column lists out of target/catalog.json

Example prompts for the agent

  • How many active customers do we have right now?
  • Show me revenue by region
  • Which customers drove the most revenue last month?

How to install answering-natural-language-questions-with-dbt

1Skills CLI (Vercel)

npx skills add dbt-labs/dbt-agent-skills --skill answering-natural-language-questions-with-dbt -a claude-code

2Manually: put the files in place

~/.claude/skills/answering-natural-language-questions-with-dbt/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/answering-natural-language-questions-with-dbt/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about answering-natural-language-questions-with-dbt

How do I install answering-natural-language-questions-with-dbt in Claude?

Run npx skills add dbt-labs/dbt-agent-skills --skill answering-natural-language-questions-with-dbt -a claude-code. The skill file then lives at ~/.claude/skills/answering-natural-language-questions-with-dbt/SKILL.md.

What does answering-natural-language-questions-with-dbt do?

It answers questions about metrics and data: looks up a metric in the dbt Semantic Layer, modifies compiled SQL when needed, or writes SQL against mart models and executes it.

Is this skill meant for dbt model development?

No. It does not validate model logic, run tests or build models. It handles data questions only.

Source text

SKILL.md · Apache-2.0
---
name: answering-natural-language-questions-with-dbt
description: Writes and executes SQL queries against the data warehouse using dbt's Semantic Layer or ad-hoc SQL to answer business questions. Use when a user asks about analytics, metrics, KPIs, or data (e.g., "What were total sales last quarter?", "Show me top customers by revenue"). NOT for validating, testing, or building dbt models during development.
user-invocable: false
metadata:
  author: dbt-labs
---

# Answering Natural Language Questions with dbt

## Overview

Answer data questions using the best available method: semantic layer first, then SQL modification, then model discovery, then manifest analysis. Always exhaust options before saying "cannot answer."

**Use for:** Business questions from users that need data answers
- "What were total sales last month?"
- "How many active customers do we have?"
- "Show me revenue by region"

**Not for:**
- Validating model logic during development
- Testing dbt models or semantic layer definitions
- Building or modifying dbt models
- `dbt run`, `dbt test`, or `dbt build` workflows

## Decision Flow

```mermaid
flowchart TD
    start([Business question received])
    check_sl{Semantic layer tools available?}
    list_metrics[list_metrics]
    metric_exists{Relevant metric exists?}
    get_dims[get_dimensions]
    sl_sufficient{SL can answer directly?}
    query_metrics[query_metrics]
    answer([Return answer])
    try_compiled[get_metrics_compiled_sql<br/>Modify SQL, execute_sql]
    check_discovery{Model discovery tools available?}
    try_discovery[get_mart_models<br/>get_model_details<br/>Write SQL, execute]
    check_manifest{In dbt project?}
    try_manifest[Analyze manifest/catalog<br/>Write SQL]
    cannot([Cannot answer])
    suggest{In dbt project?}
    improvements[Suggest semantic layer changes]
    done([Done])

    start --> check_sl
    check_sl -->|yes| list_metrics
    check_sl -->|no| check_discovery
    list_metrics --> metric_exists
    metric_exists -->|yes| get_dims
    metric_exists -->|no| check_discovery
    get_dims --> sl_sufficient
    sl_sufficient -->|yes| query_metrics
    sl_sufficient -->|no| try_compiled
    query_metrics --> answer
    try_compiled -->|success| answer
    try_compiled -->|fail| check_discovery
    check_discovery -->|yes| try_discovery
    check_discovery -->|no| check_manifest
    try_discovery -->|success| answer
    try_discovery -->|fail| check_manifest
    check_manifest -->|yes| try_manifest
    check_manifest -->|no| cannot
    try_manifest -->|SQL ready| answer
    answer --> suggest
    cannot --> done
    suggest -->|yes| improvements
    suggest -->|no| done
    improvements --> done
```

## Quick Reference

| Priority | Condition | Approach | Tools |
|----------|-----------|----------|-------|
| 1 | Semantic layer active | Query metrics directly | `list_metrics`, `get_dimensions`, `query_metrics` |
| 2 | SL active but minor modifications needed (missing dimension, custom filter, case when, different aggregation) | Modify compiled SQL | `get_metrics_compiled_sql`, then `execute_sql` |
| 3 | No SL, discovery tools active | Explore models, write SQL | `get_mart_models`, `get_model_details`, then `show`/`execute_sql` |
| 4 | No MCP, in dbt project | Analyze artifacts, write SQL | Read `target/manifest.json`, `target/catalog.json` |

## Approach 1: Semantic Layer Query

When `list_metrics` and `query_metrics` are available:

1. `list_metrics` - find relevant metric
2. `get_dimensions` - verify required dimensions exist
3. `query_metrics` - execute with appropriate filters

If semantic layer can't answer directly (missing dimension, need custom logic) → go to Approach 2.

## Approach 2: Modified Compiled SQL

When semantic layer has the metric but needs minor modifications:

- Missing dimension (join + group by)
- Custom filter not available as a dimension
- Case when logic for custom categorization
- Different aggregation than what's defined

1. `get_metrics_compiled_sql` - get the SQL that would run (returns raw SQL, not Jinja)
2. Modify SQL to add what's needed
3. `execute_sql` to run the raw SQL
4. **Always suggest** updating the semantic model if the modification would be reusable

```sql
-- Example: Adding sales_rep dimension
WITH base AS (
    -- ... compiled metric logic (already resolved to table names) ...
)
SELECT base.*, reps.sales_rep_name
FROM base
JOIN analytics.dim_sales_reps reps ON base.rep_id = reps.id
GROUP BY ...

-- Example: Custom filter
SELECT * FROM (compiled_metric_sql) WHERE region = 'EMEA'

-- Example: Case when categorization
SELECT
    CASE WHEN amount > 1000 THEN 'large' ELSE 'small' END as deal_size,
    SUM(amount)
FROM (compiled_metric_sql)
GROUP BY 1
```

**Note:** The compiled SQL contains resolved table names, not `{{ ref() }}`. Work with the raw SQL as returned.

## Approach 3: Model Discovery

When no semantic layer but `get_all_models`/`get_model_details` available:

1. `get_mart_models` - start with marts, not staging
2. `get_model_details` for relevant models - understand schema
3. Write SQL using `{{ ref('model_name') }}`
4. `show --inline "..."` or `execute_sql`

**Prefer marts over staging** - marts have business logic applied.

## Approach 4: Manifest/Catalog Analysis

When in a dbt project but no MCP server:

1. Check for `target/manifest.json` and `target/catalog.json`
2. **Filter before reading** - these files can be large

```bash
# Find mart models in manifest
jq '.nodes | to_entries | map(select(.key | startswith("model.") and contains("mart"))) | .[].value | {name: .name, schema: .schema, columns: .columns}' target/manifest.json

# Get column info from catalog
jq '.nodes["model.project_name.model_name"].columns' target/catalog.json
```

3. Write SQL based on discovered schema
4. Explain: "This SQL should run in your warehouse. I cannot execute it without database access."

## Suggesting Improvements

**When in a dbt project**, suggest semantic layer changes after answering (or when cannot answer):

| Gap | Suggestion |
|-----|------------|
| Metric doesn't exist | "Add a metric definition to your semantic model" |
| Dimension missing | "Add `dimension_name` to the dimensions list in the semantic model" |
| No semantic layer | "Consider adding a semantic layer for this data" |

**Stay at semantic layer level.** Do NOT suggest:
- Database schema changes
- ETL pipeline modifications
- "Ask your data engineering team to..."

## Rationalizations to Resist

| You're Thinking... | Reality |
|--------------------|---------|
| "Semantic layer doesn't support this exact query" | Get compiled SQL and modify it (Approach 2) |
| "No MCP tools, can't help" | Check for manifest/catalog locally |
| "User needs this quickly, skip the systematic check" | Systematic approach IS the fastest path |
| "Just write SQL, it's faster" | Semantic layer exists for a reason - use it first |
| "The dimension doesn't exist in the data" | Maybe it exists but not in semantic layer config |

## Red Flags - STOP

- Writing SQL without checking if semantic layer can answer
- Saying "cannot answer" without trying all 4 approaches
- Suggesting database-level fixes for semantic layer gaps
- Reading entire manifest.json without filtering
- Using staging models when mart models exist
- Using this to validate model correctness rather than answer business questions

## Common Mistakes

| Mistake | Fix |
|---------|-----|
| Giving up when SL can't answer directly | Get compiled SQL and modify it |
| Querying staging models | Use `get_mart_models` first |
| Reading full manifest.json | Use jq to filter |
| Suggesting ETL changes | Keep suggestions at semantic layer |
| Not checking tool availability | List available tools before choosing approach |

© dbt-labs · Apache-2.0 · dbt-labs/dbt-agent-skills

Similar skills

All skills for Data and databases →

From the same set12

fetching-dbt-docs Searches and fetches dbt Cloud, dbt Core, and Semantic Layer documentation as clean Markdown without HTML clutter. CX Codex +1 1,100installs troubleshooting-dbt-job-errors Walks an agent through a failed dbt Cloud job: run logs, git history, data checks. Useful when the error message says little or the failure comes and goes. CX Codex +1 1,000installs building-dbt-semantic-layer Guides AI agents in creating and modifying dbt Semantic Layer components, including metrics, entities, and time spines for MetricFlow across dbt Core versions. CX Codex +1 1,000installs configuring-dbt-mcp-server This skill writes the JSON config for a dbt MCP server, sorts out authentication, and checks that the connection actually works. CX Codex +1 1,000installs working-with-dbt-mesh Evaluates blast radius when modifying dbt models and sets up model versioning, contracts, and cross-project dbt Mesh references. CX Codex +1 869installs using-dbt-state A skill that teaches the agent how dbt State decides to skip, clone or rebuild a node. Useful when models rebuild for no clear reason. CX Codex +1 554installs creating-mermaid-dbt-dag Turns dbt model lineage into a Mermaid flowchart with parents, children and a colour legend by resource type. Handy when the graph has to live in markdown. CX Codex +1 527installs migrating-dbt-project-across-platforms Guides dbt project migrations across data platforms using dbt Fusion real-time compilation. Catches SQL dialect issues early and verifies logic using unit tests. CX Codex +1 526installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor