This cookbook contains a comprehensive collection of specialized prompts designed for various professional domains using LangChain. The prompts are crafted to leverage the power of large language models while maintaining domain expertise and professional standards.
The primary goals of this project are to:
Provide standardized, high-quality prompts for different professional domains
Enable consistent and reliable outputs from language models
Facilitate domain-specific knowledge extraction and analysis
Support automated report generation and content creation
Maintain professional standards across various fields
Table of Contents
References
Environment Setup
[Note]
langchain-opentutorial is a package that provides a set of easy-to-use environment setup, useful functions and utilities for tutorials.
# Set environment variables
from langchain_opentutorial import set_env
set_env(
{
"OPENAI_API_KEY": "",
# Get an API key for your Personal organization if you have not yet. The hub will not work with your non-personal organization's api key!
# If you already have LANGCHAIN_API_KEY set to a personal organization’s api key from LangSmith, you can skip this.
"LANGCHAIN_API_KEY": "",
"LANGCHAIN_TRACING_V2": "true",
"LANGCHAIN_ENDPOINT": "https://api.smith.langchain.com",
"LANGCHAIN_PROJECT": "Personal Prompts for LangChain",
}
)
By following these tailored tips, you can maximize the strengths of each model and achieve optimal performance in your LangChain projects.
1. ChatGPT (OpenAI's GPT-4)
ChatGPT is a powerful language model known for its conversational ability and logical reasoning.
Prompt Tips:
Keep it Clear and Focused: Clearly define what you want the model to do. Don’t overload it with too much background information.
Ask for a Specific Format: If you need the response in bullet points, tables, or paragraphs, mention it.
Assign a Role: Tell ChatGPT who it is (e.g., "You are a project manager") to get more tailored answers.
# Example Prompt for GPT4
"You are a professional email writer. Write a polite email to a client informing them of a project delay of one month due to supply chain issues. The tone should be apologetic but confident."
'You are a professional email writer. Write a polite email to a client informing them of a project delay of one month due to supply chain issues. The tone should be apologetic but confident.'
2. Claude (Anthropic's Model)
Claude excels in structured thinking and understanding detailed tasks. It often works well with XML-style formatting for prompts.
Prompt Tips:
Use Structured Formats: Use XML tags to organize the instructions, which helps Claude interpret them better.
Provide Context and Examples: Add a clear task and examples to guide the model's response.
# Example Prompt for Claude
"""
<context>
<project>
<name>Website Redesign</name>
<deadline>March 15, 2025</deadline>
</project>
</context>
<instructions>
Write an email to the client explaining the project will be delayed by one month due to supply chain issues. Apologize and propose a new deadline.
</instructions>
<example>
Dear [Client Name],
Due to supply chain challenges, we regret to inform you that the project will be delayed. The new expected completion date is April 15, 2025. We apologize for the inconvenience and appreciate your understanding.
Best regards,
[Your Name]
</example>
"""
'\n\n \n Website Redesign\n March 15, 2025\n \n\n\n Write an email to the client explaining the project will be delayed by one month due to supply chain issues. Apologize and propose a new deadline.\n\n\n Dear [Client Name],\n\n Due to supply chain challenges, we regret to inform you that the project will be delayed. The new expected completion date is April 15, 2025. We apologize for the inconvenience and appreciate your understanding.\n\n Best regards, \n [Your Name]\n\n'
3. Gemini (Google’s AI Model)
Gemini is a cutting-edge multimodal AI designed to work across text, images, and other data types. It handles detailed and structured tasks effectively.
Prompt Tips:
Be Detailed and Specific: Clearly explain the task and provide any necessary background details.
Break Complex Tasks into Steps: If the task is complicated, split it into smaller, sequential steps.
Add Examples: Providing examples helps Gemini align its output with your expectations.
# Exmple Prompt for Gemini
"You are a marketing strategist. Write a 200-word summary of the key milestones achieved in a project, emphasizing the team’s performance and results. Use a professional tone."
'You are a marketing strategist. Write a 200-word summary of the key milestones achieved in a project, emphasizing the team’s performance and results. Use a professional tone.'
Basic Prompts
The Basic Prompts chapter covers summarization tasks that are most commonly used across all domains. These prompts can be used individually or combined in a pipeline:
The Summary Prompt is designed to create concise, informative summaries of documents while maintaining key information and context.
PROMPT_OWNER = "eun"
from langchain import hub
from langchain.prompts import PromptTemplate
# Let's upload the prompt to the LangChain Hub.
# Don't forget to enter the LangSmith API as an environment variable.
prompt_title = "summarize_document"
summarize_prompt = """
Please summarize the sentence according to the following REQUEST.
REQUEST:
1. Summarize the main points in bullet points.
2. Each summarized sentence must start with an emoji that fits the meaning of the each sentence.
3. Use various emojis to make the summary more interesting.
4. DO NOT include any unnecessary information.
CONTEXT:
{context}
SUMMARY:"
"""
prompt = PromptTemplate.from_template(summarize_prompt)
prompt
PromptTemplate(input_variables=['context'], input_types={}, partial_variables={}, template='\nPlease summarize the sentence according to the following REQUEST.\nREQUEST:\n1. Summarize the main points in bullet points.\n2. Each summarized sentence must start with an emoji that fits the meaning of the each sentence.\n3. Use various emojis to make the summary more interesting.\n4. DO NOT include any unnecessary information.\n\nCONTEXT:\n{context}\n\nSUMMARY:"\n')
# To upload a prompt to Hub:
#
# Private Repository:
# - Simply pass the prompt title as the first argument
# hub.push(prompt_title, prompt, new_repo_is_public=False)
#
# Public Repository:
# - First create a Hub Handle at LangSmith (smith.langchain.com)
# - Include your handle in the prompt title path
# hub.push(f"{PROMPT_OWNER}/{prompt_title}", prompt, new_repo_is_public=True)
hub.push(f"{PROMPT_OWNER}/{prompt_title}", prompt, new_repo_is_public=True)
You can find the uploaded prompt in your LangSmith. Please go to the site address as output.
# You can import and use prompts as follows.
prompt = hub.pull("eun/summarize_document:129da0ee")
prompt
PromptTemplate(input_variables=['context'], input_types={}, partial_variables={}, metadata={'lc_hub_owner': 'eun', 'lc_hub_repo': 'summarize_document', 'lc_hub_commit_hash': '129da0ee7cc02d076cd26692334f58a4aa898f5c40916847e8d808adb31f0263'}, template='\nPlease summarize the sentence according to the following REQUEST.\nREQUEST:\n1. Summarize the main points in bullet points.\n2. Each summarized sentence must start with an emoji that fits the meaning of the each sentence.\n3. Use various emojis to make the summary more interesting.\n4. DO NOT include any unnecessary information.\n\nCONTEXT:\n{context}\n\nSUMMARY:"\n')
2. Map Prompt
The Map Prompt is used to extract and organize main themes from documents, creating a structured representation of the content.
from langchain import hub
from langchain.prompts import PromptTemplate
prompt_title = "map-prompt"
map_prompt = """
You are a helpful expert journalist in extracting the main themes from a GIVEN DOCUMENTS below.
Please provide a comprehensive summary of the GIVEN DOCUMENTS in numbered list format.
The summary should cover all the key points and main ideas presented in the original text, while also condensing the information into a concise and easy-to-understand format.
Please ensure that the summary includes relevant details and examples that support the main ideas, while avoiding any unnecessary information or repetition.
The length of the summary should be appropriate for the length and complexity of the original text, providing a clear and accurate overview without omitting any important information.
GIVEN DOCUMENTS:
{docs}
FORMAT:
1. main theme 1
2. main theme 2
3. main theme 3
...
CAUTION:
- DO NOT list more than 5 main themes.
Helpful Answer:
"""
prompt = PromptTemplate.from_template(map_prompt)
prompt
PromptTemplate(input_variables=['docs'], input_types={}, partial_variables={}, template='\nYou are a helpful expert journalist in extracting the main themes from a GIVEN DOCUMENTS below.\nPlease provide a comprehensive summary of the GIVEN DOCUMENTS in numbered list format.\nThe summary should cover all the key points and main ideas presented in the original text, while also condensing the information into a concise and easy-to-understand format.\nPlease ensure that the summary includes relevant details and examples that support the main ideas, while avoiding any unnecessary information or repetition.\nThe length of the summary should be appropriate for the length and complexity of the original text, providing a clear and accurate overview without omitting any important information.\n\nGIVEN DOCUMENTS:\n{docs}\n\nFORMAT:\n1. main theme 1\n2. main theme 2\n3. main theme 3\n...\n\nCAUTION:\n- DO NOT list more than 5 main themes.\n\nHelpful Answer:\n')
The Reduce Prompt combines and synthesizes multiple summaries into a single, coherent output, particularly useful for processing large document sets.
from langchain import hub
from langchain.prompts import PromptTemplate
prompt_title = "reduce-prompt"
reduce_prompt = """
You are a helpful expert in summary writing.
You are given numbered lists of summaries.
Extract top 10 most important insights and create a unified summary.
LIST OF SUMMARIES:
{doc_summaries}
REQUIREMENTS:
1. Identify key insights across summaries
2. Maintain coherence and flow
3. Eliminate redundancy
4. Preserve important details
5. Create a unified narrative
OUTPUT FORMAT:
1. Main insights (bullet points)
2. Synthesized summary
3. Key takeaways
"""
prompt = PromptTemplate.from_template(reduce_prompt)
prompt
PromptTemplate(input_variables=['doc_summaries'], input_types={}, partial_variables={}, template='\nYou are a helpful expert in summary writing.\nYou are given numbered lists of summaries.\nExtract top 10 most important insights and create a unified summary.\n\nLIST OF SUMMARIES:\n{doc_summaries}\n\nREQUIREMENTS:\n1. Identify key insights across summaries\n2. Maintain coherence and flow\n3. Eliminate redundancy\n4. Preserve important details\n5. Create a unified narrative\n\nOUTPUT FORMAT:\n1. Main insights (bullet points)\n2. Synthesized summary\n3. Key takeaways\n')
The Advanced Prompts chapter explores sophisticated techniques that enhance the quality and specificity of language model outputs. These prompts are designed to handle complex tasks requiring deeper analysis and more nuanced responses.
1. Chain of Density Summarization
Chain of Density Summarization iteratively refines summaries to achieve higher information density while maintaining readability and key insights.
from langchain import hub
from langchain.prompts import PromptTemplate
prompt_title = "chain-of-density"
chain_density_prompt = """
Given the input text, generate increasingly dense summaries through the following steps:
INPUT PARAMETERS:
- Text: {text}
- Iteration Count: {iterations}
- Target Length: {length}
PROCESS:
1. Initial Summary
2. Entity Identification
3. Density Enhancement
4. Quality Check
OUTPUT REQUIREMENTS:
1. Maintain consistent length
2. Increase information density
3. Preserve key entities
4. Ensure readability
Please provide the summary following this structure:
FORMAT:
{
"initial_summary": str,
"entity_map": list,
"refined_summaries": list,
"final_summary": str
}
"""
prompt = PromptTemplate.from_template(chain_density_prompt)
Generate increasingly dense summaries in any specified language through iterative refinement while maintaining semantic accuracy.
from langchain import hub
from langchain.prompts import ChatPromptTemplate
prompt_title = "chain-of-density-multilingual"
chain_density_multilingual = """
Article: {ARTICLE}
Language: {LANGUAGE}
You will generate increasingly concise, entity-dense summaries of the above article in the specified language.
Repeat the following 2 steps 5 times.
Step 1. Identify 1-3 informative entities (";" delimited) from the article which are missing from the previously generated summary.
Step 2. Write a new, denser summary of identical length which covers every entity and detail from the previous summary plus the missing entities.
A missing entity is:
- relevant to the main story,
- specific yet concise (100 words or fewer),
- novel (not in the previous summary),
- faithful (present in the article),
- anywhere (can be located anywhere in the article).
Guidelines:
- The first summary should be long (8-10 sentences, ~200 words) yet highly non-specific
- Make every word count: rewrite the previous summary to improve flow
- Make space with fusion, compression, and removal of uninformative phrases
- The summaries should become highly dense and concise yet self-contained
- Missing entities can appear anywhere in the new summary
- Never drop entities from the previous summary
OUTPUT FORMAT:
[
{
"Missing_Entities": str,
"Denser_Summary": str
}
]
Provide the output in the specified language: {LANGUAGE}
"""
prompt = ChatPromptTemplate.from_template(chain_density_multilingual)
# Usage Example:
response = chain_density_multilingual.format(
ARTICLE="Your article text here", LANGUAGE="Spanish"
)
1.2. Chain of Density Map (Multilingual)
Create mapped summaries with increasing density in any specified language, focusing on key entity extraction and relationship mapping.
from langchain import hub
from langchain.prompts import ChatPromptTemplate
prompt_title = "chain-of-density-map-multilingual"
chain_density_map_multilingual = """
Article: {ARTICLE}
Language: {LANGUAGE}
You will generate increasingly concise, entity-dense summaries of the above article in the specified language.
Repeat the following 2 steps 3 times.
Step 1. Identify 1-3 informative entities (";" delimited) from the article which are missing from the previous summary.
Step 2. Write a new, denser summary of identical length covering all previous entities plus new ones.
A missing entity is:
- relevant to the main story,
- specific yet concise (100 words or fewer),
- novel (not in the previous summary),
- faithful (present in the article),
- anywhere (can be located anywhere in the article).
Guidelines:
- First summary: 8-10 sentences (~200 words), non-specific with fillers
- Optimize word usage and improve flow
- Remove uninformative phrases
- Maintain density and self-containment
- Preserve all previous entities
OUTPUT FORMAT:
Text format for "Missing Entities" and "Denser_Summary"
Provide the output in the specified language: {LANGUAGE}
"""
prompt = ChatPromptTemplate.from_template(chain_density_map_multilingual)
# Usage Example:
response_map = chain_density_map_multilingual.format(
ARTICLE="Your article text here", LANGUAGE="Japanese" # or any other language
)
2. Key Information Extraction
Extract and structure critical information from various document types with high precision and consistency.
from langchain import hub
from langchain.prompts import PromptTemplate
prompt_title = "key-information-extraction"
extraction_prompt = """
Extract key information from the provided document according to these specifications:
INPUT:
- Document: {document}
- Target Fields: {fields}
- Context Requirements: {context}
EXTRACTION REQUIREMENTS:
1. Identify specified data points
2. Maintain contextual relationships
3. Validate extracted information
4. Format according to schema
OUTPUT FORMAT:
{
"extracted_data": dict,
"confidence_scores": dict,
"validation_results": dict,
"metadata": dict
}
"""
prompt = PromptTemplate.from_template(extraction_prompt)
hub.push(prompt_title, prompt, new_repo_is_public=False)
3. Metadata Tagging
Automatically generate relevant tags and metadata to enhance content organization and searchability.
Process and answer questions based on retrieved document contexts with high accuracy and relevance.
from langchain import hub
from langchain.prompts import ChatPromptTemplate
prompt_title = "rag-document-analysis"
system = """You are a precise and helpful AI assistant specializing in question-answering tasks based on provided context.
Your primary task is to:
1. Analyze the provided context thoroughly
2. Answer questions using ONLY the information from the context
3. Preserve technical terms and proper nouns exactly as they appear
4. If the answer cannot be found in the context, respond with: 'The provided context does not contain information to answer this question.'
5. Format responses in clear, readable paragraphs with relevant examples when available
6. Focus on accuracy and clarity in your responses
"""
human = """#Question:
{question}
#Context:
{context}
#Answer:
Please provide a focused, accurate response that directly addresses the question using only the information from the provided context."""
prompt = ChatPromptTemplate.from_messages([("system", system), ("human", human)])
prompt
ChatPromptTemplate(input_variables=['context', 'question'], input_types={}, partial_variables={}, messages=[SystemMessagePromptTemplate(prompt=PromptTemplate(input_variables=[], input_types={}, partial_variables={}, template="You are a precise and helpful AI assistant specializing in question-answering tasks based on provided context.\nYour primary task is to:\n1. Analyze the provided context thoroughly\n2. Answer questions using ONLY the information from the context\n3. Preserve technical terms and proper nouns exactly as they appear\n4. If the answer cannot be found in the context, respond with: 'The provided context does not contain information to answer this question.'\n5. Format responses in clear, readable paragraphs with relevant examples when available\n6. Focus on accuracy and clarity in your responses\n"), additional_kwargs={}), HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['context', 'question'], input_types={}, partial_variables={}, template='#Question:\n{question}\n\n#Context:\n{context}\n\n#Answer:\nPlease provide a focused, accurate response that directly addresses the question using only the information from the provided context.'), additional_kwargs={})])
Enhanced RAG implementation with detailed source tracking and citation for improved accountability and verification.
from langchain import hub
from langchain.prompts import ChatPromptTemplate
prompt_title = "rag-with-sources"
system = """You are a precise and thorough AI assistant that provides well-documented answers with source attribution.
Your responsibilities include:
1. Analyzing provided context thoroughly
2. Generating accurate answers based solely on the given context
3. Including specific source references for each key point
4. Preserving technical terminology exactly as presented
5. Maintaining clear citation format [source: page/document]
6. If information is not found in the context, state: 'The provided context does not contain information to answer this question.'
Format your response as:
1. Main Answer
2. Sources Used (with specific locations)
3. Confidence Level (High/Medium/Low)"""
human = """#Question:
{question}
#Context:
{context}
#Answer:
Please provide a detailed response with source citations using only information from the provided context."""
prompt = ChatPromptTemplate.from_messages([("system", system), ("human", human)])
PROMPT_OWNER = "eun"
hub.push(f"{PROMPT_OWNER}/{prompt_title}", prompt, new_repo_is_public=True)
Comprehensive evaluation of LLM responses based on multiple quality metrics with detailed scoring methodology.
from langchain import hub
from langchain.prompts import PromptTemplate
prompt_title = "llm-response-evaluation"
evaluation_prompt = """Evaluate the LLM's response based on the following criteria:
INPUT:
Question: {question}
Context: {context}
LLM Response: {answer}
EVALUATION CRITERIA:
1. Accuracy (0-10)
- Perfect (10): Completely accurate, perfectly aligned with context
- Good (7-9): Minor inaccuracies
- Fair (4-6): Some significant inaccuracies
- Poor (0-3): Major inaccuracies or misalignment
2. Completeness (0-10)
- Perfect (10): Comprehensive coverage of all relevant points
- Good (7-9): Covers most important points
- Fair (4-6): Missing several key points
- Poor (0-3): Critically incomplete
3. Context Relevance (0-10)
- Perfect (10): Optimal use of context
- Good (7-9): Good use with minor omissions
- Fair (4-6): Partial use of relevant context
- Poor (0-3): Poor context utilization
4. Clarity (0-10)
- Perfect (10): Exceptionally clear and well-structured
- Good (7-9): Clear with minor issues
- Fair (4-6): Somewhat unclear
- Poor (0-3): Confusing or poorly structured
SCORING METHOD:
1. Calculate individual scores
2. Compute weighted average:
- Accuracy: 40%
- Completeness: 25%
- Context Relevance: 25%
- Clarity: 10%
3. Normalize to 0-1 scale
OUTPUT FORMAT:
{
"individual_scores": {
"accuracy": float,
"completeness": float,
"context_relevance": float,
"clarity": float
},
"weighted_score": float,
"normalized_score": float,
"evaluation_notes": string
}
Return ONLY the normalized_score as a decimal between 0 and 1."""
prompt = PromptTemplate.from_template(evaluation_prompt)
Professional Domain Prompts
Each professional domain prompt is carefully crafted to address specific industry needs and requirements.
This part requires optimization of prompts, especially according to domain data and format. Therefore, it is recommended that you test multiple prompts with Playground on websites such as OpenAI or Anthropic and use the most appropriate prompts. Below is an example of prompts in each field.
1. Academic Research Analysis Prompt
PROMPT_TEMPLATE = """
As an expert academic researcher, analyze the academic content with:
INPUT:
- Content Type: {content_type}
- Field of Study: {field}
- Analysis Depth: {depth}
ANALYZE:
1. Research methodology and design
2. Key findings and significance
3. Theoretical framework
4. Statistical validity
5. Study limitations
6. Future directions
OUTPUT FORMAT:
{
"executive_summary": str,
"methodology_analysis": dict,
"findings_analysis": dict,
"quality_assessment": dict
}
"""
2. Clinical Case Analysis Prompt
PROMPT_TEMPLATE = """
As a medical professional, analyze clinical cases with:
INPUT:
- Patient Information: {patient_data}
- Clinical Notes: {clinical_notes}
PROVIDE:
1. Clinical Assessment
2. Diagnostic Process
3. Treatment Plan
4. Risk Assessment
OUTPUT FORMAT:
{
"clinical_summary": str,
"differential_diagnosis": list,
"treatment_plan": dict,
"risk_assessment": dict
}
"""