Sometimes it's easier to show the model what you want than to describe it. A few examples of input and output, called shots, can teach a format or style very quickly.
We want each book turned into a short tag line, with an emoji at the start. Instead of explaining, we show two examples, as human and AI message pairs, before the real question. Run it. The model copies the pattern from the examples, emoji and all, for a book it hasn't seen.
few_shot.pypython
from langchain.chat_models import init_chat_modelfrom langchain_core.prompts import ChatPromptTemplatemodel = init_chat_model("google_genai:gemini-flash-lite-latest", temperature=0)prompt = ChatPromptTemplate.from_messages([ ("system", "Turn each book into a short tagline."), ("human", "Moby Dick"), ("ai", "🐋 One man, one whale, one obsession."), ("human", "Dracula"), ("ai", "🧛 Never invite him in."), ("human", "{book}"),])print(model.invoke(prompt.invoke({"book": "Frankenstein"})).text)
A few tips. Two to five examples are usually enough. Make them varied, so the model learns the pattern, not one specific answer. Keep them short, because every example costs tokens on every call. And make sure they're all correct, because the model will copy their mistakes too.