Learn AI /Generative Media /Code generation
Code generation
- Starter
- Generative Media
- Technical readers
Also called: AI coding, code assistant.
Back to the milestone you came from
In five seconds
What it is
A system produces computer code from prompts, examples or surrounding files. People should test and revise the result before using it.
In plain words
You describe a coding task, and the system drafts code that might help. Treat it like a fast first draft: useful sometimes, trustworthy only after checking and testing.
An everyday example
You ask someone to make a small calculator that splits a group bill, rounds each share and keeps the tip separate. They quickly write the steps based on familiar examples. It works for an even split, but rounds too early when the amount divides unevenly, leaving the total wrong. You try several easy and awkward examples, find the error and revise the steps before relying on it. Generated code works similarly: a convincing first version still needs checking against cases where the answer is already known.
A human clerk may truly understand the local context, ask clarifying questions on their own and be accountable for each formula. A code generation system does not have that kind of grounded judgement. It predicts likely code patterns from training and context, so it can produce convincing output without reliably recognising whether it is correct, secure or suitable for your environment.
Remember thisGenerated code is a draft, not a finished control. Review the logic, test expected and awkward cases, and obtain the required approval before use.
Understand it
Understand it
Why it matters
Even if you never write software, code generation can affect the systems your organisation relies on. It can reduce time for routine coding, prototyping and translation between programming languages. But it can also introduce hidden errors, insecure practices, copyright or licence concerns, and hard-to-see maintenance problems. For managers and non-specialists, the key decision is not whether the draft appeared quickly. It is whether the code was reviewed, tested, documented and approved by the right people before real use. Understanding this helps you ask better questions about risk, responsibility, quality and procurement.
From request to reviewed code
Show that generated code comes from prompts and context, but only becomes useful after testing and human review.
01
1. Request
A person asks for a function, script, query or test in plain language, with examples or constraints.
Draw a box labelled 'Request' with icons for text instructions, example input/output and coding rules.
02
2. Context added
The tool may also use nearby files, comments, variable names or documentation to make the draft fit the project.
Draw a second box labelled 'Context' with stacked file icons. Add arrows from Request and Context into the next box.
03
3. Draft code produced
The system generates likely code text that matches the prompt and available context.
Draw a central box labelled 'Generated draft' containing short code lines. Use a solid arrow from inputs into this box.
04
4. Test and inspect
A person or automated checks run the code, read it, and look for bugs, unsafe methods and invented functions.
Draw a box labelled 'Review and test' with icons for a checklist and terminal output. Add a loop-back arrow from this box to 'Request' or 'Generated draft' labelled 'revise'.
05
5. Use or reject
Only code that passes review should move into real use. Failed drafts are edited or discarded.
Draw a final box labelled 'Approved use' and a side bin icon labelled 'Reject'. Show arrows from Review and test to both outcomes.
A left-to-right flow with five boxes. Read from the request on the left to the reviewed result on the right. The middle shows that surrounding code and examples shape the draft, and that testing can send the process back for revision.
Hover or tap each box to reveal one sentence about the risk at that stage, such as unclear prompt, missing context, buggy draft, failed tests or approval decision.
Describe this without the diagram
The diagram is a five-step flow. First, a person gives a request for code, such as a function or query, with instructions and examples. Second, project context such as nearby files or documentation may be added. Third, the system produces a draft of code. Fourth, a human reviewer and tests inspect the draft for correctness, security and invented elements. A loop returns from review to the draft stage if fixes are needed. Fifth, the code is either approved for use after checks or rejected. The main message is that generated code is an intermediate draft, not the final trustworthy result.
With reduced motion: A static left-to-right flowchart shows Request, Context, Generated draft, Review and test, and Approved use, with a visible loop-back arrow for revision and a separate reject path.
Code generation means using a system to produce software code, such as a small function, a database query, a web page layout or a test script. The input might be a plain-language prompt, existing code, comments, screenshots or a mix of these. The output is usually code text, not a finished program.
In simple terms, the system looks for patterns from many examples seen during training and predicts code that fits the request. Some tools suggest the next few words of code as you type. Others create a whole block of code, explain it, rewrite it in another programming language or generate tests.
What comes out can be useful, but it can also be wrong. The code may fail, use an unsafe method, invent a function that does not exist, misunderstand the task or include hidden security problems. That is why code generation is different from software that has already been tested and approved.
It is often confused with a copilot tool. A copilot is the product or interface that assists a person while they work. Code generation is the capability inside that tool: producing code suggestions or code files. It is also related to text generation, because code is usually generated as text tokens, but the goal and checks are different.
For non-specialists, the main point is this: code generation can speed up drafting, translation and routine coding work, but it does not remove the need for human review, testing, security checks and accountability.
How “A custom calculator from a description” maps onto the real thing
| In the story | In the AI system |
|---|---|
| The officer’s description of the task | The prompt or instructions given to the code system |
| The clerk’s draft formulas and labels | Generated code and related suggestions |
| Errors like missed phrases or double-counting | Bugs, incorrect logic or unsafe code in the output |
| The teammate checking a sample before reporting | Human review, testing and validation before deployment |
A worked example
An information management officer at a regional hub is preparing a monitoring report package for upload to the portal by close of business. They ask an approved code assistant to draft a Python script that checks the package manifest for missing titles, invalid filenames and duplicate entries.
Starting from: Prompt: "Write a Python script that reads a CSV manifest, reports blank title fields, flags filenames containing spaces, and lists duplicate document identifiers. Do not alter the file. Include clear error messages and tests using dummy records."
- The system generates code token by token, drawing on the prompt and common Python patterns for reading CSV files, checking text and finding duplicates.
- The officer reviews the draft and notices that blank fields containing only spaces are not detected.
- They revise the check, then run the script in a test folder containing valid, incomplete and duplicate dummy records.
- One test reveals that identifiers with different capitalisation are treated as distinct. The comparison logic is corrected and tested again.
- After code review and approval, the officer runs the script on the export and resolves the reported errors before upload.
Result: The generated script provides a quick first draft, but review and tests uncover two plausible mistakes before they affect the portal package.
In a United Nations workplace
The knowledge management officer in a small field presence, where connectivity is intermittent, has to place a note for the file from a bilateral meeting on the document register before close of business. An approved coding assistant is asked to draft a local script that checks attachment names and required metadata against the register's rules, using dummy filenames rather than the note or its contents.
The assistant predicts source-code tokens from the prompt and examples, producing a useful first draft of a routine checker. The officer still needs to inspect the logic, test valid and invalid filenames, and confirm that the script behaves properly when the connection drops.
Before you try thisDo not paste the note, names of interlocutors or details of the bilateral into a tool that is not approved for that information and purpose. Use synthetic test data, run the script only in an approved environment, and complete code review and security testing before it touches the document register.
Where you may hear it
- During a vendor demonstration to an ICT governance board
- At a sprint review before a portal release
- In a procurement meeting assessing a coding assistant
- During an internal audit discussion on software controls
Avoid confusion
Avoid confusion
Often confused with
Copilot
A tool that helps a person complete digital tasks by drafting, searching, and sometimes taking limited actions under human direction and review.
Text generation
A system produces new written words from a prompt, patterning its output on examples seen during training.
Common misconceptions
Common misconception: If the code runs, it must be correct.
Correction: Many bugs do not stop a program from running. A script can produce the wrong totals, expose data, fail on unusual inputs or become insecure while still appearing to work on a quick test. Correctness needs requirements, test cases and review, not just successful execution.
Common misconception: Generated code removes the need for programmers.
Correction: It can reduce effort for repetitive drafting, but skilled people are still needed to define the task, judge whether the approach fits the system, test edge cases, check security, maintain the code and take responsibility for the result. In some settings, it shifts work rather than removing it.
Common misconception: A code assistant only uses my prompt, so it cannot introduce outside problems.
Correction: The output reflects patterns learned during training and the context supplied at the time. That means it can reproduce outdated methods, insecure examples, style mismatches or invented functions. The source of the pattern may not be visible from the final draft.
Quick check
Which statement best describes code generation?
Code generation creates likely code drafts from instructions and context. Those drafts may be helpful, but they are not automatically correct, secure or approved. A copilot is a tool or interface that may include code generation, not the same concept.
Go deeper
Go deeper
The simple version
You describe a coding task, and the system drafts code that might help. Treat it like a fast first draft: useful sometimes, trustworthy only after checking and testing.
The technical version
Most current code generation tools produce code as sequences of tokens, often using large language models trained on mixtures of code and natural language. Depending on the product, the model conditions on the prompt, surrounding source files, comments, APIs, error messages or retrieved documentation, then predicts likely next tokens until a completion is formed. Some systems support fill-in-the-middle editing, test generation, code explanation, translation between languages or agent-like workflows that call tools such as compilers and linters. Despite this, the mechanism is still probabilistic pattern generation rather than guaranteed program synthesis from a formal specification. Because of that, outputs may compile yet still contain logic errors, security flaws, non-existent library calls, licence concerns or poor performance. Evaluation usually requires static analysis, unit tests, integration tests, code review and environment-specific validation.
Reviewed external resources
Primary sourceRecommendation on the Ethics of Artificial Intelligence (opens in a new tab)UNESCO
This UNESCO recommendation gives an official ethics framework for using AI responsibly, and it suits readers interested in governance, risk, rights and oversight.
Intermediatelink checked 2026-07-31
Primary sourceContent Credentials (opens in a new tab)Content Authenticity Initiative
This Content Authenticity Initiative resource explains content credentials and provenance approaches, and it suits readers exploring how generated outputs may be labelled or traced.
Starterlink checked 2026-07-31
EncyclopaediaWikipedia search: Code generation (opens in a new tab)Wikipedia
This Wikipedia search results page helps readers find broad background on code generation and related topics, and it suits readers who want a starting point rather than one definitive article.
search results, not one pagelink checked 2026-07-31
VideoVideo explanations: Code generation (opens in a new tab)YouTube search
This YouTube search results page offers a range of video explanations and demonstrations, and it suits readers who learn best by watching examples while comparing sources critically.
search results, not one pagelink checked 2026-07-31
DiscussionCommunity discussion: Code generation (opens in a new tab)Reddit search
This Reddit search results page shows community questions, experiences and debates about code generation, and it suits readers who want informal practitioner discussion with the caution that posts vary in quality.
search results, not one pagelink checked 2026-07-31
Where this came from
Drafted with a language model through an offline pipeline, checked against this site's schema, and every external link above fetched to see whether it answers. Treat it as a starting point and check anything that matters against the primary sources. How this site is built and what that means.
The one thing to remember
Generated code is a draft, not a finished control. Review the logic, test expected and awkward cases, and obtain the required approval before use.