


Quick Python example
Below is a concise example showing how to compose chat-style prompt templates using LangChain. This demonstrates aSystemMessagePromptTemplate and a HumanMessagePromptTemplate with a placeholder called text. When formatted, the placeholder is filled and converted to messages that you can pass to a chat model.
Use prompt templates to keep prompts consistent, enforce style or constraints, and share reusable patterns across your application or organization.
Prompt template types and common uses
Best practices
- Keep system templates focused on role, constraints, and safety guardrails.
- Use human templates for dynamic content and user data; validate or sanitize inputs before formatting.
- Create small, composable templates for reuse (e.g., short/concise vs. long/detailed personas).
- Manage organization-wide templates in a central repo or configuration to maintain consistent model behavior.
- Combine templates with output-parsing tools or schema validation when you need structured data from responses.
Example use cases
- Summarization: system sets tone, human provides target text.
- QA over documents: system enforces source citation, human supplies query and document context.
- Multi-persona assistants: swap system templates to change assistant behavior without editing application logic.
Links and references
- LangChain Documentation
- Kubernetes Basics (general reference)
- Docker Hub (general reference)