-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Checked other resources
- This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
- I added a very descriptive title to this issue.
- I searched the LangChain.js documentation with the integrated search.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangChain.js rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
chain.invoke([message], {metadata: {foo: 'bar314'}});
Error Message and Stack Trace (if applicable)
No response
Description
I trying to pass custom metadata to my chain invocation using langchain to interact with AWS Bedrock Claude models (>=3.5).
chain.invoke([message], {metadata: {foo: 'bar314'}});
metadata
is supported as per langchain docs (https://v03.api.js.langchain.com/interfaces/_langchain_aws.ChatBedrockConverseCallOptions.html#metadata)
requesMetadata
is supported on AWS Bedrock SDK calls (https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html#bedrock-runtime_Converse-request-requestMetadata)
Expectation is that my metadata would be mapped to requestMetadata in the HTTP Request payload.
Observed behaviour is that the metadata is not included in the HTTP Request payload.
Issue appears related to this statement delete callOptions.metadata;
_separateRunnableConfigFromCallOptions in runnables.base.ts:374 (https://github.com/langchain-ai/langchainjs/blob/main/langchain-core/src/runnables/base.ts#L374C24-L374C32) which deletes metadata in what then becomes the object used to parametrise the command to bedrock.
Manually adding a statement like callOptions.requestMetadata = callOptions.metadata
before said attribute is deleted seems to fix the issue. Obviously this is not a full solution as not all models would support the requestMetadata attribute, so just adding that statement has potential to break integration with other providers.
System Info
Node v18.18.2, latest release of langchain