A prompt template is a reusable instruction with variable fields. Fill those fields with a user’s input, context, or examples to create the request sent to a language model. Keeping the instruction fixed makes dynamic prompts easier to reuse than rebuilding them for every call. section 1.4.1 section 1.2.1
Start with a summary prompt
Suppose users need summaries in different lengths and tones. A Python function can insert `text`, `num_words`, and `tone` into one instruction. LangChain’s `PromptTemplate.from_template()` expresses the same pattern with `{text}`, `{num_words}`, and `{tone}` placeholders: call `.format()` with their values, then send the formatted prompt to `ChatOpenAI`. section 2.3.1 section 2.3.2
from langchain_core.prompts import PromptTemplate
prompt_template = PromptTemplate.from_template(
"""You are an experienced copywriter.
Write a {num_words} words summary of the following text,
using a {tone} tone: {text}""")
The listing shows a reusable summary instruction with three named fields rather than a prompt tied to one input. section 2.3.2
The same structure supports richer workflows:
- For few-shot prompting, keep examples separate from the instruction and inject them with `FewShotPromptTemplate` instead of hardcoding them into one string. section 2.5.5
- For research, pass instructions selected from one prompt into another that generates web searches; request JSON when the next processing step needs structured data. section 4.5.1
- For retrieval-augmented Q&A, combine the question with retrieved context. An instruction to admit when the context lacks an answer can reduce made-up answers. section 7.1.2 section 6.3.2
A template organizes a request; it does not supply missing knowledge or guarantee a correct response. Test the filled prompt and its outputs, then adjust the instructions, examples, or retrieved context for the task. section 2.0 section 1.4.1




















