A chatbot's prompt has a fixed system message, then a history that keeps growing, then the new question. Messages placeholder is a slot in the template where a whole list of messages goes.
The placeholder is named history. When we invoke the template, we pass a list of earlier messages under that name. Run it. The final prompt has the system message, the two history messages, and the new question, four messages in all.
placeholder.pypython
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholderprompt = ChatPromptTemplate.from_messages([ ("system", "You help customers of Riverside Books."), MessagesPlaceholder("history"), ("human", "{question}"),])history = [("human", "Hi, I'm Priya."), ("ai", "Hello Priya! How can I help?")]value = prompt.invoke({"history": history, "question": "What's my name?"})for m in value.messages: print(f"{m.type:>6}: {m.content}")
Output
system: You help customers of Riverside Books.
human: Hi, I'm Priya.
ai: Hello Priya! How can I help?
human: What's my name?
You'll use placeholders often. For chat history, as here. For tool results, inside agents. And for examples, when you want to show the model several sample conversations. Anywhere a prompt needs a list of messages of varying length.