All skills
dbt-labs avatar

/creating-mermaid-dbt-dag

@9d91941 official
by dbt Labsdbt-labs/dbt-agent-skills729 stars
62

Generates a Mermaid flowchart diagram of dbt model lineage using MCP tools, manifest.json, or direct code parsing as fallbacks. Use when visualizing dbt model lineage and dependencies as a Mermaid diagram in markdown format.

Use this Skill: https://skilld.dev/gh/dbt-labs/dbt-agent-skills/creating-mermaid-dbt-dag

This session only. Nothing lands on disk.

referencesusing-get-lineage.md

≈1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Using get_lineage for Lineage Retrieval

This is the fallback method when get_lineage_dev is not available. The get_lineage (or mcp__dbt__get_lineage) MCP tool reads from the production manifest in dbt Cloud.

How to use

  1. Call the get_lineage MCP tool with the model's unique_id

    • The unique_id follows the format: model.{project_name}.{model_name}
    • Must provide the full unique_id (not just the model name)
  2. The tool returns a flat list of all nodes connected to the target resource (both upstream and downstream)

  3. Each node in the list contains:

    • uniqueId: The resource's unique identifier
    • name: The resource name
    • resourceType: The type of resource (Model, Source, Seed, Snapshot, Exposure, Metric, Test, etc.)
    • parentIds: List of unique IDs that this resource directly depends on
  4. To find parents and children, traverse the graph:

    • Direct parents: Look at the parentIds field of your target node
    • Direct children: Find all nodes where your target's uniqueId appears in their parentIds list

Example usage

# Get complete lineage (all connected nodes, all types, default depth of 5)
get_lineage(unique_id="model.jaffle_shop.customers")

# Get lineage filtered to only models and sources
get_lineage(
    unique_id="model.jaffle_shop.customers",
    types=["Model", "Source"]
)

# Get only immediate neighbors (depth=1)
get_lineage(
    unique_id="model.jaffle_shop.customers",
    depth=1
)

# Get deeper lineage for comprehensive analysis
get_lineage(
    unique_id="model.jaffle_shop.customers",
    depth=10
)

Example response structure

[
  {
    "uniqueId": "source.raw.users",
    "name": "users",
    "resourceType": "Source",
    "parentIds": []
  },
  {
    "uniqueId": "model.jaffle_shop.stg_customers",
    "name": "stg_customers",
    "resourceType": "Model",
    "parentIds": ["source.raw.users"]
  },
  {
    "uniqueId": "model.jaffle_shop.customers",
    "name": "customers",
    "resourceType": "Model",
    "parentIds": ["model.jaffle_shop.stg_customers"]
  }
]

Traversing the graph

Finding upstream dependencies (parents):

# What does this node depend on?
target_node = find_node_by_id(result, "model.jaffle_shop.customers")
direct_parents = target_node["parentIds"]
# Result: ["model.jaffle_shop.stg_customers"]

Finding downstream dependents (children):

# What depends on this node?
target_id = "model.jaffle_shop.customers"
direct_children = [
    node for node in result
    if target_id in node.get("parentIds", [])
]
# Result: nodes that list "model.jaffle_shop.customers" in their parentIds

Benefits

  • ✅ Access to production lineage from dbt Cloud
  • ✅ Fast - uses GraphQL API, no need to parse large JSON files
  • ✅ Returns all nodes connected to the target (no disconnected nodes)
  • ✅ Respects depth parameter for controlling graph traversal depth
  • ✅ Can filter by resource types to reduce payload size
  • ✅ Automatically filters out macros (which have large dependency graphs)

Limitations

  • ❌ Only shows production state (not local uncommitted changes)
  • ❌ Requires dbt Cloud connection and Discovery API access
  • ❌ Must provide full unique_id (can't use just model name)
  • ❌ Does NOT include file paths (only uniqueId, name, resourceType, parentIds)

Understanding the results

  • The target node is always included in the response
  • All returned nodes are connected to the target (directly or indirectly)
  • To get full lineage, omit the types parameter
  • To reduce payload size, specify relevant types like ["Model", "Source"]
  • The depth parameter controls traversal:
    • depth=0: infinite (entire connected graph)
    • depth=1: immediate neighbors only
    • depth=5: default, goes 5 levels deep in both directions

When to use

Use this method when:

  • The get_lineage MCP tool is available
  • get_lineage_dev is NOT available
  • You want to see the production lineage (not local changes)
  • You have dbt Cloud with Discovery API enabled

Source: SKILL.md on GitHub

No alerts17d4 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    This skill provides a secure and structured way to visualize dbt model lineage using Mermaid diagrams. It follows security best practices by including explicit instructions to treat all project-related files as untrusted content, preventing potential prompt injection from data files.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 9d91941. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated 5 months ago
What it can do
Reads files Runs commands
MCP servers
dbt
user-invocable
false
metadata
{
  "author": "dbt-labs"
}
All 6 allowed tools
mcp__dbt__get_lineage_devmcp__dbt__get_lineageReadGlobGrepBash(jq *)
  • MCP
  • dbt
  • mermaid
  • lineage
  • dag
  • visualization
  • manifest

README badge

README badge for dbt-labs/dbt-agent-skills/creating-mermaid-dbt-dag

Generates a Mermaid flowchart diagram of dbt model lineage and dependencies, using MCP tools, manifest.json, or code parsing as fallbacks. Targets visualization of dbt DAG structure in markdown format with color-coded node types.

Generated from the current SKILL.md.

Does this skill require dbt Cloud or does it work with local dbt projects?
It works with both. The skill tries get_lineage_dev first for local lineage, falls back to get_lineage for dbt Cloud production lineage, then parses manifest.json or code directly if MCP tools aren't available.
Can I include tests in the lineage diagram?
Yes. The skill asks the user whether to include tests in the diagram and will represent them as yellow nodes if included.
What happens if the manifest.json file is too large?
The skill skips manifest parsing and falls back to direct code parsing, which provides best-effort incomplete lineage by analyzing SQL and YAML files directly.
Does this skill color nodes by resource type?
Yes. Nodes are colored by type: sources (blue), staging models (bronze), intermediate models (silver), marts (gold), seeds (green), exposures (orange), and tests (yellow).

Generated from the current SKILL.md. These answers refresh after source changes.