{"record":{"id":"d81a9649cc9dd45b","repo":"apache/beam","slug":"a-schema-was-provided-without-a-data-format-or-viceversa","errorCode":null,"errorMessage":"A schema was provided without a data format (or viceversa). Please provide both of these parameters to read from Pubsub, or if you would like to use the Pubsub schema service, please leave both of these blank.","messagePattern":"A schema was provided without a data format \\(or viceversa\\)\\. Please provide both of these parameters to read from Pubsub, or if you would like to use the Pubsub schema service, please leave both of these blank\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubReadSchemaTransformProvider.java","lineNumber":93,"sourceCode":"\n  @Override\n  public SchemaTransform from(PubsubReadSchemaTransformConfiguration configuration) {\n    if (configuration.getSubscription() == null && configuration.getTopic() == null) {\n      throw new IllegalArgumentException(\n          \"To read from Pubsub, a subscription name or a topic name must be provided\");\n    }\n\n    if (configuration.getSubscription() != null && configuration.getTopic() != null) {\n      throw new IllegalArgumentException(\n          \"To read from Pubsub, a subscription name or a topic name must be provided. Not both.\");\n    }\n\n    if (!\"RAW\".equals(configuration.getFormat())) {\n      if ((Strings.isNullOrEmpty(configuration.getSchema())\n              && !Strings.isNullOrEmpty(configuration.getFormat()))\n          || (!Strings.isNullOrEmpty(configuration.getSchema())\n              && Strings.isNullOrEmpty(configuration.getFormat()))) {\n        throw new IllegalArgumentException(\n            \"A schema was provided without a data format (or viceversa). Please provide \"\n                + \"both of these parameters to read from Pubsub, or if you would like to use the Pubsub schema service,\"\n                + \" please leave both of these blank.\");\n      }\n    }\n\n    Schema payloadSchema;\n    SerializableFunction<byte[], Row> payloadMapper;\n\n    String format =\n        configuration.getFormat() == null ? null : configuration.getFormat().toUpperCase();\n    if (\"RAW\".equals(format)) {\n      payloadSchema = Schema.of(Schema.Field.of(\"payload\", Schema.FieldType.BYTES));\n      payloadMapper = input -> Row.withSchema(payloadSchema).addValue(input).build();\n    } else if (\"JSON\".equals(format)) {\n      payloadSchema = JsonUtils.beamSchemaFromJsonSchema(configuration.getSchema());\n      payloadMapper = JsonUtils.getJsonBytesToRowFunction(payloadSchema);\n    } else if (\"AVRO\".equals(format)) {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubReadSchemaTransformProvider.java#L75-L111","documentation":"For non-RAW formats, PubsubReadSchemaTransformProvider requires the 'schema' and 'format' configuration fields to be provided together or not at all. It throws when exactly one of the two is set, because it cannot know how to decode payloads with only a schema (no format) or only a format (no schema).","triggerScenarios":"Calling from() with a configuration Row where (schema is set and format is empty) OR (format is set and schema is empty), while format != \"RAW\".","commonSituations":"Users supplying a JSON schema but forgetting format=JSON; users setting format=AVRO but leaving the schema field empty; template variables that resolve to empty strings for one of the two fields.","solutions":["Set both 'schema' and 'format' in the configuration Row (e.g. an Avro/JSON schema plus format=AVRO/JSON).","Alternatively, leave BOTH empty to let the reader use the Pubsub schema service.","If payloads are opaque bytes, set format=RAW, which bypasses this check.","Check that empty-string template variables aren't silently filling only one of the two fields."],"exampleFix":"// before\nconfig = Config.builder().setSchema(avroSchemaString).build(); // format missing\n// after\nconfig = Config.builder().setSchema(avroSchemaString).setFormat(\"AVRO\").build();","handlingStrategy":"validation","validationCode":"boolean hasSchema = cfg.getSchema() != null && !cfg.getSchema().isEmpty();\nboolean hasFormat = cfg.getFormat() != null && !cfg.getFormat().isEmpty();\nif (!\"RAW\".equals(cfg.getFormat()) && hasSchema != hasFormat) { throw new IllegalArgumentException(\"schema and format must be provided together or both blank\"); }","typeGuard":null,"tryCatchPattern":"try { return provider.from(cfg); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"A schema was provided without a data format\")) { /* set both fields or both blank */ } throw e; }","preventionTips":["Always set schema and format as a pair from a single config object.","Remember the third valid option: leave both blank to use the Pubsub schema service.","Watch for template variables rendering as empty strings and filling only one field."],"tags":["java","apache-beam","pubsub","configuration"],"backgroundTag":"missing-required-config-field","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"}