Command-line interface for managing dbt projects and integrating with Lightdash
Validate Lightdash projects by running validation jobs on tables, charts, and dashboards.
Runs validation jobs to check the integrity of tables, charts, and dashboards in a Lightdash project.
lightdash validate [options]Inherits all compilation options (see dbt Compilation), plus:
Validation Options:
--project <project uuid> - Project UUID to validate (overrides active project)--preview - Validate last preview project (default: false)--only <elems...> - Specify elements to validate (multiple values allowed)
tables, charts, dashboards (from ValidationTarget enum in @lightdash/common)--use-dbt-list [true|false] - Use dbt list instead of dbt compile to generate dbt manifest.json (default: true)Usage Examples:
# Validate all elements in active project
lightdash validate
# Validate specific project by UUID
lightdash validate --project abc-123-def-456
# Validate last preview project
lightdash validate --preview
# Validate only tables
lightdash validate --only tables
# Validate tables and charts (not dashboards)
lightdash validate --only tables charts
# Validate only dashboards
lightdash validate --only dashboards
# Validate with model selection
lightdash validate --select customers orders
# Validate with verbose output
lightdash validate --verbose
# CI/CD: Validate preview in pipeline
export CI=true
lightdash validate --preview --only tables chartsValidates table/model definitions and explores:
lightdash validate --only tablesChecks:
Common Issues Detected:
Example Output:
Validating tables...
✓ customers - 15 fields validated
✓ orders - 12 fields validated
✗ payments - Error: Invalid field reference 'amount_cents'Validates saved charts in the project:
lightdash validate --only chartsChecks:
Common Issues Detected:
Example Output:
Validating charts...
✓ Monthly Revenue - Valid
✓ Customer Segmentation - Valid
✗ Order Analysis - Error: Field 'orders.total_amount' not found
✗ Sales Dashboard Chart - Error: Invalid filter on 'status'Validates dashboards and their tiles:
lightdash validate --only dashboardsChecks:
Common Issues Detected:
Example Output:
Validating dashboards...
✓ Executive Dashboard - 8 tiles validated
✗ Sales Overview - Error: Chart 'regional-sales' not found
✓ Marketing Metrics - 5 tiles validatedIf validation includes tables:
--skip-dbt-compile)--skip-warehouse-catalog)Lightdash server:
lightdash validateValidates:
Use when:
# Only tables
lightdash validate --only tables
# Only charts
lightdash validate --only charts
# Only dashboards
lightdash validate --only dashboards
# Multiple targets
lightdash validate --only tables chartsUse when:
# Validates project from config
lightdash validateUses project from:
--project option (highest priority)LIGHTDASH_PROJECT environment variable# Validate by UUID
lightdash validate --project abc-123-def-456Use when:
# Validate last preview
lightdash validate --previewUses preview project from:
preview or start-preview commandpreviewProjectUse when:
Validation inherits all compilation options:
# Validate specific models
lightdash validate --select customers orders
# Validate with tag
lightdash validate --select tag:production
# Validate excluding models
lightdash validate --exclude test_*
# Validate using predefined dbt selector
lightdash validate --selector my_selectorEffect:
# Use more threads for faster compilation
lightdash validate --threads 8
# Skip dbt version check
lightdash validate --no-version-check
# Use state directory for dbt state comparison
lightdash validate --state ./prod-state
# Use predefined dbt selector
lightdash validate --selector my_selector
# Full refresh for incremental models
lightdash validate --full-refresh# Skip warehouse catalog
lightdash validate --skip-warehouse-catalog
# Use existing manifest
lightdash validate --skip-dbt-compile
# No warehouse credentials (tables only)
lightdash validate --only tables --no-warehouse-credentialsTrade-offs:
name: Validate Lightdash
on:
pull_request:
branches: [main]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install Lightdash CLI
run: npm install -g @lightdash/cli
- name: Create Preview
env:
LIGHTDASH_API_KEY: ${{ secrets.LIGHTDASH_API_KEY }}
LIGHTDASH_PROJECT: ${{ secrets.LIGHTDASH_PROJECT }}
CI: true
run: lightdash start-preview --name pr-${{ github.event.pull_request.number }}
- name: Validate Preview
env:
LIGHTDASH_API_KEY: ${{ secrets.LIGHTDASH_API_KEY }}
CI: true
run: lightdash validate --preview --only tables charts
- name: Cleanup
if: always()
env:
LIGHTDASH_API_KEY: ${{ secrets.LIGHTDASH_API_KEY }}
CI: true
run: lightdash stop-preview --name pr-${{ github.event.pull_request.number }}#!/bin/bash
set -e
echo "Running Lightdash validation..."
# Set environment
export LIGHTDASH_API_KEY="${SECRET_TOKEN}"
export LIGHTDASH_PROJECT="${PROJECT_UUID}"
export CI=true
# Validate tables first (fast)
echo "Validating tables..."
if ! lightdash validate --only tables --no-warehouse-credentials; then
echo "Table validation failed!"
exit 1
fi
# Validate charts and dashboards
echo "Validating charts and dashboards..."
if ! lightdash validate --only charts dashboards; then
echo "Content validation failed!"
exit 1
fi
echo "All validations passed!"# Before deploying to production
lightdash compile
lightdash validate --only tables
lightdash validate --only charts dashboards
lightdash deploy# Test changes in preview
lightdash preview --name test-feature
# In another terminal:
lightdash validate --preview
# If valid, deploy to production
lightdash deploy
# Cleanup
lightdash stop-preview --name test-feature# Daily cron job to check project health
0 6 * * * lightdash validate --project prod-uuid >> /var/log/lightdash-validate.log 2>&1# After deployment, verify integrity
lightdash deploy
lightdash validate --only charts dashboardsWhen validation fails, CLI provides:
Example Error Output:
Validating tables...
✓ customers
✓ orders
✗ payments
Error: Field 'amount_cents' referenced but not defined
Validating charts...
✓ Monthly Revenue
✗ Order Analysis
Error: Field 'orders.total_amount' not found
Validating dashboards...
✓ Executive Dashboard
✗ Sales Overview
Error: Chart 'regional-sales' not found in project
Validation failed: 3 errors foundExit Code 0:
lightdash validate
echo $? # 0
# All validations passedExit Code 1:
lightdash validate
echo $? # 1
# One or more validations failedFactors affecting speed:
Typical Times:
1. Use Model Selection:
# Only validate changed models
lightdash validate --select customers2. Skip Warehouse Operations:
# Tables only, no warehouse
lightdash validate --only tables --skip-warehouse-catalog3. Validate in Stages:
# Fast table check first
lightdash validate --only tables
# Then content
if [ $? -eq 0 ]; then
lightdash validate --only charts dashboards
fi4. Use Preview for Testing:
# Validate in preview, not production
lightdash validate --previewlightdash compilelightdash validateUse both:
# Check models compile
lightdash compile
# Check content works
lightdash validateRequired permissions:
Required permissions:
Error if insufficient permissions:
ForbiddenError: You don't have permission to validate this projectError: "AuthorizationError"
lightdash loginError: "Project not found"
lightdash config set-projectError: "No preview project found"
lightdash preview or lightdash start-previewError: "Validation job timeout"
--only to validate subsets, optimize warehouseError: "Chart query failed"
Error: "Table compilation failed"
dbt compile manually, check model SQL, verify dependencies# In development workflow
git checkout -b feature-branch
# Make changes...
lightdash validate --preview# Always validate in pull requests
on: pull_request
steps:
- run: lightdash validate --preview# Pre-deployment checklist
lightdash validate
if [ $? -eq 0 ]; then
lightdash deploy
else
echo "Fix validation errors before deploying"
exit 1
fi# If changing orders model
lightdash validate --select orders# Fast table validation in CI
lightdash validate --only tables --no-warehouse-credentials
# Slower content validation on schedule
lightdash validate --only charts dashboards# Regular scheduled validation
# Alert on failures
# Track validation trends over time# Project Guidelines
## Pre-Merge Checklist
- [ ] Run `lightdash validate --preview`
- [ ] All validations pass
- [ ] No errors in tables, charts, or dashboardsValidating project: Production Analytics
Validating tables... (25 tables)
✓ All tables validated successfully
Validating charts... (87 charts)
✓ All charts validated successfully
Validating dashboards... (12 dashboards)
✓ All dashboards validated successfully
Summary:
Tables: 25 passed, 0 failed
Charts: 87 passed, 0 failed
Dashboards: 12 passed, 0 failed
Validation completed successfully!Validating project: Production Analytics
Validating tables... (25 tables)
✓ customers
✓ orders
✗ payments
Error: Field 'amount_cents' not defined
✓ products
... (21 more tables)
Validating charts... (87 charts)
✓ Monthly Revenue
✗ Payment Analysis
Error: Field 'payments.amount_cents' not found
✓ Customer Segmentation
... (84 more charts)
Validating dashboards... (12 dashboards)
✓ Executive Dashboard
✓ Sales Overview
✗ Finance Dashboard
Error: Chart 'Payment Analysis' contains errors
... (9 more dashboards)
Summary:
Tables: 24 passed, 1 failed
Charts: 86 passed, 1 failed
Dashboards: 11 passed, 1 failed
Validation failed with 3 errors# Validate frequently during development
lightdash validate --preview --only tables# Full validation before production
lightdash validate --project staging-uuid# Regular health checks
lightdash validate --project prod-uuid# Fast validation in pipelines
lightdash validate --only tables --no-warehouse-credentialsInstall with Tessl CLI
npx tessl i tessl/npm-lightdash--cli