{"record":{"id":"b87e180c4e3d8465","repo":"apache/beam","slug":"with-exception-handling-with-tensorflow-transform-based","errorCode":null,"errorMessage":"with_exception_handling with TensorFlow Transform-based MLTransform operations is not supported. To enable exception handling for those operations, please create a separate MLTransform instance","messagePattern":"with_exception_handling with TensorFlow Transform-based MLTransform operations is not supported\\. To enable exception handling for those operations, please create a separate MLTransform instance","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/transforms/handlers.py","lineNumber":479,"sourceCode":"      # transformed_dataset.\n      del self.transformed_schema[_TEMP_KEY]\n      row_type = RowTypeConstraint.from_fields(\n          list(self.transformed_schema.items()))\n\n      # Decode the extra columns that were encoded as bytes.\n      transformed_dataset = (\n          transformed_dataset\n          |\n          \"DecodeUnmodifiedColumns\" >> beam.Map(lambda x: data_coder.decode(x)))\n      # The schema only contains the columns that are transformed.\n      transformed_dataset = (\n          transformed_dataset\n          | \"ConvertToRowType\" >>\n          beam.Map(lambda x: beam.Row(**x)).with_output_types(row_type))\n      return transformed_dataset\n\n  def with_exception_handling(self):\n    raise NotImplementedError(\n        \"with_exception_handling with TensorFlow Transform-based MLTransform \"\n        \"operations is not supported. To enable exception handling for those \"\n        \"operations, please create a separate MLTransform instance\")\n","sourceCodeStart":461,"sourceCodeEnd":483,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/transforms/handlers.py#L461-L483","documentation":"MLTransform backed by TensorFlow Transform explicitly overrides with_exception_handling() to raise NotImplementedError. Exception handling (bad-row routing) is not implemented for TFT-based transforms, so callers must not invoke this method on TFT MLTransform instances.","triggerScenarios":"Calling .with_exception_handling() on an MLTransform whose transforms come from apache_beam.ml.transforms.tft (TFT-based handlers), e.g. ScaleToZScore, ComputeAndApplyVocab, etc.","commonSituations":"Copy-pasting exception-handling configuration from non-TFT (e.g. torch/sklearn handlers) MLTransform usage onto a TFT pipeline.","solutions":["Remove the with_exception_handling() call from the TFT-based MLTransform chain.","Create a separate MLTransform instance for the TFT operations as the message suggests, and handle failures manually via a beam.Map/DoFn with try/except around data prep.","Use the non-TFT transform implementations in apache_beam.ml.transforms that do support exception handling if bad-row routing is required."],"exampleFix":"# before\nresult = pcoll | MLTransform(tft.ScaleToZScore('x')).with_exception_handling().with_write_artifact_location(loc)\n\n# after\nresult = pcoll | MLTransform(tft.ScaleToZScore('x')).with_write_artifact_location(loc)","handlingStrategy":"type-guard","validationCode":"def is_tft_transform(cfg) -> bool:\n    import apache_beam.ml.transforms.tft as tft\n    return isinstance(cfg, tuple(c for c in vars(tft).values() if isinstance(c, type) and issubclass(c, object) and c.__module__ == tft.__name__))","typeGuard":"def supports_exception_handling(mltransform) -> bool:\n    # TFTProcessHandler-backed MLTransform raises NotImplementedError\n    import inspect\n    try:\n        mltransform.with_exception_handling\n    except NotImplementedError:\n        return False\n    return True","tryCatchPattern":"try:\n    t = mltransform.with_exception_handling()\nexcept NotImplementedError:\n    t = mltransform  # proceed without exception handling; handle bad rows manually","preventionTips":["Only call with_exception_handling() on non-TFT MLTransform pipelines.","Wrap raw data validation in a prior beam.Map with try/except for TFT pipelines.","Check the Beam version's docs for TFT handler limitations before enabling bad-row routing."],"tags":["python","apache-beam","tft","exception-handling"],"backgroundTag":"method-not-implemented","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"}