ValidationError: 2 validation errors for HumanMessage at v1.0.0a59
songjinu opened this issue · comments
Describe the bug
ValidationError: 2 validation errors for HumanMessage at v1.0.0a59
I connect ChatInput - OpenAI without Prompt.
ValidationError: 2 validation errors for HumanMessage
content
str type expected (type=type_error.str)
content
value is not a valid list (type=type_error.list)
\src\backend\base\langflow\base\models\model.py:104 in get_chat_result │
│ │
│ 101 │ │ │ │ │ else: │
│ 102 │ │ │ │ │ │ messages.append(input_value.to_lc_message()) │
│ 103 │ │ │ else: │
│ ❱ 104 │ │ │ │ messages.append(HumanMessage(content=input_value)) │
│ 105 │ │ inputs = messages or {} │
│ 106 │ │ if stream: │
│ 107 │ │ │ return runnable.stream(inputs)
Browser and Version
- Version [v1.0.0a59]
Screenshots
To resolve the ValidationError
when connecting ChatInput
to OpenAI without a prompt, you need to ensure that the input_value
is correctly formatted as a HumanMessage
. The error indicates that the content
field is expected to be a string but is being provided as a list, or vice versa.
Here's how you can fix it:
-
Ensure
input_value
is a string: When addinginput_value
to themessages
list, it should be a string. Ifinput_value
is already aRecord
, you need to convert it to aHumanMessage
correctly. -
Modify the
get_chat_result
function: Ensure thatinput_value
is properly converted to aHumanMessage
.
Here is the relevant part of the code that needs to be checked and possibly modified:
def get_chat_result(self, runnable: BaseChatModel, stream: bool, input_value: str, system_message: Optional[str] = None):
messages: list[Union[HumanMessage, SystemMessage]] = []
if not input_value and not system_message:
raise ValueError("The message you want to send to the model is empty.")
if system_message:
messages.append(SystemMessage(content=system_message))
if input_value:
messages.append(HumanMessage(content=input_value))
if stream:
return runnable.stream(messages)
else:
message = runnable.invoke(messages)
result = message.content
if isinstance(message, AIMessage):
status_message = self.build_status_message(message)
self.status = status_message
else:
self.status = result
return result
Ensure that input_value
is a string when passed to HumanMessage
:
if input_value:
if isinstance(input_value, Record):
input_value = input_value.get_text() # Convert Record to string
messages.append(HumanMessage(content=input_value))
This ensures that input_value
is correctly formatted as a string before being used to create a HumanMessage
[1][2].
Already reported earlier at #2182 for a58 and continues to be an issue with a59 version as well.
Is the problem still there with langflow 1.0.5?
Duplicate of #2182