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.

referencesparsing-code-directly.md

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

Parsing Code Directly for Lineage Retrieval

This is the last resort method when all other approaches fail (no MCP tools available, manifest.json too large or missing). Directly parse the model's SQL/Python code to extract dependencies.

How to use

  1. Locate the model file:

    • Use Glob to find the model file: models/**/{model_name}.sql or models/**/{model_name}.py
    • Check common locations: models/staging/, models/marts/, etc.
  2. Read the model file and extract dependencies:

    For SQL models:

    • Look for {{ ref('model_name') }} calls - these are model dependencies
    • Look for {{ source('source_name', 'table_name') }} calls - these are source dependencies
    • Parse both single and double quoted strings

    For Python models:

    • Look for dbt.ref('model_name') calls - these are model dependencies
    • Look for dbt.source('source_name', 'table_name') calls - these are source dependencies
  3. Find downstream dependencies (children):

    • Use Grep to search for references to this model in other files
    • Search for {{ ref('current_model_name') }} across the project
    • Search in common model directories: models/staging/, models/intermediate/, models/marts/
  4. Determine node types (best effort):

    • Models: Files in models/ directory with .sql or .py extension
    • Sources: References found in {{ source() }} calls (you may need to check models/sources.yml or similar)
    • Seeds: Files in seeds/ directory with .csv extension
    • Exposures: Check models/**/*.yml for exposure definitions
  5. Build limited lineage graph:

    • Only direct parents (1 level up) and children (1 level down) may be available
    • File paths can be constructed from found references

Example search patterns

Use the Grep tool (not bash grep) and Glob tool (not bash find) for all searches:

  • Find all refs to a model: Grep for ref('customers') in models/
  • Find all source calls: Grep for source( in models/staging/
  • Find a model file: Glob pattern models/**/{model_name}.sql

Benefits

  • ✅ Always works as long as you have file access
  • ✅ Doesn't require manifest or MCP tools
  • ✅ Can handle very large projects
  • ✅ Shows current state of code (including uncommitted changes)

Limitations

  • ❌ Labor intensive - requires multiple file reads and searches
  • ❌ May miss indirect dependencies
  • ❌ Limited to immediate parents/children (1 level deep)
  • ❌ Cannot easily determine full graph depth
  • ❌ May not capture all node types (tests, snapshots, etc.)
  • ❌ Doesn't capture metadata like column lineage
  • ❌ Won't catch dynamic references

When to use

Use this method only when:

  • All MCP lineage tools are unavailable
  • manifest.json is too large (>10MB) or doesn't exist
  • You just need a basic lineage view
  • You're willing to accept incomplete lineage information

Important notes

⚠️ This method provides best-effort lineage and may be incomplete. If possible, try to:

  1. Generate a fresh manifest with dbt parse and use the manifest.json method instead
  2. Enable the dbt MCP server to use the tool-based approaches
  3. Warn the user that the lineage may be incomplete

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.