{"record":{"id":"8c49ef346f99be26","repo":"apache/beam","slug":"unexpected-outputs-from-validation-list-validation-result","errorCode":null,"errorMessage":"Unexpected outputs from validation: {list(validation_result.keys())}","messagePattern":"Unexpected outputs from validation: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/yaml/yaml_transform.py","lineNumber":730,"sourceCode":"    outputs[main_output_key] = validation_result\n    return outputs\n\n  # The main output from validation is the good output.\n  main_tag = error_handling_spec.get('main_tag', 'good')\n  outputs[main_output_key] = validation_result.pop(main_tag)\n\n  if error_handling_spec:\n    error_output_tag = error_handling_spec['output']\n    if error_output_tag in validation_result:\n      schema_error_pcoll = validation_result.pop(error_output_tag)\n      # The original transform also had an error output. Merge them.\n      outputs[error_output_tag] = (\n          (outputs[error_output_tag], schema_error_pcoll)\n          | f'FlattenErrors_{main_output_key}' >> beam.Flatten())\n\n    # There should be no other outputs from validation.\n    if validation_result:\n      raise ValueError(\n          \"Unexpected outputs from validation: \"\n          f\"{list(validation_result.keys())}\")\n\n  return outputs\n\n\ndef _enforce_schema(pcoll, label, error_handling_spec, clean_schema):\n  \"\"\"Applies schema to PCollection elements if necessary, then validates.\n\n  This function ensures that the input PCollection conforms to a specified\n  schema. If the PCollection is schemaless (i.e., its element_type is Any),\n  it attempts to convert its elements into schema-aware `beam.Row` objects\n  based on the provided `clean_schema`. After ensuring the PCollection has\n  a defined schema, it applies a `Validate` transform to perform the actual\n  schema validation.\n\n  Args:\n    pcoll: The input PCollection to be schema-enforced and validated.","sourceCodeStart":712,"sourceCodeEnd":748,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/yaml_transform.py#L712-L748","documentation":"The Validate transform used for output_schema checking is expected to return only the main (good) output and, if configured, an error output. If validation_result still contains other keys after integrating the error output, _integrate_validation_results raises this ValueError — an internal invariant that the validation produced unexpected extra outputs.","triggerScenarios":"A Validate transform (or custom validation implementation) emits additional tagged outputs beyond the good/error outputs, e.g. three or more outputs or unexpected tag names, while output_schema integration expects exactly zero leftover keys.","commonSituations":"Custom Validate implementations or third-party validation transforms that add extra side outputs; version drift where a validation transform gained new outputs not handled by the YAML integration code.","solutions":["Ensure the validation step only produces the main output and the configured error output.","If using a custom Validate transform, drop or merge extra outputs before returning.","Check the Beam version — this can indicate an internal incompatibility; upgrade/downgrade apache-beam to matching versions.","File an issue with the Beam YAML team if a built-in Validate produces this."],"exampleFix":"// before (custom Validate)\ndef expand(self, pcoll):\n    return {'good': ok, 'bad': errors, 'stats': stats}\n// after\ndef expand(self, pcoll):\n    return {'output': ok, self._error_tag: errors}","handlingStrategy":"try-catch","validationCode":"def check_validate_outputs(result_keys, error_tag=None):\n    allowed = {'output', error_tag} - {None}\n    extra = set(result_keys) - allowed\n    if extra:\n        raise ValueError(f'Validate produced unexpected outputs: {extra}')","typeGuard":"def only_expected_keys(result: dict, allowed: set) -> bool:\n    return set(result) <= allowed","tryCatchPattern":"try:\n    expand_output_schema_transform(spec, outputs, eh)\nexcept ValueError as e:\n    if 'Unexpected outputs from validation' in str(e):\n        print('Validation transform emitted extra outputs; pin apache-beam version or fix custom Validate')\n    else:\n        raise","preventionTips":["Use the built-in Validate transform unmodified with output_schema.","Pin your apache-beam version; this indicates an internal contract break.","Custom validation transforms must return only good + error outputs."],"tags":["python","apache-beam","yaml","validation"],"backgroundTag":"unexpected-api-response-shape","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"}