The code-generation skeleton

The four-block skeleton

4 min read

Every code-generation prompt that survives review has the same four blocks. Memorise them and you'll never write a vague code prompt again.

BlockWhat it answersExample fragment
INTENTWhat is the function for?"Write dedupe_preserve_order(items: list[str]) -> list[str]."
CONSTRAINTSWhat rules must the code obey?"O(n) time. No external imports. Type hints required."
TESTSHow will I know it's correct?"Include 4 assert cases inside if __name__ == '__main__':."
FORMATHow 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 INTENT and the model invents the signature. It might give you dedupe_list instead of dedupe_preserve_order.
  • No CONSTRAINTS and the model picks defaults that won't survive code review. It might import a third-party package, or use O(n^2) because it's "more readable."
  • No TESTS and 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 FORMAT and the model wraps the code in tutorials, alternative implementations, "you might also like…" sections. You can't paste that into a .py file.

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

1. INTENT
2. CONSTRAINTS
3. TESTS
4. FORMAT

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. :::

Quiz

Module 1: The Codegen Skeleton

Take Quiz
Was this lesson helpful?

Sign in to rate

FREE WEEKLY NEWSLETTER

Stay on the Nerd Track

One email per week — courses, deep dives, tools, and AI experiments.

No spam. Unsubscribe anytime.