{"record":{"id":"3278b68fe39469d8","repo":"apache/beam","slug":"string-format-does-not-take-a-schema","errorCode":null,"errorMessage":"STRING format does not take a schema","messagePattern":"STRING format does not take a schema","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/yaml/yaml_io.py","lineNumber":252,"sourceCode":"    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 (\n        beam_schema, lambda record: covert_to_row(\n            fastavro.schemaless_reader(io.BytesIO(record), schema)))\n  elif format == 'PROTO':\n    _validate_schema()\n    beam_schema = json_utils.json_schema_to_beam_schema(schema)\n    return beam_schema, RowCoder(beam_schema).decode","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/yaml_io.py#L234-L270","documentation":"Analogous to RAW: the 'STRING' format in _create_parser decodes each Pub/Sub message as UTF-8 text into a single 'payload' string field, so no schema can be applied. Supplying one raises ValueError('STRING format does not take a schema').","triggerScenarios":"Calling read_from_pubsub with format='STRING' and schema set to a non-None/non-empty value.","commonSituations":"Leaving a JSON schema in the config after changing format from JSON to STRING; template configs that always include a schema field.","solutions":["Remove the schema parameter when format is 'STRING'.","Switch to format 'JSON' (with the schema) if messages are structured JSON.","Validate the YAML config so format and schema are consistent."],"exampleFix":"// before\n- type: ReadFromPubSub\n  format: STRING\n  schema: '{...}'\n// after\n- type: ReadFromPubSub\n  format: STRING","handlingStrategy":"validation","validationCode":"if fmt.upper() == 'STRING' and schema:\n    raise ValueError(\"Drop 'schema' when format is STRING\")","typeGuard":null,"tryCatchPattern":"try:\n    read_from_pubsub(format='STRING', schema=schema)\nexcept ValueError as e:\n    if 'STRING format does not take a schema' in str(e):\n        schema = None","preventionTips":["Pair each format with an explicit list of allowed options.","Lint YAML transforms to flag schema alongside schema-less formats.","Test configs end-to-end with a small local pipeline before production."],"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"}