{"record":{"id":"0b35ff2fe74436b9","repo":"apache/beam","slug":"raw-format-does-not-take-a-schema","errorCode":null,"errorMessage":"RAW format does not take a schema","messagePattern":"RAW format does not take a schema","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/yaml/yaml_io.py","lineNumber":246,"sourceCode":"\n  return WriteToBigQueryHandlingErrors()\n\n\ndef _create_parser(\n    format,\n    schema: Any) -> tuple[schema_pb2.Schema, Callable[[bytes], beam.Row]]:\n\n  format = format.upper()\n\n  def _validate_schema():\n    if not schema:\n      raise ValueError(\n          f'{format} format requires valid {format} schema to be passed to '\n          f'schema parameter.')\n\n  if format == 'RAW':\n    if schema:\n      raise ValueError('RAW format does not take a schema')\n    return (\n        schema_pb2.Schema(fields=[schemas.schema_field('payload', bytes)]),\n        lambda payload: beam.Row(payload=payload))\n  if format == 'STRING':\n    if schema:\n      raise ValueError('STRING format does not take a schema')\n    return (\n        schema_pb2.Schema(fields=[schemas.schema_field('payload', str)]),\n        lambda payload: beam.Row(payload=payload.decode('utf-8')))\n  elif format == 'JSON':\n    _validate_schema()\n    beam_schema = json_utils.json_schema_to_beam_schema(schema)\n    return beam_schema, json_utils.json_parser(beam_schema, schema)\n  elif format == 'AVRO':\n    _validate_schema()\n    beam_schema = avroio.avro_schema_to_beam_schema(schema)\n    covert_to_row = avroio.avro_dict_to_beam_row(schema, beam_schema)\n    return (","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/yaml_io.py#L228-L264","documentation":"For the 'RAW' format in _create_parser (read_from_pubsub), each message is treated as opaque bytes mapped to a single 'payload' field, so no schema is meaningful. If a schema is supplied anyway, the wrapper raises ValueError('RAW format does not take a schema').","triggerScenarios":"Calling read_from_pubsub with format='RAW' and a non-empty schema argument; leaving a schema configured while switching format from JSON/AVRO to RAW.","commonSituations":"Switching formats in an existing pipeline config and forgetting to remove the now-unneeded schema field.","solutions":["Remove the schema parameter when format is 'RAW'.","If a schema is genuinely needed to parse structured messages, keep format as 'JSON'/'AVRO'/'PROTO' instead.","Use 'STRING' for plain text messages (also schema-less)."],"exampleFix":"// before\n- type: ReadFromPubSub\n  format: RAW\n  schema: '{...}'\n// after\n- type: ReadFromPubSub\n  format: RAW","handlingStrategy":"validation","validationCode":"if fmt.upper() == 'RAW' and schema:\n    raise ValueError(\"Drop 'schema' when format is RAW\")","typeGuard":null,"tryCatchPattern":"try:\n    read_from_pubsub(format='RAW', schema=schema)\nexcept ValueError as e:\n    if 'RAW format does not take a schema' in str(e):\n        schema = None","preventionTips":["When changing 'format', audit sibling fields in the same transform block.","Encode format/schema compatibility rules in config validation.","Keep RAW and JSON variants as separate, minimal YAML snippets."],"tags":["python","apache-beam","yaml","pubsub","conflicting-options"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}