appendix-b

Appendix B. Prompt Engineering Reference

 

Throughout this book you prompt an AI coding companion to write SQL, generate Python, clean data, and extract structured records. The quality of what you get back depends almost entirely on the quality of what you send. This appendix collects the prompting techniques used across the book into one quick reference you can return to whenever a prompt is not giving you what you need.

Each technique includes what it is, when to reach for it, and a short example. The chapters where each is introduced are noted so you can revisit the full treatment.

B.1 The anatomy of a prompt

Most effective prompts have four parts, even if you do not write them as separate sentences:

  • Role / context — who the model should act as and what situation it is in ("You are a data engineering assistant building a product database").
  • Task — the specific thing you want done ("extract the product name, price, and weight").
  • Input — the data or code the task operates on.
  • Output format — exactly how you want the answer ("return a pandas DataFrame," "respond with only JSON matching this schema").

The single most common cause of a bad response is a missing output-format instruction. The model does not know your environment or your intent unless you spell it out. "Write a Python script" can give you a terminal program with a __main__ block; "write Python code to run in a notebook" gives you something you can paste into a cell. One clause, big difference (Chapter 4).

B.2 Zero-shot prompting

B.3 Few-shot prompting

B.4 Chain-of-thought prompting

B.5 Self-consistency

B.6 Tree-of-thought

B.7 Role-playing, domain priming, and prompt chaining

B.8 Structured-output prompting

B.9 Common pitfalls and how to handle them

B.10 A reusable prompt checklist