langchain-ai / langchain-aws-template

Build Generative AI applications with Langchain on AWS
Other
172 stars 49 forks source link

KeyError: 'message' occasionally on completions #25

Open awsgoley opened 6 months ago

awsgoley commented 6 months ago

I occasionally get a the following error on completions:

KeyError: 'message'

Here's the stack:

  File ".../langchain_aws/chat_models/bedrock.py", line 361, in _generate
    for chunk in self._stream(messages, stop, run_manager, **kwargs):
  File ".../langchain_aws/chat_models/bedrock.py", line 339, in _stream
    for chunk in self._prepare_input_and_invoke_stream(
  File ".../langchain_aws/llms/bedrock.py", line 653, in _prepare_input_and_invoke_stream
    for chunk in LLMInputOutputAdapter.prepare_output_stream(
  File ".../langchain_aws/llms/bedrock.py", line 239, in prepare_output_stream
    chunk_obj[output_key]

Here are my langchain versions:

langchain                  0.1.20
langchain-anthropic        0.1.11
langchain-aws              0.1.3
langchain-community        0.0.38
langchain-core             0.1.52
langchain-experimental     0.0.58
langchain-text-splitters   0.0.1
langgraph                  0.0.48

Python version: Python 3.11.6 Model Id: anthropic.claude-3-sonnet-20240229-v1:0

The error is intermittent. It appears to be an issue with the response that Bedrock is generating.