bedrock prepare input not work properly for all models #28901
Labels
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
investigate
Flagged for investigation.
Checked other resources
Example Code
from langchain_community.chat_models import BedrockChat
config = {
"model_id": "amazon.nova-lite-v1:0",
'model_kwargs': {
"max_tokens": 1000,
"temperature": 0.7
}
}
llm = BedrockChat(**config)
llm.invoke('hi')
Error Message and Stack Trace (if applicable)
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/langchain_community/llms/bedrock.py", line 547, in _prepare_input_and_invoke
response = self.client.invoke_model(**request_options)
File "/usr/local/lib/python3.9/site-packages/botocore/client.py", line 569, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.9/site-packages/botocore/client.py", line 1023, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the InvokeModel operation: Malformed input request: #: required key [messages] not found, please reformat your input and try again.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.9/site-packages/langchain_core/language_models/chat_models.py", line 286, in invoke
self.generate_prompt(
File "/usr/local/lib/python3.9/site-packages/langchain_core/language_models/chat_models.py", line 786, in generate_prompt
return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)
File "/usr/local/lib/python3.9/site-packages/langchain_core/language_models/chat_models.py", line 643, in generate
raise e
File "/usr/local/lib/python3.9/site-packages/langchain_core/language_models/chat_models.py", line 633, in generate
self._generate_with_cache(
File "/usr/local/lib/python3.9/site-packages/langchain_core/language_models/chat_models.py", line 851, in _generate_with_cache
result = self._generate(
File "/usr/local/lib/python3.9/site-packages/langchain_community/chat_models/bedrock.py", line 299, in _generate
completion, usage_info = self._prepare_input_and_invoke(
File "/usr/local/lib/python3.9/site-packages/langchain_community/llms/bedrock.py", line 554, in _prepare_input_and_invoke
raise ValueError(f"Error raised by bedrock service: {e}")
ValueError: Error raised by bedrock service: An error occurred (ValidationException) when calling the InvokeModel operation: Malformed input request: #: required key [messages] not found, please reformat your input and try again.
Description
the problem ins on prepare input of langchain_community.llms.bedrock.py lane 112 aprox
@classmethod
def prepare_input(
the body is not seted correctly for this model it works for titan but not for the nova for example
System Info
pip freeze
aiohappyeyeballs==2.4.4
aiohttp==3.11.11
aiosignal==1.3.2
annotated-types==0.7.0
anyio==4.7.0
async-timeout==4.0.3
attrs==24.3.0
boto3==1.35.85
botocore==1.35.85
cachetools==5.5.0
certifi==2024.12.14
charset-normalizer==3.4.0
dataclasses-json==0.6.7
exceptiongroup==1.2.2
filetype==1.2.0
frozenlist==1.5.0
google-ai-generativelanguage==0.6.10
google-api-core==2.24.0
google-api-python-client==2.156.0
google-auth==2.37.0
google-auth-httplib2==0.2.0
google-generativeai==0.8.3
googleapis-common-protos==1.66.0
greenlet==3.1.1
grpcio==1.68.1
grpcio-status==1.68.1
h11==0.14.0
httpcore==1.0.7
httplib2==0.22.0
httpx==0.28.1
httpx-sse==0.4.0
idna==3.10
jmespath==1.0.1
jsonpatch==1.33
jsonpointer==3.0.0
langchain==0.3.13
langchain-community==0.3.13
langchain-core==0.3.28
langchain-google-genai==2.0.7
langchain-text-splitters==0.3.4
langgraph==0.2.60
langgraph-checkpoint==2.0.9
langgraph-sdk==0.1.48
langsmith==0.2.4
marshmallow==3.23.2
msgpack==1.1.0
multidict==6.1.0
mypy-extensions==1.0.0
numpy==1.26.4
orjson==3.10.12
packaging==24.2
propcache==0.2.1
proto-plus==1.25.0
protobuf==5.29.2
pyasn1==0.6.1
pyasn1_modules==0.4.1
pydantic==2.10.4
pydantic-settings==2.7.0
pydantic_core==2.27.2
pyparsing==3.2.0
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
PyYAML==6.0.2
requests==2.32.3
requests-toolbelt==1.0.0
rsa==4.9
s3transfer==0.10.4
six==1.17.0
sniffio==1.3.1
SQLAlchemy==2.0.36
tenacity==9.0.0
tqdm==4.67.1
typing-inspect==0.9.0
typing_extensions==4.12.2
uritemplate==4.1.1
urllib3==1.26.20
yarl==1.18.3
The text was updated successfully, but these errors were encountered: