Surface underlying error on bedrock integration instead of assuming connection issue
In the bedrock components, document_embeder.py#L219, generator.py#L236, there is an exception catch on run which then produces a message about it being a connection error regardless of the underlying issue.
except ClientError as exception:
msg = (
f"Could not connect to Amazon Bedrock model {self.model}. "
f"Make sure your AWS environment is configured correctly, "
f"the model is available in the configured AWS region, and you have access."
)
raise AmazonBedrockInferenceError(msg) from exception
This assumes it's always the connection issue and is misleading in cases there is another underlying issue (e.g. the token count being too high).
Desired behavior
It should either surface the underlying error directly or configure the message to be specific to possible / common issues.
In this sense, the ranker handling seems to be better:
For more context, I got this issue while running AmazonBedrockTextEmbedder with a short query as well
from haystack_integrations.components.embedders.amazon_bedrock import AmazonBedrockTextEmbedder
embedder_model = "amazon.titan-embed-text-v2:0" # Could not connect to Amazon Bedrock model amazon.titan-embed-text-v2:0. Make sure your AWS environment is configured correctly, the model is available in the configured AWS region, and you have access.
embedder = AmazonBedrockTextEmbedder(model=embedder_model)
embedder.run(text="This is a test query")
Hey! I see that the ChatGenerator is handling errors differently https://github.com/deepset-ai/haystack-core-integrations/blob/653aa2492e4713c744d6934650ac20cfab1c5971/integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py#L429-L431
An example exception with a conversation missing a user message:
haystack_integrations.common.amazon_bedrock.errors.AmazonBedrockInferenceError: Could not generate inference for Amazon Bedrock model anthropic.claude-3-haiku-20240307-v1:0 due: An error occurred (ValidationException) when calling the Converse operation: A conversation must start with a user message. Try again with a conversation that starts with a user message.
The original exception can also be inspected in detail in the stacktrace.
@bglearning @bilgeyucel If you agree, I would use this approach across all Bedrock components. LMK!
@bglearning new version has been released v3.7.0!