Code generation uses AI models to produce source code from instructions, context, or existing code.
What is it?
Code generation is the capability to produce new or modified source code from instructions, context, or existing code.
Inputs include natural-language instructions, an existing repository, a function signature, or code context. Outputs include new or modified code.
Think of it like...
A programmer receives a task description and drafts code based on the available project context. The draft can save time, but it still needs review and testing.
How it works
1 · TaskDescribe the workAn instruction explains what code should be created or changed.
2 · Code contextGather what mattersRelevant files, signatures, and patterns are provided.
3 · ModelPredict code tokensThe model uses learned patterns to predict a likely continuation.
4 · Generate codeProduce an outputIt returns new code or a modification.
5 · Review / testCheck the resultPeople or automated checks look for errors and security issues.
6 · RefineImprove the draftFeedback and failures guide another version.
Real-world examples
Write a function
Describe a function and the model drafts its implementation.
Generate SQL
Give a schema and question; the model proposes a query to review.
Create tests
Provide a function; the model drafts normal, boundary, and failure cases.
Translate languages
Ask for a module to be translated while preserving its intended behavior.
What it is NOT
Code Generation ≠ Coding Agent
A coding agent adds tools and actions around code generation.
Code Generation ≠ Compiler
A compiler translates code according to language rules; a model drafts or transforms source code.
Generated Code ≠ Guaranteed Correct Code
Generated code can contain bugs, insecure patterns, or wrong assumptions.
Related concepts
Generative AI→Code Generation
Coding agents add repository tools, execution, and feedback loops.