Noah Holm
10/22/2025, 11:24 AMdbt source freshess with PrefectDbtRunner like this PrefectDbtRunner.invoke(["source", "freshness"]) but getting an error. Other commands like build works fine. How do I invoke this command?
Task run encountered an exception ValueError: Failed to invoke dbt command 'sourcefreshness': Runtime Error\n No dbt_project.yml found at expected pathMarvin
10/22/2025, 11:24 AMMarvin
10/22/2025, 11:30 AMinvoke(["source", "freshness"]) syntax is correct. The error you’re seeing is coming from dbt, not Prefect: dbt can’t find a dbt_project.yml in the working directory. That’s why build may work for you (depending on how your runner is initialized), but source freshness fails.
Ways to fix it:
- Run from your dbt project directory (or set DBT_PROJECT_DIR)
- Pass the project (and profiles) directories as flags in your invoke call
- Configure the runner with PrefectDbtSettings that specify the project/profiles dirs
Examples:
1) Pass flags inline
runner = PrefectDbtRunner(...)
runner.invoke([
"source", "freshness",
"--project-dir", "/path/to/your/dbt_project",
"--profiles-dir", "/path/to/your/.dbt"
])
2) Configure once via settings
from prefect_dbt import PrefectDbtRunner, PrefectDbtSettings
settings = PrefectDbtSettings(
project_dir="/path/to/your/dbt_project",
profiles_dir="/path/to/your/.dbt",
)
runner = PrefectDbtRunner(settings=settings)
runner.invoke(["source", "freshness"])
Notes:
- The 'sourcefreshness' you see in the error string is just how the error message is formatted — dbt still expects two tokens (source and freshness) and your call is correct.
- You can also set DBT_PROJECT_DIR and/or DBT_PROFILES_DIR in your environment if you prefer not to pass flags.
If you’d rather use the helper task, Prefect also exposes:
from prefect_dbt.cli.commands import run_dbt_source_freshness
await run_dbt_source_freshness(
project_dir="/path/to/your/dbt_project",
profiles_dir="/path/to/your/.dbt"
)
Docs for the Prefect dbt integration: Prefect dbt integration docs
If this still fails, can you share:
- How you’re constructing PrefectDbtRunner (are you passing a manifest?)
- Where dbt_project.yml lives at runtime (container path, working dir, etc.)
- Whether you have DBT_PROJECT_DIR or DBT_PROFILES_DIR set in the environment?Noah Holm
10/22/2025, 11:33 AMsettings = PrefectDbtSettings(profiles_dir="/some/path", project_dir="/some/path")
runner = PrefectDbtRunner(settings=settings)
runner.invoke(["source", "freshness"])Marvin
10/22/2025, 11:33 AMMarvin
10/22/2025, 11:34 AM'sourcefreshness' you see is just how the error message is concatenated; dbt still expects two tokens ("source", "freshness").
Given you’re already passing PrefectDbtSettings, this looks like the `project_dir`/`profiles_dir` from settings aren’t being picked up for this specific subcommand. Two reliable workarounds:
- Pass the dirs as flags in the invoke call (putting global flags before the subcommand tends to be most robust):
runner.invoke([
"--project-dir", "/some/path",
"--profiles-dir", "/some/path",
"source", "freshness",
])
If that doesn’t work in your environment, try flags after the subcommand:
runner.invoke([
"source", "freshness",
"--project-dir", "/some/path",
"--profiles-dir", "/some/path",
])
- Use the helper task which wires this up for you:
from prefect_dbt.cli.commands import run_dbt_source_freshness
await run_dbt_source_freshness(
project_dir="/some/path",
profiles_dir="/some/path",
)
If you still see the same error:
- What versions of prefect-dbt and dbt-core are you running?
- Can you confirm that /some/path/dbt_project.yml exists inside the runtime environment (e.g., container path)?
- Please try print(runner.settings) right before invoke to confirm the values at runtime.
Docs for reference: Prefect dbt integration docsNoah Holm
10/22/2025, 1:04 PM