apache/beam · error · ValueError

Malformed type .

Error message

Malformed type {json_type}.

What it means

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 ...').

Solutions

  1. Use full schema objects: {"type": "string"} instead of the bare string "string"
  2. If the value is a union like ["string", "null"], pick a concrete type or mark nullable via the required list instead
  3. Inspect the offending schema fragment and ensure every entry under 'properties' is a dict with a 'type' key

Example fix

// before
{"properties": {"name": "string"}}
// after
{"properties": {"name": {"type": "string"}}}
Defensive patterns

Strategy: type-guard

Validate before calling

def assert_schema_type_entry(t):
    if not isinstance(t, dict) or 'type' not in t:
        raise ValueError(f'Each schema entry must be a dict with a type key, got {t!r}')

Type guard

def is_type_def(t) -> bool:
    return isinstance(t, dict) and isinstance(t.get('type'), str) and not isinstance(t.get('type'), list)

Try / catch

try:
    beam_type = json_type_to_beam_type(t)
except ValueError as e:
    raise ValueError(f'Malformed type definition {t!r}: use {"type": "string"} style') from e

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/af7e4acc6c2869f3. Report an issue: GitHub.

Appendix: source

Thrown at sdks/python/apache_beam/yaml/json_utils.py:86

    # Technically this is a valid (vacuous) schema, but as it's not generally
    # meaningful, throw an informative error instead.
    # (We could add a flag to allow this degenerate case.)
    raise ValueError('Missing properties for {json_schema}.')
  required = set(json_schema.get('required', []))
  return schema_pb2.Schema(
      fields=[
          schemas.schema_field(
              name,
              maybe_nullable(json_type_to_beam_type(t), name not in required),
              description=t.get('description') if isinstance(t, dict) else None)
          for (name, t) in json_schema['properties'].items()
      ])


def json_type_to_beam_type(json_type: dict[str, Any]) -> schema_pb2.FieldType:
  """Returns a Beam schema type for the given Json (schema) type."""
  if not isinstance(json_type, dict) or 'type' not in json_type:
    raise ValueError(f'Malformed type {json_type}.')
  type_name = json_type['type']
  if type_name in JSON_ATOMIC_TYPES_TO_BEAM:
    return schema_pb2.FieldType(
        atomic_type=JSON_ATOMIC_TYPES_TO_BEAM[type_name])
  elif type_name == 'array':
    return schema_pb2.FieldType(
        array_type=schema_pb2.ArrayType(
            element_type=json_type_to_beam_type(json_type['items'])))
  elif type_name == 'object':
    if 'properties' in json_type:
      return schema_pb2.FieldType(
          row_type=schema_pb2.RowType(
              schema=json_schema_to_beam_schema(json_type)))
    elif 'additionalProperties' in json_type:
      return schema_pb2.FieldType(
          map_type=schema_pb2.MapType(
              key_type=schema_pb2.FieldType(atomic_type=schema_pb2.STRING),
              value_type=json_type_to_beam_type(

View on GitHub (pinned to 12126d8942)