Skip to content

Prompt Engineering

Beginner → Intermediate · 8 topics

The LLMs notes introduced prompts: the parts of a good one, few-shot examples and templates. This series goes deeper, into the skills that separate a prompt that worked once from one you can ship: instructions a model follows on the first try, examples chosen on purpose, reasoning and chaining for hard tasks, reliable structured output, defence against prompt injection, and testing prompts like code.

# Nothing to install. Every example uses only the Python standard library and a fake model, so it runs offline.
# Code that needs an API key or a project layout is marked "no-run".
# Topic Sub-topics
1 Writing clear instructions The new-colleague test · reasons behind rules · success criteria · numbers over adjectives · ordering long prompts · prefill · linting prompts
2 Few-shot examples in depth Zero-, few- and many-shot · auditing an example set · examples as messages · order effects · retrieving similar examples · when examples hurt
3 Reasoning techniques Chain of thought with tags · self-consistency voting · decomposition · step-back prompting · self-critique · prompting reasoning models
4 Prompt chaining & routing One prompt vs a chain · a working chain · validation gates · routers · map-reduce for long inputs · chains vs agents
5 Structured output prompting Field descriptions · nulls, not guesses · validation · repair loops · evidence and confidence · classification · native schema mode
6 Prompt injection & defensive prompting Direct vs indirect · delimiters and spotlighting · instruction hierarchy · input and output checks · least privilege · attack sets
7 Testing & versioning prompts Eval sets · code checks vs LLM judges · comparing versions · regression tests in CI · a prompt registry · cost optimisation
8 Prompt recipes for common tasks Summaries · classification · extraction · grounded RAG answers · rewriting · code review · agent system prompts
flowchart LR
    W[Clear instructions] --> E[Examples] --> R[Reasoning] --> C[Chains & routing]
    C --> S[Structured output] --> D[Injection defence] --> T[Tests & versions]

Before you start

Read Prompt engineering in the LLMs notes first; it covers the basics these pages build on. For ready-made prompts by industry, see the Prompt library.

Back to: Notes overview