{"record":{"id":"3e08b0a50e7e1e0f","repo":"apache/beam","slug":"failed-to-serialize-input-batch","errorCode":null,"errorMessage":"Failed to serialize input batch","messagePattern":"Failed to serialize input batch","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/ml/inference/openai/src/main/java/org/apache/beam/sdk/ml/inference/openai/OpenAIModelHandler.java","lineNumber":133,"sourceCode":"              .flatMap(content -> content.outputText().stream())\n              .findFirst()\n              .orElse(null);\n\n      if (structuredOutput == null || structuredOutput.responses == null) {\n        throw new RuntimeException(\"Model returned no structured responses\");\n      }\n\n      // return PredictionResults\n      return structuredOutput.responses.stream()\n          .map(\n              response ->\n                  PredictionResult.create(\n                      OpenAIModelInput.create(response.input),\n                      OpenAIModelResponse.create(response.output)))\n          .collect(Collectors.toList());\n\n    } catch (JsonProcessingException e) {\n      throw new RuntimeException(\"Failed to serialize input batch\", e);\n    }\n  }\n\n  /**\n   * Schema class for structured output response.\n   *\n   * <p>Represents a single input-output pair returned by the OpenAI API.\n   */\n  public static class Response {\n    @JsonProperty(required = true)\n    @JsonPropertyDescription(\"The input string\")\n    public String input;\n\n    @JsonProperty(required = true)\n    @JsonPropertyDescription(\"The output string\")\n    public String output;\n  }\n","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/ml/inference/openai/src/main/java/org/apache/beam/sdk/ml/inference/openai/OpenAIModelHandler.java#L115-L151","documentation":"OpenAIModelHandler.request() serializes input batches when building the API request (and/or parsing the response) with Jackson. A JsonProcessingException — malformed request payload construction or unexpected JSON in the response — is caught and rethrown as a RuntimeException \"Failed to serialize input batch\" with the original exception as cause.","triggerScenarios":"request() called with InputT values that cannot be serialized to the expected JSON structure, or when the model returns JSON that Jackson cannot map during structured-output parsing.","commonSituations":"Custom input types lacking Jackson annotations or getters, non-UTF8/binary data in inputs, and model responses that are not valid JSON despite the JSON-mode request.","solutions":["Inspect the cause for the exact Jackson path/field that failed.","Annotate custom InputT/OutputT classes with Jackson-compatible getters or @JsonProperty mappings.","Validate that inputs contain only JSON-serializable values before batching.","Verify the model actually returns valid JSON (enable strict structured outputs)."],"exampleFix":"// before\nclass MyInput { public MyInput(String v) { this.v = v; } private String v; }\n// after\nclass MyInput { @JsonProperty public String getV() { return v; } private String v; }","handlingStrategy":"validation","validationCode":"new ObjectMapper().writeValueAsString(inputs); // dry-run serialize before calling handler","typeGuard":null,"tryCatchPattern":"try { results = handler.request(batch); } catch (RuntimeException e) { if (e.getCause() instanceof JsonProcessingException jpe) { LOG.error(\"Jackson path: {}\", jpe.getPath()); } throw e; }","preventionTips":["Give input/output POJOs Jackson-visible getters or records","Dry-run serialize representative inputs in tests","Reject non-JSON-serializable fields at input construction"],"tags":["java","json","jackson"],"backgroundTag":"json-serialization-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}