{"record":{"id":"9de75f0b9ffac6aa","repo":"apache/beam","slug":"s-hint-s-type-constraint-violated-all-ss-should-be-of-type-s-9de75f","errorCode":null,"errorMessage":"%s hint %s-type constraint violated. All %ss should be of type %s. Instead, %s is of type %s.","messagePattern":"(.+?) hint (.+?)-type constraint violated\\. All (.+?)s should be of type (.+?)\\. Instead, (.+?) is of type (.+?)\\.","errorType":"exception","errorClass":"CompositeTypeHintError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/typehints/typehints.py","lineNumber":1185,"sourceCode":"          return True\n      return False\n\n    def _raise_type_error(self, is_key, instance, inner_error_message=''):\n      type_desc = 'key' if is_key else 'value'\n      expected_type = self.key_type if is_key else self.value_type\n\n      if inner_error_message:\n        raise CompositeTypeHintError(\n            '%s hint %s-type constraint violated. All %ss should be of type '\n            '%s. Instead: %s' % (\n                repr(self),\n                type_desc,\n                type_desc,\n                repr(expected_type),\n                inner_error_message,\n            ))\n      else:\n        raise CompositeTypeHintError(\n            '%s hint %s-type constraint violated. All %ss should be of '\n            'type %s. Instead, %s is of type %s.' % (\n                repr(self),\n                type_desc,\n                type_desc,\n                repr(expected_type),\n                instance,\n                instance.__class__.__name__,\n            ))\n\n    def type_check(self, instance):\n      if not isinstance(instance, abc.Mapping):\n        raise CompositeTypeHintError(\n            'Mapping type-constraint violated. All passed instances must be of '\n            'type Mapping. %s is of type %s.' %\n            (instance, instance.__class__.__name__))\n\n      for key, value in instance.items():","sourceCodeStart":1167,"sourceCodeEnd":1203,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/typehints/typehints.py#L1167-L1203","documentation":"Raised when a value (or key) in a Dict/Mapping fails its declared type constraint and no nested composite error message exists — the report names the offending instance and its concrete class. It is thrown from Dict.type_check / Mapping.type_check while iterating items during runtime type validation.","triggerScenarios":"Returning a mapping annotated Dict[K, V] where some value is of a different class, e.g. .with_output_types(Dict[str, int]) but the dict contains {\"a\": 1.5} (float values), while type_check is enabled.","commonSituations":"Optional/None values slipping in (None is not the declared type); numpy numbers vs python ints; a lambda producing heterogeneous values; data schema drift after an upstream source change.","solutions":["Fix the producer so every value matches the declared value type, or convert values (e.g. int(v))","Widen the hint to the actual common type (e.g. Union[int, float]) or use Any","Skip/validate bad records before building the mapping"],"exampleFix":"// before\np | beam.Map(lambda d: {k: v for k, v in d.items()}).with_output_types(Dict[str, int])  # v can be float\n// after\np | beam.Map(lambda d: {k: int(v) for k, v in d.items()}).with_output_types(Dict[str, int])","handlingStrategy":"validation","validationCode":"ok = all(isinstance(v, value_type) for v in d.values())\n# assert ok before emitting the mapping","typeGuard":"def values_match_hint(d, value_type):\n    return isinstance(d, collections.abc.Mapping) and all(\n        isinstance(v, value_type) for v in d.values())","tryCatchPattern":"try:\n    typecheck.validate(Dict[str, int], result)\nexcept CompositeTypeHintError as e:\n    log.error('value type violation: %s', e)\n    result = {k: int(v) for k, v in result.items()}","preventionTips":["Normalize value types at ingestion (ints, floats, None handling)","Avoid Optional values under non-Optional hints; use Union[V, None] explicitly","Add unit assertions on DoFn outputs before enabling runtime checks"],"tags":["python","apache-beam","type-hints","dict","runtime-type-check"],"backgroundTag":"type-mismatch","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"}