langchain-ai/langchain · error · ValueError
Class {self.__class__} has a deprecated attribute {attr}. Pl
Error message
Class {self.__class__} has a deprecated attribute {attr}. Please use the corresponding classmethod instead. What it means
Runtime guard in Serializable.to_json: a class in the MRO still declares a deprecated class/instance attribute `lc_namespace` or `lc_serializable` instead of the classmethod replacements (lc_namespace() became a classmethod; lc_serializable was removed in favor of always-on serialization via to_json). The check fires on every to_json call when any inherited class re-introduces these attributes.
Source
Thrown at libs/core/langchain_core/load/serializable.py:271
for cls in [None, *self.__class__.mro()]:
# Once we get to Serializable, we're done
if cls is Serializable:
break
if cls:
deprecated_attributes = [
"lc_namespace",
"lc_serializable",
]
for attr in deprecated_attributes:
if hasattr(cls, attr):
msg = (
f"Class {self.__class__} has a deprecated "
f"attribute {attr}. Please use the corresponding "
f"classmethod instead."
)
raise ValueError(msg)
# Get a reference to self bound to each class in the MRO
this = cast("Serializable", self if cls is None else super(cls, self))
secrets.update(this.lc_secrets)
# Now also add the aliases for the secrets
# This ensures known secret aliases are hidden.
# Note: this does NOT hide any other extra kwargs
# that are not present in the fields.
for key in list(secrets):
value = secrets[key]
if (key in model_fields) and (
alias := model_fields[key].alias
) is not None:
secrets[alias] = value
lc_kwargs.update(this.lc_attributes)
# include all secrets, even if not specified in kwargsView on GitHub (pinned to e32fa9a52e)
Solutions
- Replace lc_namespace attribute with the classmethod: @classmethod def lc_namespace(cls) -> list[str]
- Delete lc_serializable entirely — subclasses of Serializable are serializable by default
- Grep your custom classes for 'lc_namespace =' and 'lc_serializable' and migrate each hit
Example fix
# before
class MyChain(Serializable):
lc_namespace = ['my_pkg']
lc_serializable = True
# after
class MyChain(Serializable):
@classmethod
def lc_namespace(cls) -> list[str]:
return ['my_pkg'] Defensive patterns
Strategy: type-guard
Validate before calling
from langchain_core.load.serializable import Serializable
def check_serializable_class(cls: type) -> None:
for bad in ('lc_namespace', 'lc_serializable'):
assert bad not in cls.__dict__ and bad not in {k for b in cls.__mro__ for k in vars(b)}, f'{cls} declares deprecated attribute {bad}' Type guard
def uses_modern_serialization(cls: type) -> bool:
return all(not hasattr(b, 'lc_namespace') or 'lc_namespace' not in vars(b) or isinstance(vars(b).get('lc_namespace'), classmethod) for b in cls.__mro__) and not any('lc_serializable' in vars(b) for b in cls.__mro__) Try / catch
try:
dumps(obj)
except ValueError as e:
if 'deprecated attribute' in str(e):
# remove/convert the attribute on the offending class, then retry
raise
raise Prevention
- After upgrading langchain-core, grep custom classes for lc_namespace = and lc_serializable
- Declare namespaces via the lc_namespace classmethod only
- Drop lc_serializable — Serializable subclasses serialize automatically
When it happens
Trigger: A custom class defines lc_namespace = ['my_pkg'] as a plain attribute or lc_serializable = True for old-style opt-in serialization, then any dumps()/dumpd()/to_json() on it (or on a chain containing it) raises. Copying serialization code from LangChain pre-0.1 examples triggers this.
Common situations: Upgrading old integrations that used the pre-core serialization API; AI/tutorial code copied from old docs; custom Serializable subclasses that never migrated off attribute-style declarations.
Related errors
- Tracing using LangChainTracerV1 is no longer supported. Plea
- Failed to hash metadata: {e}. Please use a dict that can be
- {save_path} must be json or yaml
- Expected Serializable, got {type(obj)}
- `default` should not be passed to dumps
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/0bdf060b68eaae76.
Report an issue: GitHub.