Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Bedrock API Call Wrapper - Not functioning with LangChain #11874

Open
schammah opened this issue Jan 8, 2025 · 0 comments
Open

[BUG]: Bedrock API Call Wrapper - Not functioning with LangChain #11874

schammah opened this issue Jan 8, 2025 · 0 comments
Labels

Comments

@schammah
Copy link

schammah commented Jan 8, 2025

Tracer Version(s)

2.18.1

Python Version(s)

3.9.15

Pip Version(s)

24.3.1

Bug Report

When combining langchain & langchain_community & langchain_aws the dd-trace library
Then the call to bedrock which is wrapped in the patched_bedrock_api_call method is broken

without the dd_trace library my code works fine

Reproduction Code

import all 3 modules
run the invoke method from the packgge: langchain_aws

either
prompt = ChatPromptTemplate.from_template(prompt_template)

llm = ChatBedrock(
    model_id=model_id,
    provider=provider,
    model_kwargs=model_kwargs

Error Logs

[ERROR] 2025-01-07T06:33:00.060Z 9adfd63f-5ae2-48eb-9b58-94aa8da56738 Error raised by bedrock service: too many values to unpack (expected 2)

full stacktrace:

2025-01-07T06:33:00.074Z
	
File "/var/task/common_lib/langchain_utils.py", line 97, in extract_information
	
2025-01-07T06:33:00.074Z
	
response = chain.invoke(params)
	
2025-01-07T06:33:00.074Z
	
File "./python/lib/python3.9/site-packages/ddtrace/contrib/trace_utils.py", line 335, in wrapper
	
2025-01-07T06:33:00.074Z
File "./python/lib/python3.9/site-packages/ddtrace/contrib/langchain/patch.py", line 771, in traced_lcel_runnable_sequence
	
File "./python/lib/python3.9/site-packages/ddtrace/contrib/langchain/patch.py", line 771, in traced_lcel_runnable_sequence
	
2025-01-07T06:33:00.074Z
	
File "/opt/python/langchain_core/runnables/base.py", line 3022, in invoke
	
2025-01-07T06:33:00.074Z
	
input = context.run(step.invoke, input, config)
	
2025-01-07T06:33:00.074Z
	
File "/opt/python/langchain_core/language_models/chat_models.py", line 286, in invoke
	
2025-01-07T06:33:00.074Z
	
self.generate_prompt(
	
2025-01-07T06:33:00.074Z
	
File "/opt/python/langchain_core/language_models/chat_models.py", line 786, in generate_prompt
	
2025-01-07T06:33:00.074Z
	
return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)
	
2025-01-07T06:33:00.074Z
	
File "./python/lib/python3.9/site-packages/ddtrace/contrib/trace_utils.py", line 335, in wrapper
	
2025-01-07T06:33:00.074Z
	
File "./python/lib/python3.9/site-packages/ddtrace/contrib/langchain/patch.py", line 392, in traced_chat_model_generate
	
2025-01-07T06:33:00.074Z
	
File "/opt/python/langchain_core/language_models/chat_models.py", line 643, in generate
	
2025-01-07T06:33:00.074Z
	
raise e
	
2025-01-07T06:33:00.074Z
	
File "/opt/python/langchain_core/language_models/chat_models.py", line 633, in generate
	
2025-01-07T06:33:00.074Z
	
self._generate_with_cache(
	
2025-01-07T06:33:00.074Z
	
File "/opt/python/langchain_core/language_models/chat_models.py", line 851, in _generate_with_cache
	
2025-01-07T06:33:00.074Z
	
result = self._generate(
	
2025-01-07T06:33:00.074Z
	
File "/opt/python/langchain_aws/chat_models/bedrock.py", line 561, in _generate
	
2025-01-07T06:33:00.074Z
	
completion, tool_calls, llm_output = self._prepare_input_and_invoke(
	
2025-01-07T06:33:00.074Z
	
File "/opt/python/langchain_aws/llms/bedrock.py", line 841, in _prepare_input_and_invoke
	
2025-01-07T06:33:00.074Z
	
raise e
	
2025-01-07T06:33:00.074Z
	
File "/opt/python/langchain_aws/llms/bedrock.py", line 827, in _prepare_input_and_invoke
	
2025-01-07T06:33:00.074Z
	
response = self.client.invoke_model(**request_options)
	
2025-01-07T06:33:00.074Z
	
File "/opt/python/botocore/client.py", line 569, in _api_call
	
2025-01-07T06:33:00.074Z
	
return self._make_api_call(operation_name, kwargs)
	
2025-01-07T06:33:00.074Z
	
File "./python/lib/python3.9/site-packages/ddtrace/contrib/trace_utils.py", line 335, in wrapper
	
2025-01-07T06:33:00.074Z
	
File "./python/lib/python3.9/site-packages/ddtrace/contrib/botocore/patch.py", line 158, in patched_api_call
	
2025-01-07T06:33:00.074Z
File "./python/lib/python3.9/site-packages/ddtrace/contrib/botocore/services/bedrock.py", line 321, in patched_bedrock_api_call
	
File "./python/lib/python3.9/site-packages/ddtrace/contrib/botocore/services/bedrock.py", line 321, in patched_bedrock_api_call
	
2025-01-07T06:33:00.074Z
	
ValueError: too many values to unpack (expected 2) 

Libraries in Use

langchain
langchain_community
langchain_aws

Operating System

running on lambda

@schammah schammah added the bug label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant