Contents

[pydantic] NameError: Field name "schema" shadows a BaseModel attribute; use a different field name with "alias='schema'".

0
Contents

This error is encountered when you define a pydantic class that has a attributed named schema.

class EmbedDoc(BaseModel):
    schema: int = 1
    name: str = Field(str)
    tags: List[str]
    archived: bool

The schema attribute is special field for pydantic…….

Workaround

You can specify a field alias and when the document is serialized it will use the field name schama instead of schema_.


class EmbedDoc(BaseModel):
    schema_: int = Field(1, alias="schema")
    name: str = Field(str)
    tags: List[str]
    archived: bool