Ricardo Ibarra
08/28/2025, 4:56 AMfrom prefect_dbt.cli.commands import DbtCliProfile
File "/opt/anaconda3/lib/python3.12/site-packages/prefect_dbt/__init__.py", line 3, in <module>
from .cloud import DbtCloudCredentials # noqa
raise PydanticUserError(
pydantic.errors.PydanticUserError: The `__modify_schema__` method is not supported in Pydantic v2. Use `__get_pydantic_json_schema__` instead in class `SecretStr`.
Marvin
08/28/2025, 4:56 AMMarvin
08/28/2025, 4:59 AMprefect-dbt
that was built against Pydantic v1, but your environment has Pydantic v2 (which Prefect 3.x uses). Pydantic v2 removed __modify_schema__
, so older libraries that still reference it will raise this error during import.
A couple of quick checks and fixes:
1) Check your versions
Run this to see exactly what’s installed:
python -c "import sys, prefect, prefect_dbt, pydantic; print('python', sys.version); print('prefect', prefect.__version__); print('prefect_dbt', getattr(prefect_dbt, '__version__', 'unknown')); print('pydantic', pydantic.__version__)"
2) If you’re on Prefect 3.x (likely on Python 3.12)
Upgrade prefect-dbt
to the latest release that supports Pydantic v2:
- pip:
pip install -U prefect prefect-dbt
- conda-forge:
conda install -c conda-forge prefect prefect-dbt
3) If you must stay on Prefect 2.x
Prefect 2.x relies on Pydantic v1. In that case, either:
- Pin Pydantic to v1:
pip install "pydantic<2"
- Or upgrade to Prefect 3.x + latest prefect-dbt
.
Why this happens: importing prefect_dbt
triggers its __init__
which imports the Cloud credentials module. Older prefect-dbt
builds define schema tweaks the Pydantic v1 way, which fails under Pydantic v2.
If you share the output of the version check above, I can give you exact pin recommendations for your setup.
Reference: prefect-dbt integration guide