Prompting Basics
Master the fundamentals of writing effective prompts to get better results from LLMs.
What is a Prompt?
A prompt is the input you give to an LLM. It can be:
- A question: "What is photosynthesis?"
- An instruction: "Write a professional email declining this invitation"
- A conversation: Multiple back-and-forth messages
- A complex request with context, constraints, and format requirements
The quality of your prompt directly determines the quality of the output.
The Golden Rule
Be clear, specific, and provide context.
Vague prompts get vague answers. Specific prompts get specific answers.
Bad Prompt
Write about marketing.
Good Prompt
Write a 300-word blog post introduction about email marketing
for small business owners. Focus on the ROI of building an
email list. Use a conversational tone.
Core Prompting Principles
1. Clarity
Say exactly what you want. Don't make the LLM guess.
Unclear: "Tell me about Python" Clear: "Explain Python list comprehensions with 3 examples"
2. Specificity
Narrow down the scope. Specific requests get better results.
Vague: "Help me with my resume" Specific: "Review this resume for a senior software engineer position at a fintech startup. Focus on achievements and quantifiable results."
3. Context
Provide background information. The more relevant context, the better.
No context: "What should I do?" With context: "I'm a 35-year-old software engineer with 10 years experience, considering switching to data science. I have a mortgage and 2 kids. What steps should I take?"
4. Format
Specify the output format you want.
No format: "Compare these products" With format: "Compare these products in a table with columns: Feature, Product A, Product B, Winner"
5. Constraints
Set boundaries: length, style, tone, what to avoid.
No constraints: "Write a proposal" With constraints: "Write a 500-word proposal in a formal business tone. Avoid technical jargon. Include 3 key benefits."
Basic Prompting Patterns
Pattern 1: Direct Question
Simple and effective for factual information.
What are the main causes of inflation?
How does HTTPS encryption work?
Pattern 2: Instruction
Tell the LLM what to do.
Summarize this article in 3 bullet points: [article text]
Translate this to Spanish: [English text]
Pattern 3: Example-Driven (Few-Shot)
Show examples of what you want.
Convert these to past tense:
- I go → I went
- I eat → I ate
- I run → [LLM completes]
Format these addresses:
John Smith, 123 Main St, NYC NY 10001 → Smith, J. (New York, NY)
Jane Doe, 456 Oak Ave, LA CA 90001 → [LLM completes]
Pattern 4: Role-Playing
Ask the LLM to adopt a specific persona or expertise.
You are an experienced financial advisor. A client asks about
whether to pay off student loans or invest. What do you tell them?
Act as a Python expert. Explain decorators to someone who just
learned functions.
Pattern 5: Step-by-Step
Ask for systematic, structured responses.
Explain how to change a car tire, step by step.
Create a step-by-step plan to learn Spanish in 6 months,
spending 1 hour per day.
Prompt Structure Template
A well-structured prompt typically has these components:
[ROLE/CONTEXT]
You are [expert/role] with [specific expertise].
[TASK]
I need you to [specific task].
[SPECIFICS]
Here's the relevant information: [context, data, constraints]
[FORMAT]
Provide the output as [format].
[CONSTRAINTS]
- [Constraint 1]
- [Constraint 2]
- Avoid [what not to do]
Example Using Template
[ROLE]
You are a senior software architect with expertise in microservices.
[TASK]
I need you to review this API design and suggest improvements.
[SPECIFICS]
Current design:
- REST API with 15 endpoints
- Monolithic backend
- 100K daily requests
- Response times averaging 800ms
- Considering splitting into microservices
[FORMAT]
Provide your analysis as:
1. Current issues
2. Recommended architecture changes
3. Migration plan
[CONSTRAINTS]
- Must maintain backward compatibility
- Budget is $50K
- Timeline is 3 months
- Avoid suggesting proprietary tools
Common Prompting Mistakes
Mistake 1: Being Too Vague
❌ "Tell me about fitness" ✅ "Create a 3-day-per-week strength training program for a beginner with dumbbells only"
Mistake 2: No Context
❌ "Is this a good deal?" ✅ "I'm offered a job at $120K in San Francisco as a mid-level software engineer with 5 years experience. Market rate seems to be $130-150K. Is this a good deal?"
Mistake 3: Asking Multiple Questions at Once
❌ "What's the best programming language and should I learn it and what projects should I build and how long will it take?" ✅ Ask one at a time, or structure clearly with numbered questions.
Mistake 4: Not Specifying Format
❌ "Compare these 5 phones" ✅ "Compare these 5 phones in a table: Phone, Price, Camera, Battery, Best For"
Mistake 5: Assuming Knowledge
❌ "Update the Johnson report with Q4 figures" ✅ The LLM doesn't know what the Johnson report is. Provide it.
Mistake 6: No Constraints
❌ "Write code to sort an array" ✅ "Write Python code to sort an array in-place using quicksort. Include comments and handle edge cases."
Mistake 7: Trusting Without Verification
❌ Using LLM output directly for critical decisions ✅ Verify facts, test code, review logic, especially for important matters
Iterative Refinement
You rarely get perfect output on the first try. That's normal.
The process is:
- Write initial prompt
- Get response
- Identify what's wrong or missing
- Refine prompt
- Repeat until satisfied
Example Iteration
Attempt 1:
Prompt: "Write a marketing email"
Output: [Generic, boring email]
Problem: Too vague
Attempt 2:
Prompt: "Write a marketing email for a new productivity app
targeting freelancers"
Output: [Better, but too formal]
Problem: Wrong tone
Attempt 3:
Prompt: "Write a casual, friendly marketing email for a new
productivity app targeting freelancers. Focus on the pain
point of tracking multiple projects. Email should be 150 words
with a clear CTA."
Output: [Much better!]
Follow-Up Prompts
Don't start a new conversation for every task. Build on previous responses.
Initial:
Explain React hooks to a beginner.
Follow-ups:
"Can you give an example with useState?"
"Now show me useEffect"
"What's the difference between these two?"
"Show me a complete example using both"
The LLM has context from previous messages, so you don't need to repeat yourself.
Length Matters
Short Prompts
Good for:
- Simple questions
- Quick tasks
- When context is obvious
Example: "Define entropy"
Long Prompts
Good for:
- Complex tasks
- When lots of context is needed
- When precision matters
Example: A 500-word prompt with full project requirements, constraints, and examples.
Tip: Don't be afraid of long prompts. More context = better results.
Tone and Style
Specify the tone you want:
Professional/Formal:
Write a formal business email declining this partnership proposal.
Casual/Friendly:
Write a friendly, casual email to a colleague thanking them for
their help on the project.
Technical/Precise:
Write technical documentation for this API endpoint. Use precise
language and include all parameters.
Simple/ELI5:
Explain quantum entanglement like I'm 10 years old.
Using Examples (Few-Shot Prompting)
Show the LLM examples of what you want. This is incredibly powerful.
Single Example (One-Shot)
Convert this sentence to active voice:
"The ball was thrown by John" → "John threw the ball"
Now convert: "The code was written by Sarah"
Multiple Examples (Few-Shot)
Classify these reviews as positive/negative:
"Great product, loved it!" → Positive
"Terrible, waste of money" → Negative
"Okay, nothing special" → Neutral
Now classify: "Best purchase I've made this year!"
Structured Examples
Convert to JSON:
Name: John Smith, Age: 30, City: NYC
{"name": "John Smith", "age": 30, "city": "NYC"}
Name: Jane Doe, Age: 25, City: LA
[LLM completes in same format]
Handling Complex Tasks
Break complex tasks into steps:
Instead of:
Build me a complete business plan for a food truck
Do:
1. "What are the key sections of a food truck business plan?"
2. "Help me write the executive summary for a taco food truck"
3. "Now the market analysis section..."
4. [Continue section by section]
Or structure it in a single prompt:
Create a food truck business plan with these sections:
1. Executive Summary
2. Market Analysis
3. Menu and Pricing
4. Operations Plan
5. Financial Projections
For each section, provide a detailed outline with key points
to cover. Make it specific to a gourmet taco truck in Austin, TX.
Testing and Validation
Always test LLM output:
For Code:
- Run it
- Test edge cases
- Check for security issues
For Writing:
- Read it yourself
- Check tone and style
- Verify facts
For Analysis:
- Verify logic
- Check sources (if provided)
- Test conclusions
For Data:
- Spot-check numbers
- Verify calculations
- Test formatting
Common Use Cases with Prompting Tips
Writing
Write a [type] about [topic] for [audience].
Tone: [tone]
Length: [length]
Focus on: [key points]
Summarization
Summarize this [document/article/email] in [format].
Focus on: [what matters]
[Include full text]
Analysis
Analyze this [data/text/situation] for [purpose].
Consider: [factors]
Provide: [what you want]
Code
Write [language] code to [task].
Requirements: [specs]
Constraints: [limitations]
Include: [what to include]
Learning
Explain [concept] for [level].
Use [style].
Include [examples/analogies].
Prompt Safety
Be aware of prompt injection and jailbreaking:
Prompt Injection: Malicious instructions hidden in user input Jailbreaking: Trying to bypass safety restrictions
As a user:
- Don't include untrusted user input directly in prompts
- Be cautious with LLM output that contains instructions
- Verify any surprising or suspicious outputs
As a prompt writer:
- Clearly separate instructions from user content
- Use delimiters: "User input:
[input]" - Validate and sanitize output
Best Practices Checklist
Before submitting a prompt, ask:
✅ Is it clear what I want? ✅ Have I provided enough context? ✅ Have I specified the format? ✅ Have I set appropriate constraints? ✅ Have I indicated the tone/style? ✅ Have I given examples if needed? ✅ Is the scope reasonable for one prompt?
Quick Reference
Make your prompts:
- Clear (no ambiguity)
- Specific (narrow scope)
- Contextual (provide background)
- Formatted (specify output format)
- Constrained (set boundaries)
Iterate:
- Initial prompt
- Review output
- Refine prompt
- Repeat
Build context:
- Use follow-ups in same conversation
- Provide examples
- Give role/expertise context
Verify:
- Don't trust blindly
- Test code
- Check facts
- Review logic
Practice Exercises
Try these to build your prompting skills:
Rewrite this vague prompt to be specific:
- "Tell me about investing"
Add context to this prompt:
- "Should I take this job?"
Specify format for this prompt:
- "Compare Python and JavaScript"
Create a structured prompt for:
- Analyzing your monthly budget and suggesting savings
Use few-shot prompting to:
- Convert measurements (show 2 examples, then ask for a third)
Summary
Key Takeaways:
- Clarity, specificity, and context are essential
- Use the template: role, task, specifics, format, constraints
- Don't be afraid of long, detailed prompts
- Iterate: first attempts are rarely perfect
- Use examples to show exactly what you want
- Specify format, tone, and length
- Break complex tasks into steps
- Always verify important outputs
Next Steps:
- Move to Chapter 03 for advanced techniques
- Practice with real tasks today
- Build a collection of effective prompts
- Learn from what works and what doesn't