Skip to content
Tutorials Center
My learning

Topics

Prompt Engineering Tutorial

Learn Prompt Engineering step by step: 38 lessons in 9 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is Prompt Engineering? Learn what prompt engineering is, why the way you phrase a request changes a language model's answer, and how this course teaches it with runnable Python.
  2. 2 How Language Models Read Prompts Understand tokens, context windows and next-token prediction, the mental model that explains why prompts behave the way they do. Includes runnable Python.
  3. 3 Model Settings: Temperature, Top-p and Max Tokens Learn what temperature, top-p, max tokens and stop sequences do to a model's output, with numpy simulations that show how sampling really works.
  4. 4 The Anatomy of a Prompt Break a prompt into parts: role, task, context, constraints, examples and output format. Build and test a reusable prompt builder in Python.

Prompting Fundamentals

  1. 5 Writing Clear, Specific Instructions Turn vague requests into specific, testable instructions: say what to do, how much, for whom and what to avoid. Includes a runnable specificity checker.
  2. 6 Giving Context and Naming the Audience Learn how background, purpose and audience change a model's answer, how much context is enough, and how to inject context from data with Python.
  3. 7 Controlling Output Format and Length Ask for lists, tables, headings or exact word counts and verify the result in code. Learn format instructions, length control and post-processing checks.
  4. 8 Delimiters and Prompt Templates Use delimiters, XML-style tags and templates to separate instructions from data, keep prompts maintainable and avoid confusion. Includes Python templating.
  5. 9 Iterating and Versioning Prompts Improve prompts the disciplined way: change one thing at a time, test on a fixed set of inputs, diff versions and keep a changelog. Runnable Python included.
  6. 10 Common Prompt Mistakes and How to Fix Them Ten frequent prompt-writing mistakes, from vague tasks and buried instructions to conflicting rules and fake certainty, each with a fix and a runnable checker.

Techniques: Few-shot, Chain-of-Thought and Roles

  1. 11 Zero-Shot and Few-Shot Prompting Learn when to give a model no examples (zero-shot) or a few (few-shot), how many to use, and how to build few-shot prompts programmatically in Python.
  2. 12 Choosing Good Few-Shot Examples Pick few-shot examples that work: cover the label space, include edge cases, balance classes, watch ordering bias and select examples dynamically in Python.
  3. 13 Chain-of-Thought Prompting Learn chain-of-thought prompting: asking a model to reason step by step before answering. When it helps, when it does not, and how to separate reasoning from the answer.
  4. 14 Self-Consistency and Prompt Chaining Combine several model runs by majority vote (self-consistency) and split big jobs into a chain of small prompts. Runnable Python simulations included.
  5. 15 Roles, Personas and System Prompts Learn how roles and personas shape tone and focus, how system, user and assistant messages differ, and how to write and test a system prompt in Python.

Structured Output and Tool Use

  1. 16 Getting Structured Output (JSON) from a Model Ask a model for JSON that your program can parse: schemas, field descriptions, examples, enums and strict output modes. Includes runnable Python schema tools.
  2. 17 Validating and Repairing Model JSON Handle messy model output: extract JSON from chatter, fix common syntax slips, validate against a schema and retry with error feedback. Runnable Python.
  3. 18 Function Calling and Tool Use Learn how tool use works: describing functions to a model, how it requests calls, writing good tool descriptions and dispatching calls safely in Python.
  4. 19 The Tool-Calling Loop Build the loop behind assistants that use tools: send messages, run requested calls, feed results back and stop safely. Runnable simulation with a scripted model.

Retrieval and Context Engineering

  1. 20 The Context Window and Token Budgets Learn what a context window is, how tokens are counted, and how to split a prompt budget between instructions, context, history and the answer.
  2. 21 Retrieval-Augmented Generation (RAG) Basics Understand retrieval-augmented generation: find relevant text first, then ask the model to answer only from it. Build a tiny retriever and grounded prompt.
  3. 22 Chunking Documents for Prompts Learn how to split documents into chunks for retrieval: fixed size, sentence and heading-based splitting, overlap, metadata and how to choose sizes.
  4. 23 Ranking, Deduplicating and Assembling Context Turn raw retrieval hits into a clean prompt: pick top-k, remove near-duplicates, balance relevance with diversity, order passages and fit the token budget.
  5. 24 Conversation Memory and Summarization Manage chat history in prompts: sliding windows, rolling summaries, pinned facts and long-term memory stores, with runnable examples and trade-offs.

Evaluation and Testing Prompts

  1. 25 Building a Prompt Test Set Stop judging prompts by gut feeling. Build a small, representative test set with expected answers, edge cases and tags, and run it against any prompt.
  2. 26 Metrics for Prompt Outputs Choose the right metric for each prompt: exact match, accuracy, precision and recall, token F1, rule checks, format validity and latency, with runnable code.
  3. 27 Regression Testing and Comparing Prompts Compare two prompt versions case by case, spot regressions, handle non-deterministic outputs with repeated runs, and decide when a gain is real or noise.
  4. 28 LLM-as-Judge and Scoring Rubrics Use a model to grade open-ended outputs: write clear rubrics, request structured verdicts, avoid judge bias and calibrate the judge against human labels.

Safety, Injection and Guardrails

  1. 29 Prompt Injection: How Attacks Work Understand prompt injection and jailbreaks: why models cannot separate instructions from data, direct and indirect attacks, risks for agents, and how to threat-model.
  2. 30 Defending Against Prompt Injection Learn layered defenses against prompt injection: delimiting untrusted text, least privilege for tools, human approval, output checks and tests that prove it holds.
  3. 31 Guardrails and Output Checking Build guardrails around a language model: input checks, output validators, topic limits, moderation, safe fallbacks, and how to measure false positives and misses.
  4. 32 Privacy and PII Handling in Prompts Keep personal data out of prompts and logs: detect and redact PII, use reversible placeholders, minimize context, and set retention rules for LLM applications.

Prompt Patterns in Production

  1. 33 Prompt Libraries in Production Move prompts out of scattered strings into a versioned registry: templates with typed variables, release labels, safe rollouts, rollbacks and tests in your pipeline.
  2. 34 Cost, Latency and Caching for LLM Apps Estimate and cut what a prompt costs: count tokens, shorten prompts, cache repeated work, route easy tasks to small models, stream output and batch background jobs.
  3. 35 Monitoring and Feedback Loops for Prompts Watch a prompt after launch: structured logs, quality and cost metrics, user feedback, drift detection, alerts, and turning production failures into new test cases.

Projects and Practice

  1. 36 Project: A Support Ticket Classifier Build a support ticket classifier end to end: write the prompt, validate JSON output, add a fallback, build a labelled test set, measure accuracy and fix the failures.
  2. 37 Project: Grounded Question Answering Build a small retrieval-augmented question answerer: chunk and index documents, retrieve the best passages, assemble a cited prompt, check grounding and handle unanswerable questions.
  3. 38 Practice: Prompt Review Challenges Practice finding and fixing weak prompts: ambiguous instructions, missing formats, leaky templates, unsafe tools and untestable goals, with a self-check linter and answer notes.