Skip to main content

MESSAGE_COERCION_FAILURE

Several modules in LangChain take MessageLike objects in place of formal BaseMessage classes. These include OpenAI style message objects ({ role: "user", content: "Hello world!" }), tuples, and plain strings (which are converted to HumanMessages).

If one of these modules receives a value outside of one of these formats, you will receive an error like the following:

const badlyFormattedMessageObject = {
role: "foo",
randomNonContentValue: "bar",
};

await model.invoke([badlyFormattedMessageObject]);
Error: Unable to coerce message from array: only human, AI, system, or tool message coercion is currently supported.

Received: {
"role": "foo",
"randomNonContentValue": "bar",
}

Troubleshooting

The following may help resolve this error:

  • Ensure that all inputs to chat models are an array of LangChain message classes or a supported message-like.
    • Check that there is no stringification or other unexpected transformation occuring.
  • Check the error's stack trace and add log or debugger statements.

Was this page helpful?


You can also leave detailed feedback on GitHub.