{"record":{"id":"a1e9c88ad6c45ac6","repo":"apache/beam","slug":"no-mltransform-found-please-install-tensorflow-transform-or","errorCode":null,"errorMessage":"No MLTransform found. Please install tensorflow-transform or sentence-transformers to use this transform.","messagePattern":"No MLTransform found\\. Please install tensorflow-transform or sentence-transformers to use this transform\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/yaml/yaml_ml.py","lineNumber":607,"sourceCode":"def _config_to_obj(spec):\n  if 'type' not in spec:\n    raise ValueError(f\"Missing type in ML transform spec {spec}\")\n  if 'config' not in spec:\n    raise ValueError(f\"Missing config in ML transform spec {spec}\")\n  constructor = _transform_constructors.get(spec['type'])\n  if constructor is None:\n    raise ValueError(\"Unknown ML transform type: %r\" % spec['type'])\n  return constructor(**spec['config'])\n\n\n@beam.ptransform.ptransform_fn\ndef ml_transform(\n    pcoll,\n    write_artifact_location: Optional[str] = None,\n    read_artifact_location: Optional[str] = None,\n    transforms: Optional[list[Any]] = None):\n  if MLTransform is None:\n    raise ValueError(\n        'No MLTransform found. Please install tensorflow-transform or '\n        'sentence-transformers to use this transform.')\n  options.YamlOptions.check_enabled(pcoll.pipeline, 'ML')\n  result_ml_transform = MLTransform(\n      write_artifact_location=write_artifact_location,\n      read_artifact_location=read_artifact_location,\n      transforms=[_config_to_obj(t) for t in transforms] if transforms else [])\n\n  if transforms:\n    embedding_transforms = [\n        t for t in transforms if t.get('type', '').endswith('Embeddings')\n    ]\n    if embedding_transforms:\n      from apache_beam.typehints import List\n      try:\n        if pcoll.element_type:\n          columns_to_change = {\n              col","sourceCodeStart":589,"sourceCodeEnd":625,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/yaml_ml.py#L589-L625","documentation":"apache_beam.yaml.ml_transform's ml_transform raises this ValueError when the MLTransform class failed to import, i.e. neither tensorflow-transform nor sentence-transformers is installed in the current Python environment. The YAML ML transform is only a thin wrapper around MLTransform, so without one of these backends there is nothing to construct. The check happens before YamlOptions.check_enabled, so it fires even in pipelines that would otherwise be valid.","triggerScenarios":"Calling the 'ml_transform' YAML transform (yaml_ml.py:607 ml_transform) when `from apache_beam.ml.transforms.base import MLTransform` returned None due to ImportError of both optional backends. Any pipeline spec containing type: ml_transform run in an environment without the ML extras.","commonSituations":"Running a Beam YAML pipeline that preprocesses data for ML inference on a machine where only apache-beam core was pip-installed; CI containers with slim Beam images; switching Python venvs where the ML extras were installed elsewhere.","solutions":["Install a backend: pip install 'apache-beam[yaml]' with tensorflow-transform (pip install tensorflow-transform) or sentence-transformers (pip install sentence-transformers).","Verify the import works: python -c \"from apache_beam.ml.transforms.base import MLTransform\" in the same interpreter/venv that runs the pipeline.","If you intended to gate this transform, enable it via the YAML option check (options.YamlOptions.check_enabled(..., 'ML')) only after installing a backend."],"exampleFix":"// before\npipeline:\n  - type: ml_transform\n    ...\n// after\n# shell\npip install tensorflow-transform\n# then run the same pipeline","handlingStrategy":"validation","validationCode":"import importlib\nif importlib.util.find_spec('tensorflow_transform') is None and importlib.util.find_spec('sentence_transformers') is None:\n    raise SystemExit('Install tensorflow-transform or sentence-transformers before using ml_transform')","typeGuard":"def ml_backend_available() -> bool:\n    import importlib.util\n    return any(importlib.util.find_spec(m) for m in ('tensorflow_transform', 'sentence_transformers'))","tryCatchPattern":null,"preventionTips":["Install apache-beam with the yaml/ML extras in every environment that runs the pipeline.","Pin backend packages (tensorflow-transform or sentence-transformers) in requirements.txt.","Add a preflight import check to CI before launching Beam YAML pipelines."],"tags":["python","apache-beam","yaml","ml","missing-dependency"],"backgroundTag":"missing-optional-dependency","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}