{"record":{"id":"bcaed1377ec69214","repo":"apache/beam","slug":"embeddings-can-only-be-generated-on-dict-str-dataclass-types","errorCode":null,"errorMessage":"Embeddings can only be generated on  dict[str, dataclass] types. Got dict[str, {type(batch[0])}] instead.","messagePattern":"Embeddings can only be generated on  dict\\[str, dataclass\\] types\\. Got dict\\[str, (.+?)\\] instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/transforms/base.py","lineNumber":841,"sourceCode":"\n  _MultiModalEmbeddingHandler will accept an EmbeddingsManager instance, which\n  contains the details of the model to be loaded and the inference_fn to be\n  used. The purpose of _MultiMOdalEmbeddingHandler is to generate embeddings\n  for image, video, and text inputs using the EmbeddingsManager instance.\n\n  If the input is not an Image representation column, a RuntimeError will be\n  raised.\n\n  This is an internal class and offers no backwards compatibility guarantees.\n\n  Args:\n    embeddings_manager: An EmbeddingsManager instance.\n  \"\"\"\n  def _validate_column_data(self, batch):\n    # Don't want to require framework-specific imports\n    # here, so just catch columns of primatives for now.\n    if isinstance(batch[0], (int, str, float, bool)):\n      raise TypeError(\n          'Embeddings can only be generated on '\n          ' dict[str, dataclass] types. '\n          f'Got dict[str, {type(batch[0])}] instead.')\n\n  def get_metrics_namespace(self) -> str:\n    return (\n        self._underlying.get_metrics_namespace() or\n        'BeamML_MultiModalEmbeddingHandler')\n","sourceCodeStart":823,"sourceCodeEnd":850,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/transforms/base.py#L823-L850","documentation":"The dataclass-based embedding path expects column values to be instances of a dataclass whose fields describe model inputs (e.g. framework tensors per modality). Primitive values (int, str, float, bool) are rejected with TypeError, since the model wrapper can only unpack structured dataclass inputs.","triggerScenarios":"Applying a multimodal/dataclass embedding transform to a column whose values are primitives instead of dataclass instances; feeding raw strings or numbers where a structured record was expected.","commonSituations":"Forgetting to wrap model inputs in the expected dataclass before the transform; passing a plain dict (dicts are not dataclass instances) instead of the required dataclass type.","solutions":["Wrap each value in the dataclass expected by the embedding implementation (the module-specific Inputs dataclass).","Convert dicts to the dataclass: MyInputs(**d) before applying the transform.","Use the text or image embeddings manager if your data is actually plain strings or images."],"exampleFix":"// before\nrows | beam.Map(lambda d: {'col': d['text']}) | dataclass_embedding\n// after\nfrom dataclasses import dataclass\n@dataclass\nclass ColInputs:\n  text: str\nrows | beam.Map(lambda d: {'col': ColInputs(d['text'])}) | dataclass_embedding","handlingStrategy":"validation","validationCode":"from dataclasses import is_dataclass\ndef validate_dataclass_batch(batch):\n    assert is_dataclass(batch[0]), f'Expected dataclass, got {type(batch[0])}'","typeGuard":"def is_dataclass_column(values) -> bool:\n    from dataclasses import is_dataclass\n    return all(is_dataclass(v) for v in values)","tryCatchPattern":"try:\n    data | dataclass_embedding\nexcept TypeError as e:\n    if 'dataclass' in str(e):\n        data = data | beam.Map(lambda d: {k: ColInputs(**v) for k, v in d.items()})\n    else:\n        raise","preventionTips":["Wrap model inputs in the dataclass type expected by the embedding implementation.","Convert dicts to the dataclass before the transform.","Note dicts are not dataclasses; use the documented input type.","Test one batch locally before running the full pipeline."],"tags":["python","type-mismatch","embeddings","dataclass"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}