{"record":{"id":"2d23531ca1314f88","repo":"apache/beam","slug":"tag-r-is-not-a-defined-output-tag-of-s","errorCode":null,"errorMessage":"Tag %r is not a defined output tag of %s.","messagePattern":"Tag %r is not a defined output tag of (.+?)\\.","errorType":"validation","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/ptransform.py","lineNumber":216,"sourceCode":"    self._result_id = result_id\n    self.elements = []  # type: list[Any]\n\n  def __reduce__(self):\n    # When unpickled (during Runner API roundtrip serailization), get the\n    # _MaterializedResult object from the cache so that values are written\n    # to the original _MaterializedResult when run in eager mode.\n    return (_get_materialized_result, (self._pipeline_id, self._result_id))\n\n\nclass _MaterializedDoOutputsTuple(pvalue.DoOutputsTuple):\n  def __init__(self, deferred, results_by_tag):\n    super().__init__(None, None, deferred._tags, deferred._main_tag)\n    self._deferred = deferred\n    self._results_by_tag = results_by_tag\n\n  def __getitem__(self, tag):\n    if tag not in self._results_by_tag:\n      raise KeyError(\n          'Tag %r is not a defined output tag of %s.' % (tag, self._deferred))\n    return self._results_by_tag[tag].elements\n\n\nclass _AddMaterializationTransforms(_PValueishTransform):\n  def _materialize_transform(self, pipeline):\n    result = _allocate_materialized_result(pipeline)\n\n    # Need to define _MaterializeValuesDoFn here to avoid circular\n    # dependencies.\n    from apache_beam import DoFn\n    from apache_beam import ParDo\n\n    class _MaterializeValuesDoFn(DoFn):\n      def __init__(self):\n        self.is_materialize_values_do_fn = True\n\n      def process(self, element):","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/ptransform.py#L198-L234","documentation":"After running a pipeline with materialized outputs, results are accessed per output tag via the materialized result mapping. If you index with a tag that wasn't a defined output tag of the deferred PTransform, a KeyError with this message is raised.","triggerScenarios":"result['wrong_tag'] on a _MaterializedResultBackedPCollectionView wrapper where the tag isn't in results_by_tag — e.g. misspelled tag or indexing a single-output transform with a made-up tag like 'out'.","commonSituations":"Multi-output transforms (DoFn with tagged outputs) where the developer indexes a tag not produced; copy-pasted tag names from other transforms.","solutions":["Index with a tag defined by the transform (main tag or one of deferred._tags).","Inspect the transform's output tags before indexing (e.g. deferred._tags).","Use the default indexing (no tag or MAIN_TAG) for single-output transforms."],"exampleFix":"// before\nresult['output']  # tag doesn't exist\n// after\nresult[beam.pvalue.TaggedOutput tag from transform]  # or result['main_tag'] as defined","handlingStrategy":"validation","validationCode":"available_tags = list(mat_result._deferred._tags)\nassert tag in available_tags or tag == mat_result._deferred._main_tag, f\"{tag!r} not in {available_tags}\"","typeGuard":null,"tryCatchPattern":"try:\n  elements = mat_result[tag]\nexcept KeyError:\n  elements = mat_result[mat_result._deferred._main_tag]","preventionTips":["List the transform's output tags before indexing","Use main tag for single-output transforms"],"tags":["python","apache-beam","pcollection"],"backgroundTag":"record-not-found","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"}