Page3/9
Prompt Engineering & Techniques · Page 1 of 1
Prompting Techniques
Prompt Engineering
What is Prompt Engineering?
Prompt Engineering = Art of writing prompts to get best results from LLMs.
Bad prompt: "Explain Python"
LLM: [vague, generic response]
Good prompt: "Explain Python to a complete beginner who has never coded before. Use simple language and give 2-3 real-world examples."
LLM: [detailed, beginner-friendly response]
The difference: Better prompt → Better output!
Core Principles
1. Be Specific & Clear
Bad: "Tell me about machine learning"
Good: "Explain the difference between supervised and unsupervised learning. Give a concrete example of each."
2. Give Context
Bad: "Translate this"
Good: "Translate the following Spanish sentence to English: 'El gato está en la mesa.'"
3. Specify Output Format
Bad: "Summarize this article"
Good: "Summarize this article in 2-3 sentences. Format as: Key point 1: ... Key point 2: ..."
4. Use Examples (Few-Shot Prompting)
Without examples:
"Classify sentiment: 'This movie is great!' → ?"
With examples:
"Classify sentiment:
- 'This movie is great!' → Positive
- 'Terrible waste of time' → Negative
- 'Pretty good movie' → ?"
LLM learns from examples!
5. Chain-of-Thought (CoT)
Ask the model to "think through" problems:
Bad prompt: "If there are 5 apples and 3 are red, what percent are red?"
Good prompt: "If there are 5 apples and 3 are red, what percent are red? Think step-by-step."
LLM output:
Step 1: Red apples = 3
Step 2: Total apples = 5
Step 3: Percentage = (3/5) × 100 = 60%
Answer: 60%
Better reasoning, fewer mistakes!
Advanced Techniques
Role-Playing
Prompt: "You are an expert Python teacher. Explain decorators to a student who knows functions."
LLM: [Uses teaching expertise, adjusts explanation level]
Temperature & Randomness
Temperature = 0 (Deterministic)
- Always picks most likely word
- Good for factual questions
Temperature = 1.0 (Balanced)
- Standard randomness
- Good for general use
Temperature = 2.0 (Creative)
- Picks random words
- Good for creative writing
Using System Prompts
System: "You are a friendly Python tutor. Explain concepts simply but accurately."
User: "What is a list?"
LLM: [Acts as friendly tutor, explains simply]
main.py
Loading...
OUTPUT
▶Click "Run Code" to execute…