ModelRefs / Code Generation — AI Glossary
Code Generation — AI Glossary
LLM-driven production of complete code files, functions, or programs from natural language specifications or docstrings.
Overview
Code generation models (GPT-4o, Claude 3.5 Sonnet, Gemini 1.5 Pro, DeepSeek-Coder-V3) generate complete implementations from natural language descriptions. Evaluated by Pass@k on HumanEval, MBPP, LiveCodeBench, and BigCodeBench. Production use cases: scaffolding new features, generating boilerplate, writing unit tests, and code translation.
Reference details
| Topic | applications |
|---|---|
| Last reviewed | 2026-06-24 |
Related terms
How it works
- The prompt is assembled from the specification plus whatever context the tool can gather — signatures, type definitions, imports, and nearby code — because the model can only match conventions it has been shown.
- Generation is ordinary autoregressive decoding over the same token vocabulary as prose; nothing in the mechanism enforces syntax, which is learned from the training distribution rather than imposed.
- Models used for in-file completion are additionally trained on a fill-in-the-middle objective, where a span is removed and must be reconstructed from text on both sides rather than from a prefix alone.
- Output is then parsed or compiled, which is the first point at which any correctness signal exists at all.
- Tests are executed and failures returned to the model as context, making the loop a search over candidate implementations guided by whichever checks happen to exist.
- Everything the checks do not cover — error handling, resource cleanup, consistency with the surrounding system — is unconstrained by the loop, so it reaches review untested rather than tested and passing.
Example: What the benchmark does not measure, and how much of it reaches production
A function that passes every provided test can still hard-code the test cases, ignore error handling, or import a package that is not in your lockfile. Pass@k measures whether generated code satisfies given tests — not whether it is safe, maintainable, or consistent with the codebase around it. Review effort is the real cost, and it does not appear in the score. Follow the funnel for a batch of 200 generated functions. If 85% pass their tests, that is 170 that arrive at review looking correct, and the 30 that failed were caught for free. Suppose 10% of the passing ones carry a defect the tests could not see: 170 x 0.10 = 17 defects, all of them wearing a green check. If review catches 70% of those, 17 x 0.30 ≈ 5.1 reach production. The dangerous population is not the code that failed — it is the code that passed and was wrong, and its size is set by test coverage rather than by the model.
Commonly confused with
Code generation is not code understanding. A model can write a plausible implementation without having understood the surrounding system — which is why generation quality on a benchmark and usefulness in a large repository diverge sharply. The practical marker is which failures appear: a generation failure produces code that does not work, while an understanding failure produces code that works and is wrong for this codebase, duplicating a helper that already exists or violating a convention nothing enforces.
When to use it
Reach for it when:
- Boilerplate, scaffolding, test stubs and translation between languages
- The output will be reviewed before it runs
- The task is well specified and locally scoped
- Where test coverage is good enough that passing means something
Reach for something else when:
- Nothing reviews the output before it reaches production
- The change spans a system the model cannot see
- Correctness is safety-critical and the tests are the model's own
- Where the passing-but-wrong population is unmeasured, since that is where the 5.1 defects above came from
Continue your research
Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to Code Generation — AI Glossary.
Frequently asked questions
What is Code Generation?
LLM-driven production of complete code files, functions, or programs from natural language specifications or docstrings.
What concepts are related to Code Generation?
Closely related concepts include code completion, code review ai, test generation.