I’m trying to create a conversation chain that uses Redis for storing chat history, but I keep running into issues when I add a custom prompt template.
const chatMemory = new BufferMemory({
chatHistory: new RedisChatMessageHistory({
sessionId: "user-session-456",
sessionTTL: 600,
config: {
URL: "redis://localhost:6379",
},
}),
memoryKey: "chat_history",
});
const promptTemplate = ChatPromptTemplate.fromPromptMessages([
SystemMessagePromptTemplate.fromTemplate(
"You are a helpful assistant."
),
new MessagesPlaceholder("chat_history"),
HumanMessagePromptTemplate.fromTemplate("{question}"),
]);
const conversationChain = new ConversationChain({
memory: chatMemory,
prompt: promptTemplate,
llm: languageModel,
});
const result = await conversationChain.call({
question: userInput.text,
});
The weird thing is that everything works perfectly when I don’t specify a custom prompt template. But as soon as I add the prompt configuration, I get this cryptic error: message._getType is not a function
I suspect there’s something wrong with how the chat history is being processed or merged with the prompt template, but I can’t pinpoint the exact issue. Has anyone encountered this before?
Hit the same issue a few months ago - it’s usually a version compatibility problem with LangChain components. That _getType is not a function error happens when message objects get messed up during serialization between Redis and the prompt template. For me, RedisChatMessageHistory was spitting out plain objects instead of proper message instances that ChatPromptTemplate needed. Fixed it by adding returnMessages: true to BufferMemory config - forces it to return actual message objects instead of strings. Try this:
I encountered a similar issue with Redis chat history and custom templates. The main problem is that ConversationChain requires inputKey and outputKey to be explicitly defined when using a custom prompt. However, BufferMemory does not automatically set these keys, leading to conflicts with ChatPromptTemplate. You can resolve this by specifying the key mappings in your memory configuration:
Make sure the inputKey corresponds to your template variable (in this case, “question”) and the outputKey matches the expected output from your language model. This should help the chain properly manage the data flow between Redis and the prompt template.
I’ve been fighting LangChain complexity for years - debugging Redis + custom prompt issues is brutal. The serialization problems between components are a nightmare.
Skip the BufferMemory config hell and version conflicts. I’d automate this whole conversation flow with Latenode instead. Set up a workflow that handles Redis storage, manages chat history, and connects to any LLM without the compatibility headaches.
Built something like this last month. Latenode’s visual workflow manages the Redis connection, formats messages for your prompt template, and runs the entire conversation chain. No more _getType errors or serialization debugging.
The workflow automatically formats messages between Redis and your LLM. Better error handling and monitoring than debugging LangChain’s internal message processing.
Saves hours of troubleshooting and actually works in production.
check your redis connection first - that error usually means redis isn’t returning data in the right format. i had the same issue when my redis instance kept dropping connections randomly. log what you’re getting back from redischatmessagehistory before it hits the prompt template. you’re probably getting null values or broken objects that mess up the _gettype call.