{"record":{"id":"c697fc5068c7fa1f","repo":"sigoden/aichat","slug":"invalid-response-data-data-smithy-type-smith","errorCode":null,"errorMessage":"Invalid response data: {data} (smithy_type: {smithy_type})","messagePattern":"Invalid response data: (.+?) \\(smithy_type: (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/client/bedrock.rs","lineNumber":291,"sourceCode":"                                }\n                                let arguments: Value = function_arguments.parse().with_context(|| {\n                                    format!(\"Tool call '{function_name}' have non-JSON arguments '{function_arguments}'\")\n                                })?;\n                                handler.tool_call(ToolCall::new(\n                                    function_name.clone(),\n                                    arguments,\n                                    Some(function_id.clone()),\n                                ))?;\n                            }\n                        }\n                        _ => {}\n                    }\n                }\n                (\"exception\", _) => {\n                    let payload = base64_decode(message.payload())?;\n                    let data = String::from_utf8_lossy(&payload);\n\n                    bail!(\"Invalid response data: {data} (smithy_type: {smithy_type})\")\n                }\n                _ => {\n                    bail!(\"Unrecognized message, message_type: {message_type}, smithy_type: {smithy_type}\",);\n                }\n            }\n        }\n    }\n    Ok(())\n}\n\nasync fn embeddings(builder: RequestBuilder) -> Result<EmbeddingsOutput> {\n    let res = builder.send().await?;\n    let status = res.status();\n    let data: Value = res.json().await?;\n\n    if !status.is_success() {\n        catch_error(&data, status.as_u16())?;\n    }","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/client/bedrock.rs#L273-L309","documentation":"During Bedrock's smithy EventStream decoding, a message of type 'exception' arrives over the stream. The library base64-decodes the payload and bails with 'Invalid response data' including the payload text and its smithy_type. This is Bedrock signaling a mid-stream exception (e.g. ModelStreamErrorException, ThrottlingException) that the client surfaces verbatim.","triggerScenarios":"chat_completions_streaming receives an event-stream message with message_type == \"exception\"; the decoded payload text and smithy_type are included in the error message.","commonSituations":"Bedrock throttles the stream mid-generation (ThrottlingException), the model stream fails internally (ModelStreamErrorException/ModelTimeoutException), or a long-running generation exceeds service limits.","solutions":["Read smithy_type and the decoded payload in the message to identify the exact Bedrock exception","Implement retry with exponential backoff for throttling-type exceptions","Reduce request size (shorter prompt / smaller max_tokens) to avoid stream timeouts","Check service health and quota limits in the AWS console","Ensure SDK/region config is correct if the exception indicates validation failure"],"exampleFix":"// before\nmatch result { Err(e) if e.to_string().contains(\"Throttling\") => bail!(e), ... }\n// after: retry throttled stream errors\nlet out = loop {\n    match client.chat_completions_streaming(req).await {\n        Err(e) if e.to_string().contains(\"ThrottlingException\") => { tokio::time::sleep(backoff).await; backoff *= 2; }\n        other => break other,\n    }\n};","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"smithy_type: ThrottlingException\") => retry_with_backoff(),\n    Err(e) if e.to_string().contains(\"Invalid response data\") => log::error!(\"bedrock stream exception: {e}\"),\n    other => other?,\n}","preventionTips":["Parse smithy_type from the error string to branch on the exact Bedrock exception","Add retries for throttling/timeout stream exceptions","Keep request sizes moderate to avoid mid-stream timeouts","Monitor AWS service health and account quotas"],"tags":["aws","bedrock","streaming","event-stream","throttling"],"backgroundTag":"upstream-api-error","analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}