Prompting Basics

How to write prompts that get useful results from an LLM. The single biggest determinant of output quality is the prompt you give it.

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 determines the quality of the output. This is the rule everything else hangs off.

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. Do not make the LLM guess.

Unclear: "Tell me about Python" Clear: "Explain Python list comprehensions with 3 examples"

2. Specificity

Narrow 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. The more relevant context, the better.

No context: "What should I do?" With context: "I am 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 usually has these parts:

[ROLE/CONTEXT]
You are [expert/role] with [specific expertise].

[TASK]
I need you to [specific task].

[SPECIFICS]
Here is 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

Bad: "Tell me about fitness" Good: "Create a 3-day-per-week strength training program for a beginner with dumbbells only"

Mistake 2: No Context

Bad: "Is this a good deal?" Good: "I am 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

Bad: "What is the best programming language and should I learn it and what projects should I build and how long will it take?" Good: Ask one at a time, or structure clearly with numbered questions.

Mistake 4: Not Specifying Format

Bad: "Compare these 5 phones" Good: "Compare these 5 phones in a table: Phone, Price, Camera, Battery, Best For"

Mistake 5: Assuming Knowledge

Bad: "Update the Johnson report with Q4 figures" Good: The LLM does not know what the Johnson report is. Provide it.

Mistake 6: No Constraints

Bad: "Write code to sort an array" Good: "Write Python code to sort an array in-place using quicksort. Include comments and handle edge cases."

Mistake 7: Trusting Without Verification

Bad: Using LLM output directly for critical decisions Good: Verify facts, test code, review logic, especially for important matters

Iterative Refinement

You rarely get perfect output on the first try. That is normal.

The process:

  1. Write the initial prompt
  2. Read the response
  3. Identify what is wrong or missing
  4. Refine the prompt
  5. Repeat until the output is what you want

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

Do not start a fresh 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 is the difference between these two?"
"Show me a complete example using both"

The LLM has the context from previous messages, so you do not 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.

Do not be afraid of long prompts. More relevant context produces 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 am 10 years old.

Using Examples (Few-Shot Prompting)

Show the LLM examples of what you want. This is one of the most reliable ways to steer output.

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 have 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 the logic
  • Check sources, if cited
  • Test the 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

Two things to be aware of: prompt injection and jailbreaking.

Prompt injection: malicious instructions hidden in user input. Jailbreaking: trying to bypass safety restrictions.

As a user

  • Do not 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 you send 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 or 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

  1. Initial prompt
  2. Review output
  3. Refine prompt
  4. Repeat

Build context

  • Use follow-ups in the same conversation
  • Provide examples
  • Give role and expertise context

Verify

  • Do not trust blindly
  • Test code
  • Check facts
  • Review logic

Practice Exercises

Try these to build prompting muscle.

  1. Rewrite this vague prompt to be specific:

    • "Tell me about investing"
  2. Add context to this prompt:

    • "Should I take this job?"
  3. Specify format for this prompt:

    • "Compare Python and JavaScript"
  4. Create a structured prompt for:

    • Analyzing your monthly budget and suggesting savings
  5. Use few-shot prompting to:

    • Convert measurements (show 2 examples, then ask for a third)

Next Steps

Continue to 03-advanced-prompting.md for techniques like chain-of-thought, prompt chaining, and structured output. The basics in this chapter will carry you a long way; the next chapter is for when "clear, specific, with context" is not enough.

Further Reading