Part 3 · The Right Vehicle

Prompt Engineering · ~7 min

Rules or Examples

A rule says "do it this way" and trusts the model to interpret. An example says "produce exactly this." Pick the wrong one and the agent invents its own intent.

Why this, for you: by now you can pitch a rule at the right altitude, frame it positively, and place it where attention lands. This lesson is about the vehicle — whether the instruction should be a rule at all, or an example. Choosing wrong is why precise formats still come out wrong.

Rules generalize. Examples anchor. That difference is not stylistic — it is a function of which kind of failure you are trying to prevent. Match the vehicle to the failure and the agent follows; mismatch it and the agent fills the gap with its own guess.

1 The trade-off

Each vehicle is cheap in one way and fragile in another.

Rules are compact and context-efficient — "use kebab-case filenames" costs five tokens and applies universally — but they can be misread: "write concisely" means different things to different agents. Examples are concrete and unambiguous but can be over-fitted — an agent shown one may copy its structure verbatim instead of abstracting the pattern.

So the question is never "which is better?" It is "which failure am I preventing — a misread, or an over-fit?"

2 When to use each

Use a rule for behavioral constraints where the output space is large, compliance is binary, and any reasonable interpretation is acceptable:

Use an example when format or structure matters precisely and a misinterpretation produces clearly wrong output — file naming, commit-message structure, output schemas. Examples are also strong for anti-patterns: pair "don't do this" with a concrete instance rather than describing the prohibited shape abstractly.

3 The reliable combination

The most dependable pattern is both at once: state the rule, then show one example. The rule gives a generalization to apply; the example gives a concrete reference to check against.

File names must be kebab-case and match the concept name. Example: progressive-disclosure.md # not ProgressiveDisclosure.md, not prog-disc.md

One example is usually enough. Multiple examples shift the agent's focus from the rule to the pattern of the examples themselves — it begins to interpolate between cases rather than apply the constraint uniformly.

Too many examples teaches interpolation

Several near-duplicate examples push the model to average across them — producing outputs that sit between the cases you showed instead of obeying the constraint they share. For a constraint rule, one well-chosen example suffices; pile on more and you trade a clean boundary for a blurry midpoint.

4 Hints over code samples

For format and style constraints inside a codebase, pointing at existing code beats reproducing an inline sample. A hint is a reference, not a reproduction.

Inline code sampleHint equivalent
A 30-line UserRepo class pasted in full"Follow the repository pattern in src/repos/UserRepo.ts"
A full example middleware function"Use the existing middleware in src/middleware/auth.ts"

Hints win on two counts. They stay current: an inline sample freezes the moment it is written and drifts as the real code changes, while a hint points at whatever the file says today. And they are cheaper: a 30-line example loaded every session draws on the context budget for every task, including unrelated ones — a hint costs one line. The one case for an inline sample is a genuinely novel pattern with no existing example; once any file implements it, replace the sample with a hint to that file.

5 Why it works

Rules and examples engage different machinery. GPT-3 established that models infer tasks from demonstrations alone, without fine-tuning or explicit rules (Brown et al., 2020). Mechanistic work traces this to induction heads — attention heads that find an earlier occurrence of the current token and copy what followed it (Olsson et al., 2022). An example supplies a template to replicate; a rule asks the model to derive the intended output space by inference. Combining the two engages both: the rule limits the interpretation space, and the example collapses the residual ambiguity to a specific format.

↪ Your win: match the vehicle to the failure

Retrieval practice — recall, don't peek

Question 1The characteristic failure mode of a rule is that it…

Question 2An example is the right vehicle when…

Question 3Showing several near-duplicate examples tends to make a model…

Question 4A hint to existing code beats an inline sample mainly because it…

Question 5 · spaced recall from Lesson 5For coding agents on SWE-bench, the only individually beneficial rule type was…

Ask me anything. Want a pass over your instruction file converting pasted samples into hints, or help deciding which rules deserve a paired example? Next, the Capstone: The Compliance Stack — every lever in this course, applied to one prompt.
✎ Feedback