chroma-core/chroma · error · ValueError
Trying to instantiate configuration of type {cls.__name__} f
Error message
Trying to instantiate configuration of type {cls.__name__} from JSON with type {json_map['_type']} What it means
ConfigurationInternal.from_json (chromadb/api/configuration.py:208) raises this ValueError when the "_type" discriminator in the JSON map does not equal the class you are deserializing into. to_json stamps every serialized configuration with _type = its class name, and from_json enforces an exact match (cls.__name__ != json_map["_type"]), so loading a map of one configuration class through another class is rejected instead of silently misinterpreting fields.
Source
Thrown at chromadb/api/configuration.py:208
@override
def to_json(self) -> Dict[str, Any]:
"""Returns the JSON compatible dictionary representation of the configuration."""
json_dict = {
name: parameter.value.to_json()
if isinstance(parameter.value, ConfigurationInternal)
else parameter.value
for name, parameter in self.parameter_map.items()
}
# What kind of configuration is this?
json_dict["_type"] = self.__class__.__name__
return json_dict
@classmethod
@override
def from_json(cls, json_map: Dict[str, Any]) -> Self:
"""Returns a configuration from the given JSON string."""
if cls.__name__ != json_map.get("_type", None):
raise ValueError(
f"Trying to instantiate configuration of type {cls.__name__} from JSON with type {json_map['_type']}"
)
parameters = []
for name, value in json_map.items():
# Type value is only for storage
if name == "_type":
continue
parameters.append(ConfigurationParameter(name=name, value=value))
return cls(parameters=parameters)
class HNSWConfigurationInternal(ConfigurationInternal):
"""Internal representation of the HNSW configuration.
Used for validation, defaults, serialization and deserialization."""
definitions = {
"space": ConfigurationDefinition(
name="space",View on GitHub (pinned to aecdd12c8a)
Solutions
- Dispatch on the discriminator: look up the class by json_map["_type"] (e.g. via the module's ConfigurationInternal subclasses) and call its from_json
- Or call the exact matching class: HNSWConfigurationInternal.from_json(map_with_matching_type)
- Regenerate stored JSON with the current version via to_json so _type matches
Example fix
# before
cfg = HNSWConfigurationInternal.from_json({"_type": "OtherConfiguration", ...})
# after
m = json.loads(raw)
cls = {c.__name__: c for c in ConfigurationInternal.__subclasses__()}[m["_type"]]
cfg = cls.from_json(m) Defensive patterns
Strategy: validation
Validate before calling
def from_json_typed(cls, json_map):
actual = json_map.get("_type")
if actual != cls.__name__:
raise ValueError(
f"_type {actual!r} does not match {cls.__name__}; dispatch on _type instead"
)
return cls.from_json(json_map)
def from_json_dispatch(json_map):
import chromadb.api.configuration as m
target = getattr(m, json_map["_type"], None)
if target is None:
raise ValueError(f"unknown configuration type {json_map['_type']!r}")
return target.from_json(json_map) Prevention
- Dispatch deserialization on the _type discriminator instead of hardcoding a class
- Round-trip configs only through to_json/from_json of the same version
- Match class names exactly, including case
When it happens
Trigger: HNSWConfigurationInternal.from_json({"_type": "SomeOtherConfigurationInternal", ...}); a _type value with different casing; loading nested configuration JSON with the outer class's from_json instead of the nested class; version skew where the producer class was renamed.
Common situations: Generic loading code that picks a fixed class regardless of _type; copy-pasting deserialization calls between configuration types; renamed configuration classes across chromadb versions invalidating stored JSON.
Related errors
- Invalid configuration type: {parameter.value}
- Invalid parameter name: {parameter.name}
- Invalid parameter value: {parameter.value}
- Invalid parameter name: {name} for configuration {self.__cla
- Invalid parameter name: {name}
AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16).
Data as JSON: /api/errors/6c1ac55df54b32a0.
Report an issue: GitHub.