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.
- 1Anatomy of a Great PromptRole, context, task, format, examples — the five-part formula that always works.114 min
- 2Advanced Prompting PatternsSystem prompts, role chains, structured output, and prompt injection awareness.114 min
- 3Make AI Actually Understand What You WantThe mental model: AI is a brilliant intern with amnesia. Brief it like one.115 min
- 410 Prompt Templates You Can Steal TodayCopy, paste, fill in the blanks. Battle-tested prompts for the most common tasks.7355 min
- 5When AI Gives You Garbage: The Debug PlaybookHallucinations, generic fluff, wrong format, forgotten instructions — fix any of them in under 60 seconds.113 min
- 6Prompting for Code & Building ProductsHow to brief Cursor, Lovable, Claude Code, and friends so you actually ship instead of debug.116 min
- 7Common Mistakes & How to Avoid ThemThe 5 traps beginners fall into when working on the art of prompting — and the fix for each.111 min
- 8A Real-World WalkthroughA start-to-finish example of applying the art of prompting to a real project you can copy.111 min
- 9Mental Models That Actually HelpThe 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.
- 01.Take a one-line prompt you've used. Rewrite it with all 5 parts (role, context, task, format, examples).
- 02.Build a prompt that returns strict JSON. Validate the output with Zod or JSON Schema.
- 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.
