Chapter 8 · 9 lessons · 8260 min

The Art of Prompting

Better prompts. Better outputs. Less frustration.

Overview

Prompting is real engineering — repeatable, testable, version-controlled. This chapter teaches the patterns that turn 'meh' AI output into reliable, production-grade results.

What you'll learn

  • The 5-part prompt formula: Role, Context, Task, Format, Examples.
  • Advanced patterns: chain-of-thought, few-shot, self-critique, structured JSON.
  • How to build prompts that survive prompt injection attacks.
  • Cost and latency tradeoffs: model size, caching, streaming.

Who this chapter is for

Developers building AI features into products. Researchers evaluating models. Power users who want consistent outputs instead of luck.

Lessons in this chapter

All lessons are free and open — start anywhere, in any order.

  1. 1
    Anatomy of a Great Prompt
    Role, context, task, format, examples — the five-part formula that always works.
    114 min
  2. 2
    Advanced Prompting Patterns
    System prompts, role chains, structured output, and prompt injection awareness.
    114 min
  3. 3
    Make AI Actually Understand What You Want
    The mental model: AI is a brilliant intern with amnesia. Brief it like one.
    115 min
  4. 4
    10 Prompt Templates You Can Steal Today
    Copy, paste, fill in the blanks. Battle-tested prompts for the most common tasks.
    7355 min
  5. 5
    When AI Gives You Garbage: The Debug Playbook
    Hallucinations, generic fluff, wrong format, forgotten instructions — fix any of them in under 60 seconds.
    113 min
  6. 6
    Prompting for Code & Building Products
    How to brief Cursor, Lovable, Claude Code, and friends so you actually ship instead of debug.
    116 min
  7. 7
    Common Mistakes & How to Avoid Them
    The 5 traps beginners fall into when working on the art of prompting — and the fix for each.
    111 min
  8. 8
    A Real-World Walkthrough
    A start-to-finish example of applying the art of prompting to a real project you can copy.
    111 min
  9. 9
    Mental Models That Actually Help
    The 3 mental models we keep coming back to when things get hard in the art of prompting.
    111 min

Glossary

Key terms used throughout this chapter.

System / User / Assistant
The three message roles in chat-style APIs. System sets behavior, user asks, assistant replies.
JSON mode
Forcing the model to return only valid JSON matching a schema.
RAG
Retrieval-Augmented Generation — fetching relevant context from a database before prompting.
Prompt injection
A malicious input that tries to override the system prompt or extract secrets.
Function calling
Letting the model decide when to call your code (search, calculator, DB query).
Top-p / temperature
Sampling parameters that control creativity vs. determinism.

Try it yourself

Knowledge sticks when you use it. Do at least one of these before moving on.

  1. 01.Take a one-line prompt you've used. Rewrite it with all 5 parts (role, context, task, format, examples).
  2. 02.Build a prompt that returns strict JSON. Validate the output with Zod or JSON Schema.
  3. 03.Try a prompt injection on your own app: paste 'Ignore previous instructions...' into a user input. Patch the leak.

Further reading & sources

Primary, official sources we cross-checked against while writing this chapter.