AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

TypeSafeClassifier Cannot Be Deserialized Due To Missing Class Mapping In Langchain-Core

TypeSafeClassifier from langchain-typesafe declares is_lc_serializable() True and dumpd() succeeds, but load() fails with both allowed_objects='all' and allowed_objects=[TypeSafeClassifier]. The root cause is that the serialized ID ('langchain', 'classifiers', 'typesafe', 'TypeSafeClassifier') is not present in langchain-core's deserialization mapping and the 'langchain_typesafe' namespace is not in the default valid namespaces.

highConfidence 92%LangChainAffected V0.0.1a3

Origin Analysis

langchain-typesafe uses a legacy namespace ID that is not registered in langchain-core's SERIALIZABLE_MAPPING, and the namespace 'langchain_typesafe' is not included in the loader's valid default namespaces. Therefore, allowed_objects='all' rejects the ID because the mapping is missing, and allowed_objects=[TypeSafeClassifier] still fails because the loader cannot import from the legacy namespace and the mapped import path is not whitelisted.
from langchain_core.load import dumpd, load from langchain_typesafe import TypeSafeClassifier api_key = 'test-key' classifier = TypeSafeClassifier(api_key=api_key) serialized = dumpd(classifier) print(serialized['id']) for allowed_objects in ('all', [TypeSafeClassifier]): try: load(serialized, allowed_objects=allowed_objects, secrets_map={'TYPESAFE_API_KEY': api_key}) except ValueError as error: print(repr(allowed_objects), error)

Fixing Code Block

Edge Case Audit

If langchain-typesafe is not installed, the try-import prevents errors, but the mapping will be absent and deserialization will still fail. Adding a new namespace to the whitelist could potentially allow deserialization of untrusted classes from that namespace if the package is malicious or compromised; ensure langchain-typesafe is a trusted dependency. The fix hardcodes the import path 'langchain_typesafe.classifier.TypeSafeClassifier'; if the package renames or moves the class, this mapping must be updated. Rollback: revert these changes, but note that previously serialized data will again fail to load.

Ecosystem Topology