The code-generation skeleton
The four-block skeleton
Every code-generation prompt that survives review has the same four blocks. Memorise them and you'll never write a vague code prompt again.
| Block | What it answers | Example fragment |
|---|---|---|
INTENT | What is the function for? | "Write dedupe_preserve_order(items: list[str]) -> list[str]." |
CONSTRAINTS | What rules must the code obey? | "O(n) time. No external imports. Type hints required." |
TESTS | How will I know it's correct? | "Include 4 assert cases inside if __name__ == '__main__':." |
FORMAT | How should the answer be shaped? | "Output ONLY a single Python code block, no prose." |
Why these four? Each one closes a class of failure mode you saw in lesson 1:
- No
INTENTand the model invents the signature. It might give youdedupe_listinstead ofdedupe_preserve_order. - No
CONSTRAINTSand the model picks defaults that won't survive code review. It might import a third-party package, or useO(n^2)because it's "more readable." - No
TESTSand you have to write them yourself before you trust the function. Worse, the model will sometimes return code that compiles but is subtly wrong. - No
FORMATand the model wraps the code in tutorials, alternative implementations, "you might also like…" sections. You can't paste that into a.pyfile.
The order matters. INTENT first because the model needs to know what to build before it considers how. CONSTRAINTS second because they shape the implementation. TESTS third because they're the executable definition of correctness. FORMAT last because it controls the output envelope, not the substance.
The skeleton, stacked top-down:
The four-block codegen skeleton
You'll see in the next three lessons that each block has its own micro-skills. INTENT is more than a sentence — you need to specify the signature, the side-effects, and the failure modes. CONSTRAINTS covers performance, dependencies, style, and security. TESTS is where you trade verbosity for correctness — three sharp asserts beat ten vague ones. And FORMAT is the difference between code you can Cmd+V and code you have to clean up first.
The skeleton works for Python, TypeScript, Go, Rust, SQL — language-agnostic. It also works at scales above one function: you'll re-use it in module 3 for refactor prompts and in module 6 for the capstone PR.
Next up: how to write the INTENT and CONSTRAINTS blocks well.
:::
Sign in to rate