Overview
Prompt templates help you create reusable, parameterized prompts for language models.ChatPromptTemplate
Template for chat models with message roles. Import:Basic Usage
Multiple Messages
MessagesPlaceholder
Insert dynamic message arrays:PromptTemplate
Template for completion models (text-in, text-out).Partial Variables
Set some variables upfront:Few-Shot Prompts
Include examples in your prompt:Prompt Composition
Combine prompts:Using with Models
Prompt Methods
Format the prompt with variables
Format as a string (for PromptTemplate)
Create a new prompt with some variables pre-filled
Template Syntax
Variable Substitution
Conditional Content
Prompt from File
Best Practices
Use descriptive variable names
Use descriptive variable names
Choose variable names that clearly indicate what value should be provided:
Include instructions in system messages
Include instructions in system messages
Put behavior instructions in system messages:
Use MessagesPlaceholder for conversation history
Use MessagesPlaceholder for conversation history
This keeps your prompt flexible:
Related
Prompt Engineering Guide
Learn prompt engineering best practices
Chat Models
Using prompts with chat models
