Skip to content

Commit

Permalink
community[patch]: Add explicit error message to Bedrock error output. (
Browse files Browse the repository at this point in the history
…langchain-ai#17328)

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

---------

Co-authored-by: Bagatur <[email protected]>
  • Loading branch information
2 people authored and gkorland committed Mar 30, 2024
1 parent d31c802 commit 9724ed5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libs/community/langchain_community/document_loaders/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ def __init__(
raise ValueError(
"Could not load credentials to authenticate with AWS client. "
"Please check that credentials in the specified "
"profile name are valid."
f"profile name are valid. {e}"
) from e
self.parser = AmazonTextractPDFParser(
textract_features=features,
Expand Down
2 changes: 1 addition & 1 deletion libs/community/langchain_community/embeddings/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def validate_environment(cls, values: Dict) -> Dict:
raise ValueError(
"Could not load credentials to authenticate with AWS client. "
"Please check that credentials in the specified "
"profile name are valid."
f"profile name are valid. Bedrock error: {e}"
) from e

return values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def validate_environment(cls, values: Dict) -> Dict:
raise ValueError(
"Could not load credentials to authenticate with AWS client. "
"Please check that credentials in the specified "
"profile name are valid."
f"profile name are valid. {e}"
) from e

except ImportError:
Expand Down
4 changes: 3 additions & 1 deletion libs/community/langchain_community/llms/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,13 @@ def validate_environment(cls, values: Dict) -> Dict:
"Could not import boto3 python package. "
"Please install it with `pip install boto3`."
)
except ValueError as e:
raise ValueError(f"Error raised by bedrock service: {e}")
except Exception as e:
raise ValueError(
"Could not load credentials to authenticate with AWS client. "
"Please check that credentials in the specified "
"profile name are valid."
f"profile name are valid. Bedrock error: {e}"
) from e

return values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def create_client(cls, values: Dict[str, Any]) -> Dict[str, Any]:
raise ValueError(
"Could not load credentials to authenticate with AWS client. "
"Please check that credentials in the specified "
"profile name are valid."
f"profile name are valid. {e}"
) from e

@property
Expand Down

0 comments on commit 9724ed5

Please sign in to comment.