LLM-Assisted Coding in Practice: Reproducing a Popular Project and Lessons Learned
This article documents a reproduction experiment in which an LLM was asked to build a small tool from a natural language requirement. It explains how to write a clear specification, structure prompts, generate code module by module, and validate the results through unit, integration, and requirement-level testing. It also covers common failure patterns in generated code and how to review them.
1. Background and Goals
Readers in our community have asked to see how large language models (LLMs) perform on real programming tasks. Rather than relying on promotional material or leaderboards, a more useful approach is to give the same clearly defined requirement, record the full process from the initial request to a working result, and check the output quality item by item. This article follows that approach in a reproduction experiment.
The experiment had three goals:
- Verify whether an LLM can generate a well-structured small project from a natural language requirement;
- Identify the failure patterns that recur during generation;
- Summarize a reusable set of prompting and acceptance methods.
This article does not rank any models or cite performance metrics. All conclusions apply only to the tasks and environment of this experiment.
2. Experiment Design
2.1 Task Selection
The task was a small tool with a clear functional scope and a publicly described requirement. It had three parts: input handling, core logic, and result output. If the task is too large, problems are hard to attribute. If it is too small, common defects do not surface.
2.2 Evaluation Dimensions
- Runnability: whether the project starts directly after dependencies are installed;
- Functional completeness: how many items in the requirement checklist were implemented;
- Correctness: whether boundary inputs produce reasonable results;
- Maintainability: whether module structure, naming, and comments are clear;
- Iteration cost: how many interaction rounds were needed to reach a usable state.
2.3 Recording Method
Each round recorded three items: the original prompt, the scope of changes in the generated code, and the number of lines modified manually. These records make the review traceable and show which types of requirements are most prone to deviation.
3. Breaking Down Requirements: From Vague Idea to Executable Specification
When facing vague requirements, an LLM usually fills in missing details based on common practice. The filled-in details may not match the real intent, so the output tends to drift from expectations. The remedy is to write a specification before prompting. A specification should include at least four items:
- Input: data source, format, and size limits;
- Output: return structure, file format, and conventions for error messages;
- Constraints: runtime environment, dependency scope, and performance limits;
- Acceptance criteria: specific behaviors that can be expressed as test cases.
For example, “build a log analysis tool” is too general. Rewritten as “read a line-based text log, count error entries per minute, and write the output to a CSV file; skip empty lines; lines with an invalid timestamp count as parse failures and are listed separately in the summary,” the model no longer has to guess.
4. Prompt Structure Design
A fixed template is recommended for organizing prompts:
[Role] You are a Python developer familiar with the standard library.[Goal] Implement a command-line script that reads a log file and counts error entries.[Input] A line-based text file where each line has the format "date time level message".[Output] Print a summary to standard output, and also write a CSV file.[Constraints] Use only the standard library; no function exceeds 40 lines; all functions have type annotations.[Acceptance] Provide at least 5 test cases covering empty input, invalid formats, and boundary values.
The purpose of the template is to state implicit assumptions explicitly. Missing parts show up in the output in some form, such as unnecessary third-party dependencies, missing exception handling, or tests that cover only the normal path.
5. Iterative Generation by Module
Generating an entire project in one pass usually has a low success rate. A safer approach is to proceed module by module:
- Generate the data structures and parsing functions first, and run them on their own;
- Generate the core statistics logic and add unit tests at the same time;
- Finally, generate the command-line entry point and output module, then run an end-to-end check.
Only after each module passes verification should the next step begin. The following sketch of a parsing function shows the basic use of type annotations and error handling:
from datetime import datetimefrom typing import Optionaldef parse_line(line: str) -> Optional[tuple[datetime, str]]:"""Parse a line in the form '2026-01-01 12:00:00 ERROR message'.Returns None for an empty line or a malformed line."""parts = line.strip().split(" ", 3)if len(parts) < 3:return Nonetry:ts = datetime.strptime(f"{parts[0]} {parts[1]}", "%Y-%m-%d %H:%M:%S")except ValueError:return Nonereturn ts, parts[2]
The corresponding unit tests also use only the standard library:
import unittestclass TestParseLine(unittest.TestCase):def test_valid_line(self):result = parse_line("2026-01-01 12:00:00 ERROR disk full")self.assertIsNotNone(result)self.assertEqual(result[1], "ERROR")def test_empty_line(self):self.assertIsNone(parse_line(" "))def test_bad_timestamp(self):self.assertIsNone(parse_line("2026-13-01 12:00:00 ERROR x"))if __name__ == "__main__":unittest.main()
The tests cover three cases: normal input, empty lines, and invalid dates. These are the cases that generated code most often misses.
6. Testing and Acceptance
Acceptance has three levels.
Unit level. Each function needs at least one normal case and one exceptional case. After running the tests, all cases should pass. The absence of errors alone is not enough.
Integration level. Prepare a sample file that contains normal lines, empty lines, invalid timestamps, and overly long messages. Check whether the summary figures match a manual count. The manual count can be done with a simple script or by spot-checking by hand.
Requirement level. Check each acceptance criterion in the specification one by one. An item without a matching test is incomplete, even if the code appears to implement it.
7. Common Failure Patterns and Mitigations
Fabricated interfaces or parameters. The model sometimes calls functions or parameters that do not exist. A runtime error reveals this, but if a code path rarely runs, the problem can stay hidden for a long time. The remedy is to ask the model to list every external function it uses, then check each one against the official documentation.
Dependency bloat. The model tends to introduce third-party libraries for tasks the standard library can handle. Listing the allowed dependencies in the constraints reduces this problem.
Missing exception handling. Generated code often assumes that inputs are always valid. The remedy is to add invalid-input cases to the acceptance criteria, which forces the code to handle errors explicitly.
Silent errors. The most dangerous case is a program that runs but produces biased results, for example a wrong counting rule or inconsistent time zone handling. Only manual sample checks can catch these problems, so integration tests should not be skipped.
Security issues. Generated code may concatenate unescaped query strings, use unvalidated file paths, or hardcode secrets. Review should check these against basic security practices. Secrets belong in environment variables or a dedicated secrets management service, not in code or logs.
8. Efficiency and Cost
More iteration rounds increase the burden of manual review. The experience from this experiment is that spending time up front on a clear specification noticeably reduces rework later. The more specific the specification, the less room the model has to fill gaps, and the less needs correcting during review.
Fast generation does not mean fast delivery, however. If code lacks tests, or no one understands its logic, maintenance costs rise quickly.
9. Conclusion
LLMs suit generating clearly structured modules and boilerplate code, and they can also implement some functionality of moderate complexity. Stable results depend on writing requirements as verifiable specifications and judging quality with tests rather than subjective impressions.
Developers remain responsible for the result. Model output should be treated as a draft to review. Only after verification, manual checks, and security review should it enter production.
