apache/pulsar · error · RestException
Failed to serialize input with error: %s. Please checkif inp
Error message
Failed to serialize input with error: %s. Please checkif input data conforms with the schema of the input topic.
What it means
When the trigger payload cannot be serialized for the input topic's schema (SchemaSerializationException), triggerFunction returns HTTP 400 with 'Failed to serialize input with error: %s. Please check if input data conforms with the schema of the input topic.' The message bytes you sent don't match the topic's declared schema.
Source
Thrown at pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java:1220
if (msg == null) {
break;
}
if (msg.getProperties().containsKey("__pfn_input_msg_id__")
&& msg.getProperties().containsKey("__pfn_input_topic__")) {
MessageId newMsgId = MessageId.fromByteArray(
Base64.getDecoder().decode((String) msg.getProperties().get("__pfn_input_msg_id__")));
if (msgId.equals(newMsgId)
&& msg.getProperties().get("__pfn_input_topic__")
.equals(TopicName.get(inputTopicToWrite).toString())) {
return new String(msg.getData());
}
}
curTime = System.currentTimeMillis();
}
throw new RestException(Status.REQUEST_TIMEOUT, "Request Timed Out");
} catch (SchemaSerializationException e) {
throw new RestException(Status.BAD_REQUEST, String.format(
"Failed to serialize input with error: %s. Please check"
+ "if input data conforms with the schema of the input topic.",
e.getMessage()));
} catch (IOException e) {
throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
} finally {
if (reader != null) {
reader.closeAsync();
}
if (producer != null) {
producer.closeAsync();
}
}
}
@Override
public FunctionState getFunctionState(final String tenant,
final String namespace,View on GitHub (pinned to 820761864e)
Solutions
- Read the embedded SchemaSerializationException message in the response to see the exact encode failure, then fix the payload to conform to the topic schema.
- Check the topic's schema (pulsar-admin schemas get) and craft the test payload accordingly (e.g., valid JSON for JSON schema, base64 Avro for Avro).
- If the schema changed recently, update the payload generator or restore the expected schema version.
- Trigger via a client that encodes with the topic's Schema object rather than raw bytes.
Example fix
// before
curl -X POST --data-binary 'not-json' .../functions/.../f?topic=avroTopic
// after: send schema-conformant payload
curl -X POST --data-binary '{"id":"1","value":42}' .../functions/.../f?topic=jsonTopic Defensive patterns
Strategy: validation
Validate before calling
// Encode the payload with the topic's schema before triggering
SchemaRecord record = new SchemaRecord("1", 42);
byte[] encoded = schema.encode(record); // throws immediately if it doesn't conform
assert encoded.length > 0; Try / catch
try { triggerFunction(..., payload, null); }
catch (PulsarAdminException e) {
if (e.getResponseStatus() == 400 && e.getMessage().contains("Failed to serialize"))
throw new SchemaMismatchException("payload violates topic schema: " + e.getMessage());
throw e;
} Prevention
- Fetch the topic schema (pulsar-admin schemas get) and generate payloads from it
- Use a Pulsar client producer with the topic's Schema to author test payloads instead of raw strings
- Re-run payload conformance checks whenever a topic schema is updated
When it happens
Trigger: Posting text/JSON to an input topic with Avro/Protobuf schema; sending data that violates the topic's schema (wrong types, missing required fields); schema changed on the topic after the trigger script was written.
Common situations: Testing an Avro-schema topic with plain strings from curl; schema registry updates (topic schema evolved, old payloads rejected); passing numeric data as strings for typed schemas.
Related errors
- This method is not supported
- Not implemented for ${this.getClass}
- Unknown version ${BytesSchemaVersion.of(schemaVersion)}
- Can't get accurate schema information for topic ${topicName}
- Size of data received by BooleanSchema is not 1
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/427d34c4a64fd528.
Report an issue: GitHub.