{"record":{"id":"530f348e1f20f3b5","repo":"apache/beam","slug":"unexpected-output-type-s","errorCode":null,"errorMessage":"Unexpected output type: %s","messagePattern":"Unexpected output type: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/pipeline.py","lineNumber":1347,"sourceCode":"  def replace_output(\n      self,\n      output: Union[pvalue.PValue, pvalue.DoOutputsTuple],\n      tag: Union[str, int, None] = None) -> None:\n    \"\"\"Replaces the output defined by the given tag with the given output.\n\n    Args:\n      output: replacement output\n      tag: tag of the output to be replaced.\n    \"\"\"\n    if isinstance(output, pvalue.DoOutputsTuple):\n      self.replace_output(output[output._main_tag])\n    elif isinstance(output, pvalue.PValue):\n      self.outputs[tag] = output\n    elif isinstance(output, dict):\n      for output_tag, out in output.items():\n        self.outputs[output_tag] = out\n    else:\n      raise TypeError(\"Unexpected output type: %s\" % output)\n\n    # Importing locally to prevent circular dependency issues.\n    from apache_beam.transforms import external\n    if isinstance(self.transform, external.ExternalTransform):\n      self.transform.replace_named_outputs(self.named_outputs())\n\n  def replace_inputs(self, main_inputs):\n    self.main_inputs = main_inputs\n\n    # Importing locally to prevent circular dependency issues.\n    from apache_beam.transforms import external\n    if isinstance(self.transform, external.ExternalTransform):\n      self.transform.replace_named_inputs(self.named_inputs())\n\n  def replace_side_inputs(self, side_inputs):\n    self.side_inputs = side_inputs\n\n    # Importing locally to prevent circular dependency issues.","sourceCodeStart":1329,"sourceCodeEnd":1365,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/pipeline.py#L1329-L1365","documentation":"TypeError raised in AppliedPTransform.replace_output when the replacement output is not a PValue or dict of outputs. Only PValue instances (or dict mapping tags to them) are accepted when rewiring a transform's outputs after pipeline modification.","triggerScenarios":"Calling applied_transform.replace_output(tag, something) with a plain Python value, list, or None instead of a PCollection.","commonSituations":"Programmatic pipeline surgery (pipeline.replace()/test scenarios) where users pass wrong objects; refactorings that changed outputs from PCollection to raw values.","solutions":["Pass a PCollection (or other PValue) as the output","Pass a dict {tag: PCollection} to replace multiple outputs at once","Verify the value you are passing is the actual output of a transform, not intermediate data"],"exampleFix":"// before\napplied.replace_output(None, results_list)\n// after\napplied.replace_output(None, new_pcollection)","handlingStrategy":"type-guard","validationCode":"from apache_beam.pvalue import PValue\nassert isinstance(output, (PValue, dict)), f'Bad output: {output}'","typeGuard":"from apache_beam.pvalue import PValue\n\ndef is_valid_output(x):\n    return isinstance(x, PValue) or (isinstance(x, dict) and all(isinstance(v, PValue) for v in x.values()))","tryCatchPattern":"try:\n    applied.replace_output(tag, output)\nexcept TypeError as e:\n    logging.error('replace_output requires a PValue: %s', e)","preventionTips":["Only pass PCollection objects (transform outputs) to replace_output","When replacing multiple outputs, pass a {tag: PCollection} dict","Inspect the object type with print(type(output)) if unsure"],"tags":["python","apache-beam","pipeline","argument-type"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}