Pydantic cannot build a schema for one of your field types
Your error
pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class '__main__.Client'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.3 more lines it can showFix it fast
Most common cause, 1 of 3The annotation is a module or a value, not a type
Import the class itself, or write the full dotted name in the annotation, so the field points at a real type.
from datetime import datetime
from pydantic import BaseModel
class Event(BaseModel):
started_at: datetimeShort answer
PydanticSchemaGenerationError: Unable to generate pydantic-core schema for X means a model field is annotated with something pydantic cannot validate. If X is a module or a plain value, fix the annotation. If X is a class of your own or from another package, add arbitrary_types_allowed=True or InstanceOf[X]. Inside a library, match its pydantic range. pydantic 2.14.
Which cause do you have?
Look at what follows schema for in the message and at the last frame of the traceback. A module or a bare value is cause 1, a class is cause 2, and a traceback that ends inside a third-party package you did not edit is cause 3.
python -c "import app.models" 2>&1 | grep -E "schema for|File \""
python -c "import pydantic; print(pydantic.VERSION)"Then find the line you see in this list and open its fix:
- 1The annotation is a module or a value, not a type
The message says schema for <module '...'> or for a literal such as 43 - 2A field uses a class pydantic has no validator for
The message names <class '...'>, such as an API client, a DataFrame or a class from your own code - 3A library's models broke after pydantic was upgraded
Nothing in your code changed, the traceback ends inside a package such as llama_index, and pydantic moved to a new minor version
What does the error look like?
pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class '__main__.Client'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.Unable to generate pydantic-core schema for <module 'datetime' from '...'>Unable to generate pydantic-core schema for typing.AsyncGenerator[str, NoneType]For further information visit https://errors.pydantic.dev/2.14/u/schema-for-unknown-type
Cause 1 of 3
The annotation is a module or a value, not a type
You seeThe message says schema for <module '...'> or for a literal such as 43
Check
pydantic raises the schema-for-unknown-type error when an annotation is not a type it understands, and its own docs show x: 43 = 123 doing exactly that. The same thing happens after import datetime when a field is typed datetime: pydantic receives the module, not the class.
grep -rnE "^import (datetime|decimal|uuid)$" --include=*.py .Fix
Import the class itself, or write the full dotted name in the annotation, so the field points at a real type.
from datetime import datetime
from pydantic import BaseModel
class Event(BaseModel):
started_at: datetimeVerify
The class definition runs, and a sample object validates.
python -c "from app.models import Event; print(Event(started_at='2026-11-21T10:00:00'))"Confirmed by docs.pydantic.dev
Cause 2 of 3
A field uses a class pydantic has no validator for
You seeThe message names <class '...'>, such as an API client, a DataFrame or a class from your own code
Check
Pydantic builds a validator for each annotation. A plain Python class gives it nothing to build from, so model creation fails until you allow such types or teach pydantic about them.
python -c "import app.models"Fix
When an isinstance check is all you need, turn on arbitrary_types_allowed for the model, or mark just that field with InstanceOf. Nothing inside the object is validated either way, so keep real data in proper pydantic fields.
from pydantic import BaseModel, ConfigDict, InstanceOf
from app.http import HttpClient # your own class
class Job(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
client: HttpClient
class Report(BaseModel):
client: InstanceOf[HttpClient]Verify
The models import cleanly; passing a wrong object now gives Input should be an instance of HttpClient [type=is_instance_of] instead.
python -c "import app.models"Confirmed by docs.pydantic.dev
Cause 3 of 3
A library's models broke after pydantic was upgraded
You seeNothing in your code changed, the traceback ends inside a package such as llama_index, and pydantic moved to a new minor version
Check
A package can declare a pydantic range that is wider than what its models really support. In November 2024 llama-index hit this with pydantic 2.10.0 on typing.AsyncGenerator, and its maintainers shipped llama-index-core 0.12.1 pinning pydantic below 2.10 while the fix landed.
pip show pydantic <the-library> | grep -E "^(Name|Version|Requires)"Fix
Upgrade the library first, because a newer release may already carry the fix or a pin. If none exists yet, pin pydantic to the last version that worked in your requirements file and follow the library's issue tracker.
pip install -U llama-index-core
# only if no fixed release exists yet:
pip install "pydantic<2.10"Verify
Import the library in a fresh interpreter; it loads without the schema error.
python -c "import llama_index.core; print('ok')"Confirmed by github.com
How do I stop it coming back?
- Pin pydantic together with the libraries that define models on top of it, and upgrade them in one change.
- Import classes, not modules, for anything used in type annotations, and let a type checker flag module-typed fields.
- Keep live objects such as clients and connections out of pydantic models, or mark them with InstanceOf on purpose.
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.