{"record":{"id":"881f9fd7ab26a79f","repo":"continuedev/continue","slug":"malformed-json-received-from-bedrock-decoded","errorCode":null,"errorMessage":"Malformed JSON received from Bedrock: ${decoded}","messagePattern":"Malformed JSON received from Bedrock: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"core/llm/llms/BedrockImport.ts","lineNumber":62,"sourceCode":"        sessionToken: credentials.sessionToken || \"\",\n      },\n    });\n\n    const input = this._generateInvokeModelCommandInput(prompt, options);\n    const command = new InvokeModelWithResponseStreamCommand(input);\n    const response = await client.send(command, { abortSignal: signal });\n\n    if (response.body) {\n      for await (const item of response.body) {\n        const decoder = new TextDecoder();\n        const decoded = decoder.decode(item.chunk?.bytes);\n        try {\n          const chunk = JSON.parse(decoded);\n          if (chunk.outputs[0].text) {\n            yield chunk.outputs[0].text;\n          }\n        } catch (e) {\n          throw new Error(`Malformed JSON received from Bedrock: ${decoded}`);\n        }\n      }\n    }\n  }\n\n  private _generateInvokeModelCommandInput(\n    prompt: string,\n    options: CompletionOptions,\n  ): any {\n    const payload = {\n      prompt: prompt,\n    };\n\n    return {\n      body: JSON.stringify(payload),\n      modelId: this.modelArn,\n      accept: \"application/json\",\n      contentType: \"application/json\",","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/continuedev/continue/blob/5522c6f44ca0ac3528b37244818fbfa39b5af470/core/llm/llms/BedrockImport.ts#L44-L80","documentation":"Thrown while streaming a completion from Bedrock when a decoded response chunk fails JSON.parse or does not contain the expected outputs[0].text shape. The full offending payload is included in the message. It indicates the invoke-model-with-response-stream body could not be parsed as a valid Bedrock completion event.","triggerScenarios":"Calling _streamComplete where Bedrock returns an error event, a partial/garbled event body (network truncation, proxy buffering), a model whose stream payload schema differs (missing outputs array), or a modelId that routes to a non-converse API with mismatched response format.","commonSituations":"Using a Bedrock model whose streaming format changed (e.g. new foundation model versions), a corporate proxy mangling chunked responses, or streaming with on-demand throughput dropping mid-stream.","solutions":["Inspect the ${decoded} payload in the message: an error JSON reveals the real cause (throttling, access denied)","Verify the modelId matches a model that supports invoke-model-with-response-stream in your region","Disable request/response compression or proxy buffering that could corrupt chunked SSE bytes","Retry the request: transient truncation usually succeeds on a second attempt"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  for await (const t of llm.streamComplete(prompt)) yield t;\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Malformed JSON received from Bedrock')) {\n    return retryStream(); // transient truncation often clears\n  }\n  throw e;\n}","preventionTips":["Bypass proxies that buffer/rewrite chunked streams for Bedrock endpoints","Verify the model supports invoke-model-with-response-stream","Retry once on malformed-chunk errors before failing"],"tags":["aws","bedrock","streaming","json","response-parsing"],"backgroundTag":"malformed-api-response","analyzedSha":"5522c6f44ca0ac3528b37244818fbfa39b5af470","analyzedAt":"2026-08-27T11:28:54.683Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}