{"record":{"id":"af7e4acc6c2869f3","repo":"apache/beam","slug":"malformed-type-json-type","errorCode":null,"errorMessage":"Malformed type {json_type}.","messagePattern":"Malformed type (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/yaml/json_utils.py","lineNumber":86,"sourceCode":"    # Technically this is a valid (vacuous) schema, but as it's not generally\n    # meaningful, throw an informative error instead.\n    # (We could add a flag to allow this degenerate case.)\n    raise ValueError('Missing properties for {json_schema}.')\n  required = set(json_schema.get('required', []))\n  return schema_pb2.Schema(\n      fields=[\n          schemas.schema_field(\n              name,\n              maybe_nullable(json_type_to_beam_type(t), name not in required),\n              description=t.get('description') if isinstance(t, dict) else None)\n          for (name, t) in json_schema['properties'].items()\n      ])\n\n\ndef json_type_to_beam_type(json_type: dict[str, Any]) -> schema_pb2.FieldType:\n  \"\"\"Returns a Beam schema type for the given Json (schema) type.\"\"\"\n  if not isinstance(json_type, dict) or 'type' not in json_type:\n    raise ValueError(f'Malformed type {json_type}.')\n  type_name = json_type['type']\n  if type_name in JSON_ATOMIC_TYPES_TO_BEAM:\n    return schema_pb2.FieldType(\n        atomic_type=JSON_ATOMIC_TYPES_TO_BEAM[type_name])\n  elif type_name == 'array':\n    return schema_pb2.FieldType(\n        array_type=schema_pb2.ArrayType(\n            element_type=json_type_to_beam_type(json_type['items'])))\n  elif type_name == 'object':\n    if 'properties' in json_type:\n      return schema_pb2.FieldType(\n          row_type=schema_pb2.RowType(\n              schema=json_schema_to_beam_schema(json_type)))\n    elif 'additionalProperties' in json_type:\n      return schema_pb2.FieldType(\n          map_type=schema_pb2.MapType(\n              key_type=schema_pb2.FieldType(atomic_type=schema_pb2.STRING),\n              value_type=json_type_to_beam_type(","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/json_utils.py#L68-L104","documentation":"json_type_to_beam_type requires its argument to be a dict containing a 'type' key before it can map JSON types to Beam FieldTypes. If json_type is not a dict (e.g. a string like 'string' passed directly, or None) or lacks 'type', it raises ValueError('Malformed type ...').","triggerScenarios":"Passing a bare type name (e.g. \"string\") instead of a schema dict (e.g. {\"type\": \"string\"}) inside a properties entry; passing null; passing a list such as [\"string\",\"null\"] union form to json_type_to_beam_type via json_schema_to_beam_type.","commonSituations":"Confusing OpenAPI/Avro-style shorthand type names with JSON Schema type objects; JSON Schema union types (type as array) which this converter does not support; JSON5/YAML shorthand like name: string in pipeline YAML expanded differently than expected.","solutions":["Use full schema objects: {\"type\": \"string\"} instead of the bare string \"string\"","If the value is a union like [\"string\", \"null\"], pick a concrete type or mark nullable via the required list instead","Inspect the offending schema fragment and ensure every entry under 'properties' is a dict with a 'type' key"],"exampleFix":"// before\n{\"properties\": {\"name\": \"string\"}}\n// after\n{\"properties\": {\"name\": {\"type\": \"string\"}}}","handlingStrategy":"type-guard","validationCode":"def assert_schema_type_entry(t):\n    if not isinstance(t, dict) or 'type' not in t:\n        raise ValueError(f'Each schema entry must be a dict with a type key, got {t!r}')","typeGuard":"def is_type_def(t) -> bool:\n    return isinstance(t, dict) and isinstance(t.get('type'), str) and not isinstance(t.get('type'), list)","tryCatchPattern":"try:\n    beam_type = json_type_to_beam_type(t)\nexcept ValueError as e:\n    raise ValueError(f'Malformed type definition {t!r}: use {\"type\": \"string\"} style') from e","preventionTips":["Always write JSON Schema type definitions as full dicts: {\"type\": \"...\"}","Avoid union 'type' arrays (e.g. [\"string\",\"null\"]); encode nullability via 'required'","Never pass OpenAPI/Avro shorthand type strings into Beam yaml json_schema options"],"tags":["python","apache-beam","json-schema","type-system"],"backgroundTag":"invalid-argument-format","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"}