dbt: Env var required but not provided
Fixes dbt's Env var required but not provided error from profiles.yml. Use when dbt debug or dbt run fails because an env_var() call in profiles.yml references an environment variable that is not set in the shell. Exports the missing variable or gives env_var a fallback default. Not for variables set correctly but misspelled in profiles.yml or for --vars CLI overrides.
dbt: Env var required but not provided
TL;DR: profiles.yml calls envvar() with a variable you never exported. Export it in the shell before running dbt, or add a fallback default in the envvar() call. Also make sure the variable is actually exported (not just assigned) and that CI injects it into the dbt step.
Env var required but not providedSteps
- Rerun with the full error; dbt names the missing variable. Note its exact spelling.
- Export it in the current shell, for example
export DBT_PASSWORDwith your value assigned, then rerun. Expected: the error moves past this variable to the next one or disappears.
- For a durable fix, add a fallback in profiles.yml:
env_var('DBT_PASSWORD', 'fallback'). Expected: dbt runs without the variable set, using the fallback.
- In CI, add the variable to the job's env block so the dbt step inherits it. Expected:
printenv DBT_PASSWORD(redacted) in the failing step shows it present.
When this applies
- the exact
Env var required but not providederror on dbt debug, dbt run, or dbt compile - profiles.yml that uses env_var() for passwords, hosts, or schemas
- CI pipelines where secrets are injected per-job
When it doesn't
- a variable that IS exported but spelled differently in profiles.yml — that's a typo, not a missing var
- dbt Cloud CLI env-var handling, which is configured in the dbt Cloud UI
- --vars values, which never touch env_var()
Compatibility
dbt Core and Fusion CLIs; profiles.yml with env_var() calls. Verified against the dbt environment-variables community guide.
Variant phrasings
- dbt env var required but not provided fix
- dbt profiles.yml env_var error
- dbt export environment variable profiles
Root cause
env_var() without a default raises at parse time when the variable is absent from the process environment. Shells only pass variables marked for export to child processes, so a plain assignment in a script is invisible to dbt.
Edge cases
- on Windows,
setdoes not persist across terminal sessions; use the system environment settings or a persistent profile - a fallback default still prints the value into logs; prefer real secret injection for passwords
- dbt Cloud CLI reads env vars from the environment settings UI, not your laptop's shell