get_column_lineage
Trace column-level lineage through SQL transformations, showing how columns flow via CTEs, joins, aggregations, and more. Supports upstream, downstream, or full bidirectional tracing.
Instructions
Trace column-level lineage through SQL transformations.
Uses sqlglot to parse compiled SQL and track how columns flow through:
CTEs and subqueries
JOINs and aggregations
Transformations (calculations, CASE statements, etc.)
Window functions
This provides detailed column-to-column dependencies that model-level lineage cannot capture.
Args: model_name: Name or unique_id of the dbt model to analyze column_name: Name of the column to trace direction: Direction to trace lineage: - "upstream": Which source columns feed into this column - "downstream": Which downstream columns use this column - "both": Full bidirectional column lineage depth: Maximum levels to traverse (None for unlimited) - depth=1: Immediate column dependencies only - depth=2: Dependencies + their dependencies - None: Full dependency tree
Returns: Column lineage information including: - Source columns this column depends on (upstream) - Downstream columns that depend on this column - Transformations and derivations - CTE transformation paths (via_ctes, transformations) - dbt resource mapping where available
Each dependency includes:
- column: Column name
- table: Source table name
- schema: Source schema (if available)
- database: Source database (if available)
- via_ctes: List of CTE names in transformation order
- transformations: Transformation details per CTE step
- cte: CTE name
- column: Column name at this step
- expression: SQL expression (truncated to 200 chars)Raises: ValueError: If model not found, column not found, or SQL parse fails RuntimeError: If sqlglot is not installed
Examples: # Find which source columns feed into revenue get_column_lineage("fct_sales", "revenue", "upstream")
# See what downstream models use customer_id
get_column_lineage("dim_customers", "customer_id", "downstream")
# Full bidirectional lineage for a column
get_column_lineage("fct_orders", "order_total", "both")Note: Requires sqlglot package. Install with: pip install sqlglot The model must be compiled (run 'dbt compile' first).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model_name | Yes | ||
| column_name | Yes | ||
| direction | No | upstream | |
| depth | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||