Open
Description
Sample Code:
from langchain_aws import ChatBedrockConverse
model_id="us.anthropic.claude-3-5-haiku-20241022-v1:0"
llm1 = ChatBedrockConverse(model_id=model_id,disable_streaming=True)
llm1.invoke([HumanMessage(content=[{'type': 'text', 'text': 'For the earlier part, can you see if there are any updates'}], additional_kwargs={}, response_metadata={}, id='dbda63b2-4ed8-4d7c-ab51-219f82353cb6'),
AIMessage(content=[{'type': 'text', 'text': '\n\n', 'index': 0}], additional_kwargs={}),
HumanMessage(content="try again")])
Original Conversation
[HumanMessage(content=[{'type': 'text', 'text': 'For the earlier part, can you see if there are any updates'}], additional_kwargs={}, response_metadata={}, id='dbda63b2-4ed8-4d7c-ab51-219f82353cb6'),
AIMessage(content=[{'type': 'text', 'text': "I'd be happy to check for any updates regarding your earlier query. Let me search for the most current information.", 'index': 0}], additional_kwargs={}, response_metadata={'stopReason': 'tool_use', 'metrics': {'latencyMs': 4917}, 'llm': 'us.anthropic.claude-3-7-sonnet-20250219-v1:0'}, name='general', id='run-12a3ef27-eaa6-4ea8-857e-1031b066560c', tool_calls=[{'name': 'get_current_date', 'args': {}, 'id': 'tooluse_8Ke4pZdcS2C9DklgqMNFvw', 'type': 'tool_call'}], usage_metadata={'input_tokens': 39897, 'output_tokens': 77, 'total_tokens': 39974}),
ToolMessage(content='2025-03-13', name='get_current_date', id='006b1fc4-0162-42ae-a778-1e2eb9767e2b', tool_call_id='tooluse_8Ke4pZdcS2C9DklgqMNFvw'),
AIMessage(content=[{'type': 'text', 'text': '\n\n', 'index': 0}], additional_kwargs={}, response_metadata={'stopReason': 'tool_use', 'metrics': {'latencyMs': 6728}, 'llm': 'us.anthropic.claude-3-7-sonnet-20250219-v1:0'}, name='general', id='run-ba56d3ef-7adc-404a-8029-f1e38a2802bc', tool_calls=[{'name': 'execute_redshift_sql_query', 'args': {'query': "SELECT * FROM mytable"}, 'id': 'tooluse_v7fPQJREQSGs_CW-TmYlgg', 'type': 'tool_call'}], usage_metadata={'input_tokens': 39991, 'output_tokens': 48, 'total_tokens': 40039})]
Error:
---------------------------------------------------------------------------
ValidationException Traceback (most recent call last)
Cell In[50], line 4
1 from tools import AgentTools
2 tool=AgentTools({})
----> 4 llm1.invoke([HumanMessage(content=[{'type': 'text', 'text': 'For the earlier part, can you see if there are any updates'}], additional_kwargs={}, response_metadata={}, id='dbda63b2-4ed8-4d7c-ab51-219f82353cb6'),
5 AIMessage(content=[{'type': 'text', 'text': '\n\n', 'index': 0}], additional_kwargs={}),
6 HumanMessage(content="try again")])
File ~/lang-chain/.env/lib/python3.11/site-packages/langchain_core/language_models/chat_models.py:285, in BaseChatModel.invoke(self, input, config, stop, **kwargs)
274 def invoke(
275 self,
276 input: LanguageModelInput,
(...)
280 **kwargs: Any,
281 ) -> BaseMessage:
282 config = ensure_config(config)
283 return cast(
284 ChatGeneration,
--> 285 self.generate_prompt(
286 [self._convert_input(input)],
287 stop=stop,
288 callbacks=config.get("callbacks"),
289 tags=config.get("tags"),
290 metadata=config.get("metadata"),
291 run_name=config.get("run_name"),
292 run_id=config.pop("run_id", None),
293 **kwargs,
294 ).generations[0][0],
295 ).message
...
1030 error_class = self.exceptions.from_code(error_code)
-> 1031 raise error_class(parsed_response, operation_name)
1032 else:
1033 return parsed_response
ValidationException: An error occurred (ValidationException) when calling the Converse operation: The text field in the ContentBlock object at messages.1.content.0 is blank. Add text to the text field, and try again.
I see this is a valid scenario where AIMessage is clearly not empty, instead it is \n\n
and with/without a tool call. In Either case this shall work as expected.
It even fails when the text is \n\t
or \t
or any I guess which is escapable.