Course outline

What is Prompt Engineering?

6 min read · Lesson 2.1

Prompt engineering is the practice of designing and refining the inputs you give to an AI language model to get the best possible outputs. It's the difference between getting a vague, generic answer and getting a precise, useful one — using the same underlying model.

If an LLM is a very capable but literal genie, prompt engineering is learning how to phrase your wishes correctly.


Why Prompts Matter So Much

LLMs are extraordinarily sensitive to how you phrase things. The exact same model can produce vastly different results depending on your prompt:

Weak prompt:

Write about climate change.

Result: A generic 200-word overview you could find on Wikipedia.

Strong prompt:

You are a science journalist writing for a general audience.
Explain how climate change affects ocean currents in 3 paragraphs.
Focus on the AMOC slowdown. Use an analogy in the first paragraph.
End with one concrete action individuals can take.

Result: A specific, structured, accurate, and engaging piece.

Same model. Completely different output. That's the leverage of prompt engineering.


The Anatomy of a Prompt

Most effective prompts combine several elements:

┌─────────────────────────────────────────────────┐
│  SYSTEM PROMPT (who the model is / rules)       │
│  "You are a senior Python engineer. Be concise. │
│   Always include error handling."               │
├─────────────────────────────────────────────────┤
│  CONTEXT (background information)               │
│  "Here is the codebase structure: ..."          │
├─────────────────────────────────────────────────┤
│  TASK (what to do)                              │
│  "Refactor the following function to use        │
│   async/await instead of callbacks."            │
├─────────────────────────────────────────────────┤
│  INPUT (the actual data)                        │
│  "```python\ndef fetch_data(url, callback):..." │
├─────────────────────────────────────────────────┤
│  OUTPUT FORMAT (how to respond)                 │
│  "Return only the refactored code, no           │
│   explanation needed."                          │
└─────────────────────────────────────────────────┘

You won't always use all five elements — but knowing each one helps you diagnose why a prompt isn't working.


Core Prompting Techniques

Zero-Shot Prompting

Ask directly, no examples. Works well for common tasks the model has seen during training.

Classify the sentiment of this review as Positive, Negative, or Neutral:
"The delivery was fast but the product feels cheap."

Few-Shot Prompting

Provide 2–5 examples to teach the model your desired format or behavior.

Classify sentiment:

Review: "Amazing quality, will buy again!" → Positive
Review: "Broken on arrival, terrible." → Negative
Review: "It's okay, nothing special." → Neutral

Review: "Took forever to arrive but works perfectly." → ?

The model picks up the pattern and applies it — without any retraining.

Chain-of-Thought (CoT)

Ask the model to reason step-by-step before giving the final answer. This dramatically improves performance on math, logic, and multi-step reasoning.

Q: A train leaves Chicago at 9am going 60mph. Another leaves
New York at 10am going 80mph. The cities are 800 miles apart.
When do they meet?

A: Let's think step by step...

Just adding "Let's think step by step" or "Think through this carefully before answering" can significantly boost accuracy.

Role Prompting

Give the model a persona to adopt. This shapes tone, vocabulary, and depth.

You are a skeptical senior software architect reviewing a pull request.
Point out potential issues with the following code...

Instruction Following

Modern LLMs are fine-tuned to follow instructions. Be explicit about format, length, and constraints:

Summarize this article in exactly 3 bullet points.
Each bullet should be under 20 words.
Do not include information about the author.

Prompt Engineering vs. Programming

Prompt engineering is often compared to programming — but it works differently:

ProgrammingPrompt Engineering
LanguageFormal syntax, strict rulesNatural language, flexible
ErrorsCompiler / runtime errorsSubtle output degradation
DebuggingStack traces, logsIterating on outputs
ReuseFunctions, modulesPrompt templates
TestingUnit testsEval suites
Version controlGit diffsPrompt versioning

The skill transfer is real — programmers tend to pick up prompting quickly because they're used to being precise and thinking about edge cases.


Common Prompt Engineering Mistakes

Being vague about output format

❌ "Give me a list of ideas"
✓  "Give me 5 ideas as a numbered list, each 1 sentence long"

Overloading a single prompt

❌ "Summarize this, translate to Spanish, then classify the topic"
✓  Break into separate prompts or chain them explicitly

No examples when the task is ambiguous

❌ "Write in my style" (what style?)
✓  "Write in my style. Here are 3 examples of my writing: ..."

Asking the model to do math without CoT

❌ "What is 15% of 847?"
✓  "Calculate 15% of 847. Show your work step by step."

Ignoring the system prompt Most APIs let you set a system prompt — don't skip it. It's the most reliable way to enforce consistent behavior across all turns.


Why Prompt Engineering Is a Real Skill

You might think: "Can't I just describe what I want in plain English?"

You can — and you'll get decent results. But prompt engineering is about going from decent to reliable and production-grade:

  • A product with 1,000 daily users needs prompts that work 99% of the time, not 80%
  • Edge cases that seem rare at 10 users become daily occurrences at 10,000
  • Costs are directly tied to token count — a bloated prompt multiplied by millions of calls is expensive
  • Security matters — poorly designed prompts can be hijacked by users (prompt injection)

At the engineering level, prompts are code. They live in version control, get reviewed, get tested, and get optimized.


The Prompt Engineering Feedback Loop

1. Write a prompt
      ↓
2. Test it on representative inputs (including edge cases)
      ↓
3. Identify failure modes (too verbose? wrong format? hallucinating?)
      ↓
4. Diagnose: Is it a clarity issue? A context issue? A format issue?
      ↓
5. Refine the prompt
      ↓
6. Re-test → repeat until satisfactory
      ↓
7. Build an eval suite so regressions are caught automatically

Skipping step 7 is the most common mistake in production AI systems.


Prompt Engineering in the Age of Agents

As LLMs move from single Q&A interactions to multi-step agents that use tools, prompt engineering evolves:

  • System prompts define agent identity, capabilities, and constraints
  • Tool descriptions must be precise — the model decides when to call them
  • Reasoning prompts (ReAct, CoT) guide the agent's planning
  • Output parsers need structured generation prompts (JSON mode, XML tags)

Good agent behavior is 80% good prompting.


What's Next

  • Prompting Patterns — a catalog of the most effective techniques with examples
  • Context Engineering — managing what goes into the context window at scale
  • Structured Generation — getting reliable JSON and structured data from LLMs
  • Prompt Optimization — systematic approaches to improving prompt performance
  • Prompt Security — defending against injection attacks and jailbreaks

Never Miss an AI Job

Get the top AI & LLM jobs delivered to your inbox every week. Curated, not spammy.

Join 1,000+ AI professionals. Unsubscribe anytime.