Importing spaCy or FastAPI fails with a recursive_guard TypeError
Your error
TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard'Fix it fast
Most common cause, 1 of 2Pydantic 1.10.15 or older on Python 3.12.4 and newer
Move the project to Pydantic 2, the supported line; V1-style code can import from pydantic.v1 as a bridge during the migration, though that layer is out of support too.
# preferred
python -m pip install -U "pydantic>=2.7.4"
# short stop-gap, Python 3.12/3.13 only
python -m pip install "pydantic>=1.10.16,<2"Short answer
TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard' appears when Python 3.12.4 or newer runs Pydantic older than 1.10.16, or a Pydantic 2 older than 2.7.4 through pydantic.v1. Python made that argument keyword-only. Upgrade to Pydantic 2.7.4+ (current 2.14) and spaCy 3.8.12+; Pydantic 1 does not work on Python 3.14.
Which cause do you have?
Print the interpreter version and the versions of pydantic and the libraries that depend on it. Then read the traceback: a path through pydantic/typing.py means Pydantic 1 itself, a path through pydantic/v1/ means a library using the V1 layer inside Pydantic 2.
python --version && python -m pip show pydantic spacy thinc confection fastapi | grep -E '^(Name|Version)'Then find the line you see in this list and open its fix:
- 1Pydantic 1.10.15 or older on Python 3.12.4 and newer
pip show prints a pydantic version starting with 1. and below 1.10.16; the traceback ends in pydantic/typing.py inside evaluate_forwardref - 2spaCy uses the pydantic.v1 layer of a Pydantic 2 older than 2.7.4
pydantic is 2.x but below 2.7.4, spaCy is between 3.6.1 and 3.8.11, and the failing frames sit under pydantic/v1/
What does the error look like?
TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard'
Cause 1 of 2
Pydantic 1.10.15 or older on Python 3.12.4 and newer
You seepip show prints a pydantic version starting with 1. and below 1.10.16; the traceback ends in pydantic/typing.py inside evaluate_forwardref
Check
The recursive_guard TypeError comes from a Pydantic 1 release that still passes that argument by position. CPython 3.12.4 and 3.13 changed typing.ForwardRef._evaluate so it only accepts recursive_guard as a keyword, and Pydantic's tracker shows 1.10.15 failing this way on import.
python -m pip show pydantic | grep VersionFix
Move the project to Pydantic 2, the supported line; V1-style code can import from pydantic.v1 as a bridge during the migration, though that layer is out of support too. Only as a stop-gap on Python 3.12 or 3.13, 1.10.16 and later pass the argument by keyword, and 1.10.27 is the final V1 release.
# preferred
python -m pip install -U "pydantic>=2.7.4"
# short stop-gap, Python 3.12/3.13 only
python -m pip install "pydantic>=1.10.16,<2"Verify
The import that crashed now runs without a traceback.
python -c "import fastapi; print('import ok')"Confirmed by github.com
Cause 2 of 2
spaCy uses the pydantic.v1 layer of a Pydantic 2 older than 2.7.4
You seepydantic is 2.x but below 2.7.4, spaCy is between 3.6.1 and 3.8.11, and the failing frames sit under pydantic/v1/
Check
Since spaCy 3.6.1 the library accepted Pydantic 2 through its transitional V1 support. The copy of V1 shipped inside Pydantic 2 had the same positional call until 2.7.4, whose notes list the recursive_guard keyword change, so spaCy crashes on import with an older 2.x pin.
python -m pip show pydantic spacy | grep -E '^(Name|Version)'Fix
Upgrade both. spaCy 3.8.12 moved to confection 1.3 and Thinc 8.3.13 and adopts Pydantic 2 properly, with full Python 3.14 support, so pip pulls a matching set.
python -m pip install -U "spacy>=3.8.12" "pydantic>=2.7.4"Verify
spaCy prints its installation details instead of the TypeError.
python -m spacy infoConfirmed by github.com
How do I stop it coming back?
- Upgrade the Python base image and the pydantic pin in the same pull request, and run the import test in CI before merging.
- Search requirements files and lockfiles for pydantic<2 or pydantic==1. pins; V1 gets no more releases after 1.10.27.
- Keep spaCy, thinc and confection pinned together from one resolved lockfile instead of pinning them one by one.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.