{"record":{"id":"09a555e2914e5acc","repo":"spring-projects/spring-ai","slug":"invalid-json-format-for-the-response","errorCode":null,"errorMessage":"Invalid JSON format for the response: ","messagePattern":"Invalid JSON format for the response: ","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/api/AbstractBedrockApi.java","lineNumber":254,"sourceCode":"\t\t}\n\t\tcatch (JacksonException e) {\n\t\t\tthrow new IllegalArgumentException(\"Invalid JSON format for the input request: \" + request, e);\n\t\t}\n\n\t\tInvokeModelRequest invokeRequest = InvokeModelRequest.builder()\n\t\t\t\t.modelId(this.modelId)\n\t\t\t\t.body(body)\n\t\t\t\t.build();\n\n\t\tInvokeModelResponse response = this.client.invokeModel(invokeRequest);\n\n\t\tString responseBody = response.body().asString(StandardCharsets.UTF_8);\n\n\t\ttry {\n\t\t\treturn this.jsonMapper.readValue(responseBody, clazz);\n\t\t}\n\t\tcatch (JacksonException e) {\n\t\t\tthrow new IllegalArgumentException(\"Invalid JSON format for the response: \" + responseBody, e);\n\t\t}\n\t}\n\n\t/**\n\t * Internal method to invoke the model and return the response stream.\n\t *\n\t * @param request Model invocation request.\n\t * @param clazz Response class type.\n\t * @return The model invocation response stream.\n\t */\n\tprotected Flux<SO> internalInvocationStream(I request, Class<SO> clazz) {\n\n\t\t// final Sinks.Many<SO> eventSink = Sinks.many().unicast().onBackpressureError();\n\t\tfinal Sinks.Many<SO> eventSink = Sinks.many().multicast().onBackpressureBuffer();\n\n\t\tSdkBytes body;\n\t\ttry {\n\t\t\tbody = SdkBytes.fromUtf8String(this.jsonMapper.writeValueAsString(request));","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-bedrock/src/main/java/org/springframework/ai/bedrock/api/AbstractBedrockApi.java#L236-L272","documentation":"After invoking the Bedrock model, internalInvocation deserializes the HTTP response body into the response class with Jackson. If the body is not valid JSON or does not match the target type, the JacksonException is wrapped in an IllegalArgumentException containing the raw response body, signaling an unexpected or malformed response from Bedrock.","triggerScenarios":"Bedrock returns a non-JSON body (error page, throttling/HTML message) or JSON whose shape does not fit the expected response class while calling readValue(responseBody, clazz).","commonSituations":"AWS throttling/access-denied errors returned in unexpected format; wrong response class for the modelId; Bedrock model output exceeding limits and truncated responses; Jackson module/version mismatches.","solutions":["Inspect the response body in the message to identify what Bedrock actually returned (often an AWS error message)","Verify the modelId matches the response class expected by the API client","Check AWS credentials/permissions and retry limits so Bedrock stops returning error payloads","Ensure Jackson can deserialize the target type (modules, constructors, @JsonProperty mappings)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { return api.internalInvocation(request, clazz); } catch (IllegalArgumentException e) { String body = e.getMessage(); log.error(\"Unexpected Bedrock response: {}\", body); throw new AwsResponseException(body, e); }","preventionTips":["Log raw response bodies to spot AWS error payloads","Match response classes to the configured modelId","Handle AWS throttling/access errors and retries before parsing","Keep Jackson mappings current with model response schemas"],"tags":["bedrock","jackson","deserialization","aws"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}