{"record":{"id":"f1259dd0c064a652","repo":"apache/beam","slug":"s-hint-s-type-constraint-violated-all-s-should-be-of-type-s-f1259d","errorCode":null,"errorMessage":"%s hint %s-type constraint violated. All %s should be of type %s. Instead, %s is of type %s.","messagePattern":"(.+?) hint (.+?)-type constraint violated\\. All (.+?) 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":897,"sourceCode":"          isinstance(sub, self.__class__) and\n          is_consistent_with(sub.key_type, self.key_type) and\n          is_consistent_with(sub.value_type, self.value_type))\n\n    def _raise_hint_exception_or_inner_exception(\n        self, is_key, incorrect_instance, inner_error_message=''):\n      incorrect_type = 'values' if not is_key else 'keys'\n      hinted_type = self.value_type if not is_key else self.key_type\n      if inner_error_message:\n        raise CompositeTypeHintError(\n            '%s hint %s-type constraint violated. All %s should be of type '\n            '%s. Instead: %s' % (\n                repr(self),\n                incorrect_type[:-1],\n                incorrect_type,\n                repr(hinted_type),\n                inner_error_message))\n      else:\n        raise CompositeTypeHintError(\n            '%s hint %s-type constraint violated. All %s should be of '\n            'type %s. Instead, %s is of type %s.' % (\n                repr(self),\n                incorrect_type[:-1],\n                incorrect_type,\n                repr(hinted_type),\n                incorrect_instance,\n                incorrect_instance.__class__.__name__))\n\n    def type_check(self, dict_instance):\n      if not isinstance(dict_instance, dict):\n        raise CompositeTypeHintError(\n            'Dict type-constraint violated. All passed instances must be of '\n            'type dict. %s is of type %s.' %\n            (dict_instance, dict_instance.__class__.__name__))\n\n      for key, value in dict_instance.items():\n        try:","sourceCodeStart":879,"sourceCodeEnd":915,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/typehints/typehints.py#L879-L915","documentation":"Raised by DictConstraint's _raise_hint_exception_or_inner_exception when a dict key or value fails a simple-type check; it names the offending instance and its runtime class. Emitted from type_check for every key/value pair scanned.","triggerScenarios":"{'a': 'x'} against Dict[str, int]; an int key against Dict[str, int]; None values where a concrete type is hinted.","commonSituations":"JSON-parsed dicts with mixed value types; inconsistent records merged into one dict; Optional values not wrapped in Optional[...] hints.","solutions":["Coerce or fix the reported key/value to the hinted type","Filter or transform offending entries before the hinted transform","Widen the hint, e.g. Dict[str, Union[int, str]] or Optional values","Add upstream validation of dict entries"],"exampleFix":"# before\nDict[str, int]: {'a': '5'}\n# after\n{'a': int('5')}","handlingStrategy":"validation","validationCode":"bad = [(k, type(v).__name__) for k, v in d.items() if not isinstance(v, int)]\nif bad: raise ValueError(f'non-int values: {bad}')","typeGuard":"def all_values_type(d, t): return isinstance(d, dict) and all(isinstance(v, t) for v in d.values())","tryCatchPattern":null,"preventionTips":["Coerce value types when building dicts from parsed data","Use Union[...] hints for legitimately mixed values"],"tags":["python","apache-beam","type-hints","dict"],"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"}