{"record":{"id":"904203d81175d5d3","repo":"langchain-ai/langchain","slug":"field-obj-must-have-a-name-to-be-deprecated","errorCode":null,"errorMessage":"Field {obj} must have a name to be deprecated.","messagePattern":"Field (.+?) must have a name to be deprecated\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/_api/deprecation.py","lineNumber":292,"sourceCode":"                    return wrapped(self, *args, **kwargs)\n\n                obj.__init__ = functools.wraps(obj.__init__)(  # type: ignore[misc]\n                    warn_if_direct_instance\n                )\n                # Set __deprecated__ for PEP 702 (IDE/type checker support)\n                obj.__deprecated__ = _build_deprecation_message(  # type: ignore[attr-defined]\n                    alternative=alternative,\n                    alternative_import=alternative_import,\n                )\n                return obj\n\n        elif _is_pydantic_v1_field_info(obj):\n            wrapped = None\n            if not _obj_type:\n                _obj_type = \"attribute\"\n            if not _name:\n                msg = f\"Field {obj} must have a name to be deprecated.\"\n                raise ValueError(msg)\n            old_doc = obj.description\n\n            def finalize(_: Callable[..., Any], new_doc: str, /) -> T:\n                from pydantic.v1.fields import FieldInfo as FieldInfoV1  # noqa: PLC0415\n\n                return cast(\n                    \"T\",\n                    FieldInfoV1(\n                        default=obj.default,\n                        default_factory=obj.default_factory,\n                        description=new_doc,\n                        alias=obj.alias,\n                        exclude=obj.exclude,\n                    ),\n                )\n\n        elif isinstance(obj, FieldInfo):\n            wrapped = None","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/_api/deprecation.py#L274-L310","documentation":"Raised inside the `deprecated` decorator when the object being deprecated is a Pydantic v1 `FieldInfo` (i.e. you decorated a `Field(...)` value from `pydantic.v1`) and no `name=` was passed to the decorator. A FieldInfo instance carries no reliable own name, so the decorator needs the field name to render the deprecation message and to rebuild the FieldInfo with an updated description.","triggerScenarios":"`x: int = deprecated(\"0.3\")(Field(default=1, description=\"...\"))` where the `Field` comes from `pydantic.v1` (or the pydantic.v1 compatibility shim) and the decorator call omits `name=`. The check `if not _name` fires at class-definition/import time.","commonSituations":"Migrating a legacy langchain model that still uses pydantic.v1 fields; the author decorates a Field with `@deprecated(since=...)` the way they would a function and forgets that fields need an explicit name. Also occurs when deprecating an attribute where the surrounding class refactor removed the name argument.","solutions":["Pass the field name to the decorator: `deprecated(\"0.3\", name=\"my_field\")`.","If you intended to deprecate the whole model or method rather than one field, decorate that object instead — it knows its own name."],"exampleFix":"# before\nclass MyModel(BaseModelV1):\n    old_attr: int = deprecated(\"0.3\")(Field(default=0))\n\n# after\nclass MyModel(BaseModelV1):\n    old_attr: int = deprecated(\"0.3\", name=\"old_attr\")(Field(default=0))","handlingStrategy":"validation","validationCode":"def deprecate_v1_field(since: str, name: str | None, field) -> Any:\n    if not name:\n        raise ValueError(\"Field deprecation requires name=\")\n    return deprecated(since, name=name)(field)","typeGuard":"from pydantic.v1.fields import FieldInfo as FieldInfoV1\n\ndef is_v1_field_info(obj: object) -> bool:\n    return isinstance(obj, FieldInfoV1)","tryCatchPattern":null,"preventionTips":["Always pass name= when decorating any Field(...) — it never carries its own name.","Prefer deprecating at the class or method level where names are self-evident."],"tags":["deprecation","pydantic-v1","langchain-core"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}