You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The complete prompt engineering toolkit. Pure Python — zero dependencies. Use with ChatGPT, Claude, Gemini, or any LLM. 71 passing tests.
Why this repo?
26 prompt techniques — from Zero-Shot to Tree-of-Thought, ReAct, RAG, Reflexion.
18 ready-to-use templates — summarization, code review, SQL generation, email writing, and more.
15 anti-patterns documented — with bad vs. good examples for each.
Pure Python builders — each technique is a function. Pass inputs, get a prompt string.
71 passing tests verify everything.
Works with any LLM — ChatGPT, Claude, Gemini, Llama, Mistral, Ollama.
Stop copy-pasting prompts from random blogs. Use a tested, structured library instead.
Quick Start
git clone https://github.com/pyshine-labs/prompt-engineering-guide.git
cd prompt-engineering-guide
python tests/test_prompts.py
30-Second Tour
frompromptsimport (
chain_of_thought, few_shot, react, rag,
review_code, summarize_text, text_to_sql,
)
# 1. Chain-of-Thought for math/reasoningprompt=chain_of_thought(
"Compute the total cost",
"3 items at $12 each plus $5 shipping",
)
print(prompt)
# Instruction: Compute the total cost# Question: 3 items at $12 each plus $5 shipping# Let's think step by step.# 2. Few-shot for classificationexamples= [
{"input": "great", "output": "positive"},
{"input": "bad", "output": "negative"},
]
prompt=few_shot("Classify sentiment", examples, "awesome")
# 3. ReAct for tool-using agentsprompt=react(
"Answer the question",
"What's the weather in Paris?",
available_tools=["weather_api", "calculator"],
)
# 4. RAG for grounded answersprompt=rag(
"Answer the question",
"Who founded Apple?",
context_chunks=[
"Apple was founded by Steve Jobs, Steve Wozniak, and Ronald Wayne in 1976.",
"The company is headquartered in Cupertino, California.",
],
)
# 5. Templates for everyday tasksprompt=review_code("def add(a, b): return a - b", language="python")
prompt=summarize_text(long_article, max_words=100)
prompt=text_to_sql("Find top 10 users by score", "users(id, name, score)")
frompromptsimportget_anti_patternap=get_anti_pattern("Vague instruction")
print(ap["bad"]) # "Write something about Python."print(ap["good"]) # "Write a 200-word introduction to Python for absolute beginners..."
Run Tests
python tests/test_prompts.py
# Passed: 71/71# All tests passed.
Real-world prompts often combine multiple techniques:
frompromptsimportrole_prompt, few_shot, chain_of_thought# Role + Few-shot + CoTbase=role_prompt("Senior data scientist", "Analyze the dataset")
examples= [{"input": "small dataset", "output": "use simpler model"}]
demo=few_shot("Recommend a model", examples, "1M rows, 50 features")
reasoning=chain_of_thought("Recommend a model", "1M rows, 50 features")
full_prompt=base+"\n\n"+demo+"\n\n"+reasoning
frompromptsimportrag, structured_output# RAG + structured outputcontext= ["Apple was founded in 1976.", "Apple makes iPhones."]
grounded=rag("Extract facts", "Apple founding", context)
fmt=structured_output("Extract", ["year", "founders", "product"])
full_prompt=grounded+"\n\n"+fmt
When to Use Which Technique
Simple task (translate, summarize) → zero_shot
Need specific format → json_output / structured_output
Format is critical, reasoning is not → few_shot
Multi-step reasoning (math, logic) → chain_of_thought
Hard reasoning, need reliability → self_consistency
Multiple paths, some dead-end → tree_of_thought
Sequential sub-questions → least_to_most
Improve a draft → self_refine
Multi-hop question answering → self_ask
Learn from prior failures → reflexion
Answer from your documents → rag
Need background facts first → step_back
Tool-using agent → react
Plan a sequence of tool calls → action_planner
Domain-specific tone → role_prompt
Unsure how to phrase → meta_prompt
Teaching/tutoring → socratic
Learn More
Master Python, AI, and prompt engineering with tutorials from pyshine.com: