FlowiseAI/Flowise · error · Error
An invalid response was returned by Bedrock.
Error message
An invalid response was returned by Bedrock.
What it means
embedTextTitan catches any failure while decoding the Bedrock InvokeModel response body or reading the `.embedding` field. If JSON.parse throws (non-JSON body) or `.embedding` is undefined/ non-numeric, this generic message fires — masking whether the issue is transport, model, or response shape.
Source
Thrown at packages/components/nodes/embeddings/AWSBedrockEmbedding/AWSBedrockEmbedding.ts:214
const embedTextTitan = async (text: string, client: BedrockRuntimeClient, model: string): Promise<number[]> => {
const cleanedText = text.replace(/\n/g, ' ')
const res = await client.send(
new InvokeModelCommand({
modelId: model,
body: JSON.stringify({
inputText: cleanedText
}),
contentType: 'application/json',
accept: 'application/json'
})
)
try {
const body = new TextDecoder().decode(res.body)
return JSON.parse(body).embedding
} catch (e) {
throw new Error('An invalid response was returned by Bedrock.')
}
}
const embedTextCohere = async (texts: string[], client: BedrockRuntimeClient, model: string, inputType: string): Promise<number[][]> => {
const cleanedTexts = texts.map((text) => text.replace(/\n/g, ' '))
const command = {
modelId: model,
body: JSON.stringify({
texts: cleanedTexts,
input_type: inputType,
truncate: 'END'
}),
contentType: 'application/json',
accept: 'application/json'
}
const res = await client.send(new InvokeModelCommand(command))
try {View on GitHub (pinned to abe4a8601a)
Solutions
- Confirm modelId is an embedding model (amazon.titan-embed-* ) and is enabled in the region.
- Log res.body and the parsed JSON before reading .embedding to see the actual shape.
- Verify IAM permissions include bedrock:InvokeModel for the model.
- Pin the AWS SDK version; check for region/model availability changes.
- Handle non-JSON bodies explicitly instead of relying on the catch-all.
Example fix
// before
try {
const body = new TextDecoder().decode(res.body)
return JSON.parse(body).embedding
} catch (e) {
throw new Error('An invalid response was returned by Bedrock.')
}
// after
const body = new TextDecoder().decode(res.body)
let parsed: any
try { parsed = JSON.parse(body) } catch (e) {
throw new Error(`Bedrock returned non-JSON for model ${model}: ${body.slice(0, 200)}`)
}
if (!parsed || !Array.isArray(parsed.embedding)) {
throw new Error(`Bedrock response missing 'embedding' for model ${model}: ${body.slice(0, 200)}`)
}
return parsed.embedding Defensive patterns
Strategy: try-catch
Validate before calling
import { BedrockRuntimeClient } from '@aws-sdk/client-bedrock-runtime'
// pre-check the model is an embed model enabled in region
if (!/titan-embed/i.test(model)) throw new Error(`${model} is not a Titan embedding model`) Type guard
interface TitanEmbedResponse { embedding: number[] }
function isTitanEmbedResponse(v: unknown): v is TitanEmbedResponse {
return !!v && Array.isArray((v as any).embedding)
} Try / catch
const body = new TextDecoder().decode(res.body)
let parsed: any
try { parsed = JSON.parse(body) } catch (e) {
throw new Error(`Titan embed: non-JSON body from Bedrock (model=${model}): ${body.slice(0, 200)}`)
}
if (!isTitanEmbedResponse(parsed)) {
throw new Error(`Titan embed: response missing 'embedding' (model=${model}): ${body.slice(0, 200)}`)
}
return parsed.embedding Prevention
- Confirm modelId is a Titan embed model and is enabled in the region.
- Verify IAM bedrock:InvokeModel permission for the model.
- Pin the AWS SDK version; retest when upgrading.
- Log the raw response body when shape validation fails.
When it happens
Trigger: Bedrock returns 200 with an unexpected body for a Titan embed call — e.g. wrong modelId returning an error object, truncated response, IAM allowing invoke but model not enabled in region, or a model that returns a different JSON key.
Common situations: modelId typo (e.g. a generation model instead of an embed model), model not enabled in the configured region, response throttled into a non-JSON error, or a Bedrock SDK version changing the body encoding.
Related errors
- Model ID is required
- Input Type must be selected for Cohere models.
- Failed to load file ${filePath} using unstructured loader.
- Failed to process binary file: ${error.message}
- Failed to scrape URL. Error: ${responseData.error}
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/4378af081a483bb6.
Report an issue: GitHub.