{"id":"23e146b44cff5a5c","repo":"pydantic/pydantic","slug":"model-field-missing-annotation-23e146","errorCode":"model-field-missing-annotation","errorMessage":"Field {var_name!r} requires a type annotation","messagePattern":"Field (.+?) requires a type annotation","errorType":"exception","errorClass":"PydanticUserError","httpStatus":null,"severity":"error","filePath":"pydantic/_internal/_model_construction.py","lineNumber":500,"sourceCode":"            )\n\n        elif var_name.startswith('__'):\n            continue\n        elif is_valid_privateattr_name(var_name):\n            if var_name not in raw_annotations or not is_classvar_annotation(raw_annotations[var_name]):\n                private_attributes[var_name] = cast(ModelPrivateAttr, PrivateAttr(default=value))\n                del namespace[var_name]\n        elif var_name in base_class_vars:\n            continue\n        elif var_name not in raw_annotations:\n            if var_name in base_class_fields:\n                raise PydanticUserError(\n                    f'Field {var_name!r} defined on a base class was overridden by a non-annotated attribute. '\n                    f'All field definitions, including overrides, require a type annotation.',\n                    code='model-field-overridden',\n                )\n            elif isinstance(value, FieldInfo):\n                raise PydanticUserError(\n                    f'Field {var_name!r} requires a type annotation', code='model-field-missing-annotation'\n                )\n            else:\n                raise PydanticUserError(\n                    f'A non-annotated attribute was detected: `{var_name} = {value!r}`. All model fields require a '\n                    f'type annotation; if `{var_name}` is not meant to be a field, you may be able to resolve this '\n                    f\"error by annotating it as a `ClassVar` or updating `model_config['ignored_types']`.\",\n                    code='model-field-missing-annotation',\n                )\n\n    for ann_name, ann_type in raw_annotations.items():\n        if (\n            is_valid_privateattr_name(ann_name)\n            and ann_name not in private_attributes\n            and ann_name not in ignored_names\n            # This condition can be a false negative when `ann_type` is stringified,\n            # but it is handled in most cases in `set_model_fields`:\n            and not is_classvar_annotation(ann_type)","sourceCodeStart":482,"sourceCodeEnd":518,"githubUrl":"https://github.com/pydantic/pydantic/blob/2e5f0e2b4218de31709f1cf9c5bc61ea97a68835/pydantic/_internal/_model_construction.py#L482-L518","documentation":"A `PydanticUserError` (code `model-field-missing-annotation`) raised when a `FieldInfo`/`Field(...)` is assigned to a class attribute without a type annotation. Pydantic cannot infer the field type from a bare `Field()` assignment.","triggerScenarios":"Writing `class M(BaseModel): name = Field(...)` with no annotation. The Field info is present but the type is unknown.","commonSituations":"Forgetting the annotation after adding Field(...); copy-pasting from dataclass-style code; renaming and dropping the annotation.","solutions":["Add the type annotation: `name: str = Field(...)`.","If using Python 3.12+ type aliases, ensure the annotation is still syntactically present."],"exampleFix":"# before\nfrom pydantic import BaseModel, Field\nclass M(BaseModel):\n    name = Field(...)\n\n# after\nclass M(BaseModel):\n    name: str = Field(...)","handlingStrategy":"validation","validationCode":null,"typeGuard":"def fields_have_annotations(namespace, annotations):\n    from pydantic.fields import FieldInfo\n    missing = [k for k, v in namespace.items()\n              if isinstance(v, FieldInfo) and k not in annotations]\n    return not missing, missing","tryCatchPattern":null,"preventionTips":["Always pair Field(...) with a type annotation.","Enable a linter/pyright to flag unannotated Field assignments."],"tags":["pydantic","fields","annotations","model-construction"],"analyzedSha":"2e5f0e2b4218de31709f1cf9c5bc61ea97a68835","analyzedAt":"2026-08-04T19:54:21.281Z","schemaVersion":2}