Requirement Fidelity in LLM-Generated Code and Its Significance for Open Source
This article explains why the output of LLM-generated front-end code should be evaluated for requirement fidelity, not only for whether it runs. It presents a six-dimension scoring framework, examines how login, list, and form pages tend to fail, analyzes three causes of failure, and describes practical methods for improving results, including structured requirement templates, behavior-based acceptance tests, page-by-page generation, and manual review of critical logic.
1. Why Requirement Fidelity Needs Separate Evaluation
When a large language model generates a front-end page, the result is usually judged on two levels. The first level is whether it runs: whether the page renders, routing works, and dependencies are complete. The second level is whether it is correct: whether the page behavior matches the requirements document. Most experience reports address only the first level, but enterprise adoption usually stalls at the second. A requirements document typically describes page structure, field relationships, interaction rules, and validation logic. The model must map these descriptions accurately into code before the task is complete.
Therefore, evaluation should measure “runs” and “requirement fidelity” separately. The first is a basic threshold. The second determines the cost of rework.
2. Evaluation Framework: Six Measurable Dimensions
Six dimensions are recommended for scoring generated results. Each dimension is scored from 0 to 2, and run screenshots and source code should be kept as evidence.
- Delivery completeness: Whether the project can be started with one command, and whether it provides an accessible running address or a reproducible build artifact. Results that provide only code snippets receive a lower score.
- Page coverage: Whether all pages listed in the document exist, and whether routes and navigation are complete.
- Feature coverage: Whether each page’s functions, such as carousels, filtering, sorting, and pagination, are implemented item by item. This dimension is the easiest to overlook, yet it best reflects how deeply the model understands the requirements.
- Data structure fidelity: Whether field names, types, and dependencies between fields match the document. For example, a field that becomes editable only after a certain option is selected has a dependency. Missing it breaks the business logic of the entire form.
- Validation and interaction details: Whether required fields, formats, lengths, cross-field validation, and status feedback before and after submission are implemented correctly.
- Engineering and visual quality: Whether components are split sensibly, state management is clear, and styles are consistent. Pages do not need a distinctive design, but layout consistency and maintainability should meet a basic standard.
Record the time taken and the number of retries as well. The same requirement can take very different amounts of time under different resource conditions. Timing data is comparable only when the environment, prompts, and retry strategy are identical.
3. Three Page Types as Examples
Difficulty differs noticeably between page types in the same requirements document.
(1) Login pages: highly templated
Login pages involve common components such as forms, buttons, validation, and carousels. Training data contains many code samples of this kind, so generated results are usually fairly complete. Acceptance for these pages focuses on details, such as the carousel’s auto-switch interval, pausing and manual switching, and placeholder handling when an image fails to load. These details are easy to overlook and must be checked one by one.
(2) List pages: filtering logic is a common weak point
The difficulty of list pages lies in mapping the data model to user interactions. A working filter must meet three conditions: the control renders correctly, the control value is bound to the query parameters, and the list data is actually filtered by those parameters. A common failure is that the control renders, but its value never reaches the data layer. The page appears to have a filter, but the filter does nothing.
This problem suggests that the model has difficulty integrating information across sections. For example, filter rules may appear in section 2 of the page description, while field definitions appear in section 5. The model must connect both to build the complete implementation chain.
(3) Form pages: dependencies are the most easily lost
Problems in complex forms center on linkage between fields. For example, the value of field A determines the options available in field B, and field C becomes required under certain conditions. If the generated result implements each field but ignores the linkage, the form looks complete while the business process is wrong.
4. Why Comprehension Becomes the Bottleneck
From an engineering perspective, requirement fidelity failures usually come from three causes.
The first is implicit constraints. Requirements documents often omit rules that seem obvious, such as lists sorting by creation time in descending order by default, or pagination resetting to page one when filter conditions change. Human developers fill in these conventions, but models may miss them.
The second is reference resolution across long contexts. The more pages a document has, the more likely the same field is described ambiguously in different sections. The model must keep information consistent across many places.
The third is insufficient structure. Natural-language requirements leave a large space for ambiguity, and a single sentence may map to several implementations.
Most of these causes can be mitigated on the user’s side without waiting for model upgrades. The next section describes specific methods.
5. Engineering Practices for Better Generation Quality
(1) Use structured requirement templates
Split requirements into five layers: pages, components, fields, rules, and interactions. Assign each rule a unique ID so it can be checked item by item after generation. Example:
page: Order listfilters:- id: F-01label: Order statustype: selectoptions: [Pending payment, Paid, Cancelled]binding: query.statusbehavior: Refresh the list immediately after selection and reset the page number to 1list:default_sort: created_at desccolumns: [Order number, Amount, Status, Created at]
Structured descriptions reduce ambiguity and let acceptance proceed rule by rule.
(2) Write automated acceptance tests for key interactions
For list filtering, write acceptance cases that do not depend on the implementation and verify behavior directly. For example, after a status is selected, every record in the list should show that status. Such cases are more stable than manual page-by-page clicking and are easier to rerun for regression testing.
Example (pseudocode):
Given I open the order list pageWhen I select "Paid" in the "Order status" filterThen the Status column of every row in the list is "Paid"And the current page number is 1
(3) Generate in stages and accept page by page
First generate the page skeleton and routes, then implement features one page at a time, accepting each page immediately after it is complete. This confines errors to a single page. When a large amount of code is generated at once, the cost of locating problems rises quickly.
