Module 1: Fundamentals of Prompt Engineering
1. Introduction: Prompt Engineering as a Discipline
Overview
This is the first capsule of Module 1 of Advanced Prompt Engineering. Here you'll understand the fundamental difference between "using ChatGPT" and doing professional prompt engineering. Most developers who work with LLMs write prompts by intuition: they try something, if it works they keep it, if it doesn't they rewrite it until it "looks good". That doesn't scale in production.
Prompt engineering as a discipline means designing inputs for LLMs that produce predictable, measurable and optimized outputs. It's not art or magic: it's engineering with principles, patterns and reproducible practices. This module gives you the mental framework and the tools you'll use across the next 7 modules.
Why it matters: Without understanding prompt engineering as a discipline, the later modules (zero-shot, few-shot, CoT, ReAct, evaluation) would be loose techniques with no context. With this foundation, every technique fits into a coherent framework: identifiable components, roles that control behavior, parameters that shape results.
The difference: using ChatGPT vs prompt engineering
Using ChatGPT (the casual approach)
- You write a question or an instruction
- If the answer is good, you use it
- If it isn't, you rewrite it and try again
- No method, no metrics, no reproducibility
- Works for personal tasks and exploration
Prompt engineering (the professional approach)
- You design prompts with identifiable components (instruction, context, input, output format)
- You configure roles (system, user, assistant) as a behavior contract
- You tune parameters (temperature, max_tokens) to the use case
- You evaluate with objective metrics, not with "it looks good"
- You version prompts, run A/B tests, optimize costs
- Works for production systems serving real users
The transition: "What you do works sometimes" → "it works every time, with any model, predictably".
Prompt engineering as an engineering skill
Why it isn't "art"
Art: Subjective, dependent on individual talent, hard to replicate.
Engineering: Systematic, principle-based, reproducible by any team.
Evidence that it's engineering:
-
Identifiable components: A professional prompt has structure: instruction, context, input, output format. You can analyze it, break it apart, and improve it piece by piece.
-
Configurable parameters: Temperature, top_p, max_tokens shape the result predictably. It's not "the model decided" — it's "you set X and got Y".
-
Objective evaluation: Metrics like accuracy, faithfulness, format compliance let you measure whether a prompt got better or worse. Not "it looks good" but "score 0.92 vs 0.78".
-
Versioning and CI/CD: Prompts get versioned, tested, and deployed like any other software artifact. A change in the prompt can break a system; that's why regression testing exists.
Analogy: Writing prompts as engineering is like writing SQL. A junior developer writes queries that "work sometimes". A senior designs optimized queries, with indexes, with constraints, that always work and stay maintainable. Prompt engineering is the same jump in level.
Two kinds of problems it solves
Problem 1: inconsistent outputs
Without a method, the same prompt can return very different results across successive calls, especially when you switch model or version.
from openai import OpenAI
client = OpenAI()
# Casual prompt — high temperature, no format constraints
for i in range(3):
r = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Classify this email as urgent or not urgent: 'The production server is down.'"}],
temperature=0.7 # High — variable results
)
print(f" Attempt {i+1}: {r.choices[0].message.content}")
# It may produce:
# Attempt 1: "Urgent"
# Attempt 2: "This email clearly indicates an urgent situation, since..."
# Attempt 3: "URGENT - Requires immediate attention"
# Engineered prompt — temperature 0, strict format
for i in range(3):
r = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "Classify emails. Answer ONLY with: URGENT or NOT_URGENT. Nothing else."},
{"role": "user", "content": "The production server is down."}
],
temperature=0,
max_tokens=5
)
print(f" Attempt {i+1}: {r.choices[0].message.content}")
# It always produces:
# Attempt 1: URGENT
# Attempt 2: URGENT
# Attempt 3: URGENT
Problem 2: unpredictable behavior across models
import anthropic
oai = OpenAI()
ant = anthropic.Anthropic()
# Same casual prompt on two models
casual_prompt = "Summarize this text: 'The market fell 3% yesterday on inflation figures.'"
r_oai = oai.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": casual_prompt}],
temperature=0
)
r_ant = ant.messages.create(
model="claude-3-5-haiku-20241022",
messages=[{"role": "user", "content": casual_prompt}],
temperature=0,
max_tokens=100
)
# Both work, but the format can vary between models
# For code that depends on the output: a potential problem
# Engineered prompt — same result on both:
engineered_prompt = """
Summarize in exactly 1 sentence, maximum 15 words, in English.
Text: "The market fell 3% yesterday on inflation figures."
Summary:"""
# Consistent result regardless of the model
Where it sits in the AI engineering stack
┌─────────────────────────────────────────────────────────┐
│ AI Engineering Stack │
├─────────────────────────────────────────────────────────┤
│ Deployment, Monitoring, Cost Optimization (Level 3) │
│ Evaluation, Testing, Guardrails (Level 2) │
│ Agents, RAG, Chains (Level 1) │
│ ← Prompt Engineering (THIS GUIDE) │
│ LLM Access, APIs, Python (Fundamentals) │
└─────────────────────────────────────────────────────────┘
Prompt engineering is the layer between: "You know how to call LLM APIs" and "You build RAG systems, agents, chains".
- Every AI system uses prompts: a chatbot's system prompt, a RAG's prompt for generating answers, an agent's instructions.
- Without well-designed prompts, the best RAG or the best agent still fails on inconsistent outputs, wrong formats, or unpredictable behavior.
- This guide gives you the foundation so that when you build RAG (guide #8), agents (guide #11), or evaluation pipelines, your prompts are production-ready.
What changes with this guide
Before (if you only used ChatGPT or basic APIs):
- Prompts by intuition
- No component structure
- No system prompts as a contract
- No parameters set on purpose
- No evaluation beyond "I tried it and it worked"
After (once you finish this guide):
- Prompts with a method (CRISPE, anatomy, roles)
- Identifiable, measurable components
- System prompts that control behavior
- Parameters chosen for the use case
- Evaluation with metrics, regression testing, A/B testing
- Prompts versioned and managed in production
Module 1 roadmap
| # | Capsule | What you'll see |
|---|---|---|
| 01 | Introduction (this one) | Prompt engineering as a discipline, its place in the stack |
| 02 | Anatomy of a prompt | Components: instruction, context, input, output format. Tokens |
| 03 | Roles: system, user, assistant | The system prompt as a contract. Multi-turn |
| 04 | Temperature and parameters | temperature, top_p, max_tokens. When to use each value |
| 05 | Mental models (CRISPE) | A framework for designing prompts systematically |
| 06 | Comparison: casual vs engineered | Side-by-side with metrics. When the basics are enough |
| 07 | Providers and their differences | OpenAI vs Anthropic vs Google. Adapter patterns |
| 08 | Project: Prompt Analyzer | A system that classifies, breaks down and suggests improvements |
Estimated duration: 1.0-1.25 hrs for the full module.
What this module does NOT cover
- Fine-tuning: Adjusting the model's weights (that requires training, it's out of scope)
- Prompt injection in depth: We cover basic guardrails in M3; advanced attacks belong to specialized security
- Jailbreaking: Techniques for breaking safety guardrails aren't useful in production
- Mathematical NLP: Attention, embeddings, weight matrices — that's for people who build models, not people who use them
What it does cover: Everything an AI Engineer needs to use LLMs in production, professionally and reproducibly.
Technical setup
Prerequisites
- Python 3.11+
- An OpenAI API key (or Anthropic for comparisons)
- Experience with
requestsor API SDKs
Installation
# Create a virtual environment
python -m venv venv
source venv/bin/activate # Mac/Linux
# venv\Scripts\activate # Windows
# Install dependencies
pip install openai>=1.0.0 anthropic>=0.25.0 python-dotenv>=1.0.0 pydantic>=2.0.0
The .env file
# .env
OPENAI_API_KEY=sk-proj-...
ANTHROPIC_API_KEY=sk-ant-... # Optional, for capsule 07
Verify the installation
# verify_setup.py
import os
from openai import OpenAI
from dotenv import load_dotenv
load_dotenv()
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Say exactly: 'Setup correct'"}],
temperature=0,
max_tokens=20
)
print(response.choices[0].message.content)
# Expected output: Setup correct
How this connects to the rest of the guide
This module is the conceptual foundation for everything that follows:
- M2 (Zero-Shot / Few-Shot): Uses prompt anatomy to build examples with a method
- M3 (Structured Outputs): Extends "output format" to Pydantic schemas and JSON mode
- M4 (Chain-of-Thought): Adds "reasoning" as a component inside the output format
- M5 (ReAct): Combines the "context" with tools and external observations
- M6 (Prompt Composition): Chains multiple prompts with a well-defined anatomy
- M7 (Evaluation): Measures each anatomy component with objective metrics
- M8 (Production): Versions, caches and monitors prompts with a consistent structure
A prompt engineer's cycle in production
In practice, working with prompts in production follows an iterative cycle you'll see applied in every module:
1. DESIGN
Define the goal → Pick components (CRISPE) → First draft
│
▼
2. TEST
Run it on representative examples → Capture outputs
│
▼
3. EVALUATE
Measure with objective metrics → Identify failures per component
│
▼
4. REFINE
Fix the component that fails → Don't rewrite everything
│
▼
5. VERSION
Save the version → Tag the change → Regression tests
│
└──────────────── Repeat with a new task ────────────────▶
This cycle shows up in the Prompt Analyzer (M1-08), in the Few-Shot System (M2-08), in the Structured Data Extractor (M3-08), and in every project of the guide. By the end of this guide, you'll have internalized this cycle as a way of working.
First code: a direct comparison
The code below shows, in 30 lines, the key difference between a casual and an engineered prompt on a concrete case: classifying the urgency of support tickets.
from openai import OpenAI
from dotenv import load_dotenv
load_dotenv()
client = OpenAI()
TICKET = "The production database has been unresponsive for 20 minutes. Users affected: 5000."
# === CASUAL PROMPT ===
r_casual = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": f"Is this urgent? {TICKET}"}],
temperature=0.7
)
print("Casual:", r_casual.choices[0].message.content[:100])
# It may return: "Yes, this is very urgent because..." (free text, not parseable)
# === ENGINEERED PROMPT ===
r_eng = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": (
"You are an urgency classifier for support tickets. "
"Classify into: CRITICAL, HIGH, MEDIUM, or LOW. "
"Answer ONLY with the category. Nothing else."
)
},
{"role": "user", "content": TICKET}
],
temperature=0,
max_tokens=10
)
print("Engineered:", r_eng.choices[0].message.content)
# Always returns: CRITICAL
Across the 8 capsules of this module you'll learn exactly why each decision in the "engineered prompt" (system prompt, temperature=0, max_tokens, response format) matters, and what happens when you change them.
Evidence of success
By the end of this module you should be able to:
- Explain prompt engineering as a discipline (not as "tips") in 3 sentences
- Identify the 4 components of a prompt in any example
- Set temperature and max_tokens deliberately, based on the use case
- Design a prompt using the CRISPE framework
- Compare OpenAI's and Anthropic's behavior on the same prompt
- Build a working basic Prompt Analyzer (capsule 08)
Frequently asked questions when starting out
Do I need to know Machine Learning for this guide? No. This guide assumes you know Python and how to consume REST APIs. You don't need to understand how a transformer works internally to design effective prompts.
Will the prompts in this guide still work in 6 months, when the models change? The principles will. The exact parameter values may need adjusting. The CRISPE framework, prompt anatomy, and the zero-shot/few-shot patterns are fundamentals that hold regardless of the model. Module 7 (Evaluation) gives you the tools to detect when a prompt regresses on a new model.
How long does it take to master prompt engineering? To have production-ready prompts: 2-3 weeks of active practice. To master advanced techniques (CoT, ReAct, evaluation): 2-3 months of work on real projects. This guide gives you the map; the projects in each module are the deliberate practice.
Should I use OpenAI or Anthropic? Start with OpenAI (gpt-4o-mini for practice, low cost). Capsule 07 explains the differences and when to use each. Modules 7 and 8 cover multi-provider in production.
Summary
- Prompt engineering is an engineering discipline, not art: identifiable components, configurable parameters, objective evaluation.
- Key difference: Using ChatGPT = intuition. Prompt engineering = a reproducible method.
- Where it sits: The layer between "LLM APIs" and "RAG, agents, chains". Every AI system uses prompts.
- What changes: From "it works sometimes" to "it works every time, with any model, predictably".
- In this module: Anatomy, roles, parameters, CRISPE, a provider comparison, and the Prompt Analyzer as the project.
- Limits: It doesn't cover fine-tuning, jailbreaking, or mathematical NLP. Only what an AI Engineer uses in production.
Further resources
- OpenAI API Reference — Official API documentation and available parameters
- Anthropic Messages API — Claude's API, with design differences from OpenAI's
- Prompt Engineering Guide (OpenAI) — Official prompting guide with recommended strategies
- Learn Prompting — Introductory prompt engineering resources with examples
- tiktoken — OpenAI's library for counting tokens in your prompts
- Prompting Guide (DAIR.AI) — A comprehensive reference of prompting techniques, with papers