apache/beam · error · ValueError
'{type(self).__name__}' not registered as Specifiable. Decor
Error message
'{type(self).__name__}' not registered as Specifiable. Decorate ({type(self).__name__}) with @specifiable What it means
apache_beam.ml.anomaly.specifiable.to_spec() can only serialize objects whose class was registered via the @specifiable decorator, which sets a class-level `spec_type`. If the class lacks `spec_type`, the library cannot map the instance back to a constructor spec and raises this ValueError.
Source
Thrown at sdks/python/apache_beam/ml/anomaly/specifiable.py:198
return subclass
kwargs = {
k: _specifiable_from_spec_helper(v, _run_init)
for k, v in spec.config.items()
}
if _run_init:
kwargs["_run_init"] = True
return subclass(**kwargs)
def to_spec(self) -> Spec:
"""Generate a spec from a `Specifiable` subclass object.
Returns:
Spec: The specification of the instance.
"""
if getattr(type(self), 'spec_type', None) is None:
raise ValueError(
f"'{type(self).__name__}' not registered as Specifiable. "
f"Decorate ({type(self).__name__}) with @specifiable")
args = {
k: _specifiable_to_spec_helper(v)
for k, v in self.init_kwargs.items()
}
return Spec(type=self.spec_type(), config=args)
def run_original_init(self) -> None:
"""Invoke the original __init__ method with original keyword arguments"""
pass
@classmethod
def unspecifiable(cls) -> None:
"""Resume the class structure prior to specifiable"""
passView on GitHub (pinned to 12126d8942)
Solutions
- Decorate the class with @specifiable (optionally @specifiable(spec_type='my_type')) before instantiating/calling to_spec
- If you cannot modify the class, wrap it in a Specifiable-compatible adapter class decorated with @specifiable
- Check that the instance's actual (most-derived) class is the decorated one, not an undecorated subclass
Example fix
// before
class MyDetector(AnomalyDetector):
...
obj.to_spec()
// after
from apache_beam.ml.anomaly import specifiable
@specifiable.specifiable
class MyDetector(AnomalyDetector):
...
obj.to_spec() Defensive patterns
Strategy: validation
Validate before calling
from apache_beam.ml.anomaly import specifiable
if getattr(type(detector), 'spec_type', None) is None:
raise TypeError(f"{type(detector).__name__} must be decorated with @specifiable before to_spec()") Type guard
def is_specifiable(obj) -> bool:
return getattr(type(obj), 'spec_type', None) is not None Prevention
- Always decorate custom detector/transform classes with @specifiable
- Run a unit test that calls to_spec() on every pipeline component
- Keep custom class names unique from Beam built-ins
When it happens
Trigger: Calling to_spec() (or specifiable_object_to_spec) on an instance of a class not decorated with @specifiable, e.g. a custom AnomalyDetector subclass or a third-party sklearn model passed into ML Transform without registration.
Common situations: Users write a custom detector subclass and pass it to RunInference/anomaly transforms without decorating it; upgrading Beam adds @specifiable to internal classes that user subclasses now shadow; passing plain sklearn/torch objects inside ensemble detectors.
Related errors
- Unable to deterministically encode non-frozen '%s' of type '
- Unable to deterministically encode '%s' of type '%s', please
- Unable to deterministically encode '%s' of type '%s', for th
- No fallback.
- Attempted to encode null for non-nullable field "{}".
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/9138d681877e8fd4.
Report an issue: GitHub.