community[patch]: Add explicit error message to Bedrock error output. (#17328)

- **Description:** Propagate Bedrock errors into Langchain explicitly.
Use-case: unset region error is hidden behind 'Could not load
credentials...' message
- **Issue:**
[17654](https://github.com/langchain-ai/langchain/issues/17654)
  - **Dependencies:** None

---------

Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
This commit is contained in:
T Cramer 2024-03-29 03:07:33 +00:00 committed by GitHub
parent 69bb96c80f
commit 540ebf35a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 7 additions and 5 deletions

View File

@ -670,7 +670,7 @@ class AmazonTextractPDFLoader(BasePDFLoader):
raise ValueError( raise ValueError(
"Could not load credentials to authenticate with AWS client. " "Could not load credentials to authenticate with AWS client. "
"Please check that credentials in the specified " "Please check that credentials in the specified "
"profile name are valid." f"profile name are valid. {e}"
) from e ) from e
self.parser = AmazonTextractPDFParser( self.parser = AmazonTextractPDFParser(
textract_features=features, textract_features=features,

View File

@ -107,7 +107,7 @@ class BedrockEmbeddings(BaseModel, Embeddings):
raise ValueError( raise ValueError(
"Could not load credentials to authenticate with AWS client. " "Could not load credentials to authenticate with AWS client. "
"Please check that credentials in the specified " "Please check that credentials in the specified "
"profile name are valid." f"profile name are valid. Bedrock error: {e}"
) from e ) from e
return values return values

View File

@ -142,7 +142,7 @@ class SagemakerEndpointEmbeddings(BaseModel, Embeddings):
raise ValueError( raise ValueError(
"Could not load credentials to authenticate with AWS client. " "Could not load credentials to authenticate with AWS client. "
"Please check that credentials in the specified " "Please check that credentials in the specified "
"profile name are valid." f"profile name are valid. {e}"
) from e ) from e
except ImportError: except ImportError:

View File

@ -427,11 +427,13 @@ class BedrockBase(BaseModel, ABC):
"Could not import boto3 python package. " "Could not import boto3 python package. "
"Please install it with `pip install boto3`." "Please install it with `pip install boto3`."
) )
except ValueError as e:
raise ValueError(f"Error raised by bedrock service: {e}")
except Exception as e: except Exception as e:
raise ValueError( raise ValueError(
"Could not load credentials to authenticate with AWS client. " "Could not load credentials to authenticate with AWS client. "
"Please check that credentials in the specified " "Please check that credentials in the specified "
"profile name are valid." f"profile name are valid. Bedrock error: {e}"
) from e ) from e
return values return values

View File

@ -109,7 +109,7 @@ class AmazonComprehendModerationChain(Chain):
raise ValueError( raise ValueError(
"Could not load credentials to authenticate with AWS client. " "Could not load credentials to authenticate with AWS client. "
"Please check that credentials in the specified " "Please check that credentials in the specified "
"profile name are valid." f"profile name are valid. {e}"
) from e ) from e
@property @property