ChatPromptTemplate
Creates reusable prompt templates with variable interpolation. Essential for building consistent, parameterized prompts.
Syntax
langchain
ChatPromptTemplate.fromMessages([["system", "..."], ["human", "{variable}"]])Example
langchain
import { ChatPromptTemplate } from "@langchain/core/prompts";
const prompt = ChatPromptTemplate.fromMessages([
["system", "You are a helpful {role}."],
["human", "{question}"]
]);
const chain = prompt.pipe(model);
const response = await chain.invoke({ role: "teacher", question: "What is recursion?" });