The code-generation skeleton
Writing TESTS and FORMAT
The TESTS block does two things at once. It tells the model what "correct" means, and it gives you executable proof when the answer arrives. Skip it and you're trusting the vibes.
A good TESTS block lists 3–5 specific cases. Each case names an input, an expected output, and — implicitly — the property being tested. You don't need pytest scaffolding; assert is enough.
Compare these two attempts:
Weak tests block:
Include some test cases.
Strong tests block:
Include 4
asserttest cases inside anif __name__ == "__main__":block: 1. Empty list returns[]. 2. Single-item list returns the same list. 3.["a","b","a","c","b"]returns["a","b","c"]. 4. Case-sensitivity:["Apple","apple","Apple"]returns["Apple","apple"].
The strong block does what a unit test should do: it covers an edge case (empty), a degenerate case (single item), the happy path, and the case-sensitivity behaviour from CONSTRAINTS. Each line is one property the function must satisfy.
The pattern: one property per assert. Two properties in one assert and you can't tell which one failed. Three properties and the test will pass for the wrong reason eventually.
The shape of a strong TESTS block, mapped to coverage:
FORMAT is the simplest block, but the one engineers most often skip. It controls the envelope around the answer, not the answer itself. Without it, the model wraps your function in markdown explanations, alternative implementations, and friendly chatter that breaks paste-into-file workflows.
These format directives work well:
| Directive | What it does |
|---|---|
Output ONLY a single code block. | Strips prose around the code. |
No markdown fences. | For when you want to pipe to a file directly. |
No prose, no comments. | For when you only want the function body. |
Wrap in unified diff format. | For paste-into-Cursor workflows (module 5). |
Capital "ONLY" matters — it's a strong signal in instruction-tuned models. Models trained on RLHF have a tendency to be helpful, which often means adding context the user didn't ask for. FORMAT is your tool for shutting that off.
The four blocks together mean the function arrives ready to commit. In the next lesson you'll see all four applied to the same dedupe task that failed in lesson 1 — and the difference is night and day.
Next up: the worked example. :::
Sign in to rate