{"record":{"id":"177c052b85f116b5","repo":"apache/beam","slug":"failed-to-find-a-batchconverter-for-the-input-types-of-dofn","errorCode":null,"errorMessage":"Failed to find a BatchConverter for the input types of DoFn {self.fn!r} (element_type={input_element_type!r}, batch_type={input_batch_type!r}).","messagePattern":"Failed to find a BatchConverter for the input types of DoFn (.+?) \\(element_type=(.+?), batch_type=(.+?)\\)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/core.py","lineNumber":1727,"sourceCode":"\n  def infer_batch_converters(self, input_element_type):\n    # TODO: Test this code (in batch_dofn_test)\n    if self.fn._process_batch_defined:\n      input_batch_type = self.fn._get_input_batch_type_normalized(\n          input_element_type)\n\n      if input_batch_type is None:\n        raise TypeError(\n            \"process_batch method on {self.fn!r} does not have \"\n            \"an input type annoation\")\n\n      try:\n        # Generate a batch converter to convert between the input type and the\n        # (batch) input type of process_batch\n        self.fn.input_batch_converter = BatchConverter.from_typehints(\n            element_type=input_element_type, batch_type=input_batch_type)\n      except TypeError as e:\n        raise TypeError(\n            \"Failed to find a BatchConverter for the input types of DoFn \"\n            f\"{self.fn!r} (element_type={input_element_type!r}, \"\n            f\"batch_type={input_batch_type!r}).\") from e\n\n    else:\n      self.fn.input_batch_converter = None\n\n    if self.fn._can_yield_batches:\n      output_batch_type = self.fn._get_output_batch_type_normalized(\n          input_element_type)\n      if output_batch_type is None:\n        # TODO: Mention process method in this error\n        raise TypeError(\n            f\"process_batch method on {self.fn!r} does not have \"\n            \"a return type annoation\")\n\n      # Generate a batch converter to convert between the output type and the\n      # (batch) output type of process_batch","sourceCodeStart":1709,"sourceCodeEnd":1745,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/core.py#L1709-L1745","documentation":" After resolving the DoFn's input batch type, Beam asks BatchConverter.from_typehints to build a converter between element_type and batch_type. If no registered converter supports that (element_type, batch_type) pair, the underlying TypeError is re-raised with this message.","triggerScenarios":"Using a DoFn with process_batch where the declared element type and batch type pair has no registered BatchConverter (e.g. element_type=SomeCustomClass, batch_type=pandas.DataFrame), via a ParDo with batch support enabled.","commonSituations":"Using custom or unsupported element types with batch DoFns; mismatched pandas/numpy/arrow types (e.g. element dict vs batch np.ndarray without a converter); missing optional deps like pandas or pyarrow so the registry lacks converters.","solutions":["Align element_type and batch_type with a registered converter pair (e.g. element_type=np.int64 with batch_type=np.ndarray, or element type backed by pandas DataFrame).","Register a custom BatchConverter via BatchConverter registry (register_batch_converter) for your types.","Install missing optional dependencies (pandas, pyarrow) that provide built-in converters.","Override DoFn.infer_input_type / adjust annotations so the pair is supported.","Example fix: annotate batch as numpy.ndarray and element as np.int64 instead of custom class."],"exampleFix":"// before\nclass MyDoFn(beam.DoFn):\n    def process_batch(self, batch: MyCustomBatchType): ...\n// after\nclass MyDoFn(beam.DoFn):\n    def process_batch(self, batch: numpy.ndarray): ...\n    def process(self, element: numpy.int64): ...","handlingStrategy":"validation","validationCode":"try:\n    BatchConverter.from_typehints(element_type=el_t, batch_type=batch_t)\nexcept TypeError:\n    raise TypeError('no BatchConverter registered for this (element, batch) pair')","typeGuard":"def has_batch_converter(el_t, batch_t) -> bool:\n    try:\n        BatchConverter.from_typehints(element_type=el_t, batch_type=batch_t)\n        return True\n    except TypeError:\n        return False","tryCatchPattern":"try:\n    run_pipeline_with_batch_dofn()\nexcept TypeError as e:\n    if 'BatchConverter' in str(e):\n        register_custom_converter(); run_pipeline_with_batch_dofn()\n    else:\n        raise","preventionTips":["Stick to supported type pairs (numpy/pandas/arrow).","Install pandas and pyarrow when using batch transforms.","Register custom BatchConverters for domain-specific types."],"tags":["python","apache-beam","batchconverter","type-hints"],"backgroundTag":"incompatible-source-type","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"}