continuedev/continue · error · Error
Malformed JSON received from Bedrock: ${decoded}
Error message
Malformed JSON received from Bedrock: ${decoded} What it means
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.
Source
Thrown at core/llm/llms/BedrockImport.ts:62
sessionToken: credentials.sessionToken || "",
},
});
const input = this._generateInvokeModelCommandInput(prompt, options);
const command = new InvokeModelWithResponseStreamCommand(input);
const response = await client.send(command, { abortSignal: signal });
if (response.body) {
for await (const item of response.body) {
const decoder = new TextDecoder();
const decoded = decoder.decode(item.chunk?.bytes);
try {
const chunk = JSON.parse(decoded);
if (chunk.outputs[0].text) {
yield chunk.outputs[0].text;
}
} catch (e) {
throw new Error(`Malformed JSON received from Bedrock: ${decoded}`);
}
}
}
}
private _generateInvokeModelCommandInput(
prompt: string,
options: CompletionOptions,
): any {
const payload = {
prompt: prompt,
};
return {
body: JSON.stringify(payload),
modelId: this.modelArn,
accept: "application/json",
contentType: "application/json",View on GitHub (pinned to 5522c6f44c)
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
Defensive patterns
Strategy: retry
Try / catch
try {
for await (const t of llm.streamComplete(prompt)) yield t;
} catch (e) {
if (e instanceof Error && e.message.startsWith('Malformed JSON received from Bedrock')) {
return retryStream(); // transient truncation often clears
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- No stream received from Bedrock API
- AWS Bedrock stream error (${(error as any).code}): ${error.m
- AWS Bedrock rerank error (${(error as any).code}): ${error.m
- Error in BedrockReranker.rerank: ${error.message}
- Error in BedrockReranker.rerank: Unknown error occurred
AI-assisted analysis of continuedev/continue@5522c6f44c (2026-08-27).
Data as JSON: /api/errors/881f9fd7ab26a79f.
Report an issue: GitHub.