Evaluating LLM Requirement Understanding for Front-End Code Generation

    LLM-generated front-end pages can often render successfully while still missing critical requirements. This article presents a practical evaluation method for requirement understanding in front-end code generation: writing verifiable requirements documents, scoring six dimensions, using executable tests for filtering and form validation logic, cataloging common failure modes, and adopting engineering practices that improve generation quality and team review.

    1. Why Requirement Understanding Needs Separate Evaluation

    Large language models are now part of many teams’ daily coding workflows. A model can quickly produce a page skeleton, but whether the page can be delivered depends on whether it accurately understands the requirements. A page that renders does not necessarily implement the filtering conditions described in the document; a form that submits does not necessarily follow the field linkage rules and validation rules.

    Therefore, when evaluating a model, “it runs” and “it gets it right” should be assessed separately. Running is the minimum threshold. Getting it right requires the model to reproduce every rule in the requirements document in code. The former can be judged with screenshots and page access; the latter requires checking each item against the requirements document.

    This type of evaluation also has practical value: it helps teams define the boundaries of model usage. Only systematic testing can reveal which page types the model handles reliably and which page types tend to lose details.

    2. Preparation: Write a Verifiable Requirements Document

    The quality of the evaluation depends on the quality of the requirements document. If the document itself is vague, failures may come from requirement expression rather than model capability. It is recommended to split the requirements document into the following parts.

    1. Page list: list the route, purpose, and entry point of each page.
    2. Function points: for each function point, specify the trigger condition, expected result, and exception cases.
    3. Field table: describe field types, whether required, validation rules, and linkage relationships.
    4. State descriptions: cover loading, empty data, request failure, no permission, and other states.

    Below is an example field table:

    Field Type Required Validation Rules Linkage Relationships
    Phone number String Yes 11 digits, starting with 1 After selecting “Overseas region”, validation no longer applies
    Verification code String Yes 6 digits, can be resent within 60 seconds Disable the Send button when phone number validation fails
    Department Dropdown Yes Must be in the department list Department list reloads after company switch
    Notes Multiline text No Maximum 200 characters None

    The value of the field table is that each row can become a test case. Rules that are not written into the table cannot be judged when the model omits them, and the evaluation loses its basis.

    3. Six Evaluation Dimensions

    3.1 Page Completeness

    Completeness refers to whether the page structure is complete. Check items include: title, navigation, main content, action buttons, and empty-state prompts. This dimension is usually where models perform best, because page skeletons are common in training data.

    High completeness does not mean the page is deliverable. A page with a complete skeleton may still lack business modules explicitly mentioned in the requirements.

    3.2 Functional Coverage

    Functional coverage checks whether every function point in the requirements has a corresponding implementation. Filtering, sorting, and pagination on list pages are the most easily missed parts. Models often implement prominent features while ignoring conditions buried in the requirements document, such as “the default filter value is All” or “the search box needs debounce”.

    During evaluation, check function points one by one, assign each one of three conclusions—“implemented”, “partially implemented”, or “not implemented”—and record the reason.

    3.3 Field and Validation Reproduction

    The difficulty of form pages lies in the relationships between fields. Single-field format validation is usually handled correctly; the hard part is linkage rules. For example, selecting a certain option hides another field, or the selectable range of a field depends on the value of the previous field.

    This dimension requires testing field by field and rule by rule, and trying combined operations. Checking only the successful submission path is far from enough; you also need to test whether error messages on failed submission match the rules.

    3.4 Interaction Details

    Interaction details include input debounce, button disable timing, countdowns, loading states, prompt copy, and similar items. Individually these look small, but together they determine whether users find the page “smooth”.

    Interaction details are also the part most likely to be unclear in a requirements document. Before evaluation, write interaction rules as verifiable sentences, for example, “after clicking Submit, the button enters a disabled state until the request returns”, rather than “the submission experience should be good”.

    3.5 Visual and Engineering Standards

    The visual dimension focuses on layout consistency, spacing, type hierarchy, and responsive behavior. If the team already has a design system or a mature component library, it should be used as the baseline for judging generated results. If not, you can check only basic consistency: whether styles for the same type of element are unified, and whether the page misaligns at different widths.

    Engineering standards include directory structure, naming, state management, and code comments. These determine whether the generated code can be maintained by the team later.

    3.6 Usability and Time Cost

    Time cost includes the time the model takes to generate a complete project and whether the generated result can run directly. During evaluation, record two numbers: time to first runnable version, and the number of iterations needed to meet the requirements.

    Time cost is affected by model service load, network conditions, and task size. Teams should compare within the same time period and at the same task scale to avoid mistaking occasional queuing for a model capability problem.

    4. Scoring Method and Test Cases

    4.1 Scoring Table

    It is recommended to set weights for each dimension and score each function point separately. Below is a reference scoring table:

    Dimension Weight Scoring Standard
    Page completeness 10% Full score when page structure is complete; deduct points for each missing block
    Functional coverage 30% Implementation rate of function points; partial implementation counts as half score
    Field and validation reproduction 30% Reproduction rate of validation rules and linkage rules
    Interaction details 15% Reproduction rate of interaction rules
    Visual and engineering standards 10% Consistency and maintainability
    Usability and time cost 5% Full score when first run succeeds and no blocking errors occur

    Weights can be adjusted by business context. For example, financial forms can increase the weight of fields and validation, while internal admin backends can reduce the visual weight.

    4.2 Verify Logic with Executable Tests

    For logic such as list filtering, the most reliable approach is to extract it into a pure function and verify it with test cases. The example below shows a combined filtering logic and the corresponding checking method:

    1. // Product list filtering: keyword, status, and minimum price apply together
    2. function filterProducts(list, { keyword = '', status = 'all', minPrice = null }) {
    3. return list.filter((item) => {
    4. const hitKeyword = !keyword || item.name.includes(keyword);
    5. const hitStatus = status === 'all' || item.status === status;
    6. const hitPrice = minPrice === null || item.price >= minPrice;
    7. return hitKeyword && hitStatus && hitPrice;
    8. });
    9. }
    10. // Test data
    11. const data = [
    12. { name: 'Wireless earbuds', status: 'online', price: 299 },
    13. { name: 'Wired earbuds', status: 'offline', price: 99 },
    14. { name: 'Bluetooth speaker', status: 'online', price: 199 },
    15. ];
    16. // Case 1: Single-condition filtering
    17. console.assert(filterProducts(data, { keyword: 'earbuds' }).length === 2, 'Keyword filtering failed');
    18. // Case 2: Combined conditions
    19. console.assert(
    20. filterProducts(data, { status: 'online', minPrice: 250 }).length === 1,
    21. 'Combined filtering failed'
    22. );
    23. // Case 3: Default conditions return all items
    24. console.assert(filterProducts(data, {}).length === 3, 'Default conditions should return all data');

    When evaluating a model, you can ask it to generate the filtering logic and then run it with the same test data. If the generated code passes the cases, the logic-level requirements have been reproduced. If not, record the failed condition combinations as evidence of capability gaps.

    4.3 How to Evaluate Forms

    Form evaluation can use a “rule checklist plus negative cases” approach. For each validation rule, design one valid value and at least one invalid value, and confirm that the page’s prompt matches the rule. For linkage rules, switch the preceding field and observe the state changes of the following field.

    It is recommended to record results in a table, with each row containing the rule ID, test input, expected behavior, and actual behavior. Such records can be used directly for retesting.

    5. Common Failure Modes

    In extensive practice, requirement reproduction failures usually cluster into the following categories.

    1. Implicit requirements are ignored: rules not directly written in the document but necessary for the business, such as duplicate-submission protection and permission-based hiding.
    2. Linkage relationships are lost: dependencies between fields appear only in one paragraph of the document, and the model implements only one of the fields.
    3. Exception states are missing: loading, empty data, and request failure displays are often omitted, making the page usable only with normal data.
    4. Validation is only one layer deep: the front end performs format validation but does not handle business errors returned by the backend.
    5. Locally correct but globally inconsistent: a single component is implemented correctly but conflicts with the state management approach of other components on the same page.

    For these problems, the evaluation report should list them separately rather than mix them into the total score. Teams can use this to decide which requirements must be supplemented manually and which can be generated by the model.

    6. Engineering Practices to Improve Generation Quality

    Another purpose of evaluation is to find ways to improve generation quality. The following practices are relatively effective in practice.

    1. Split tasks by page. Generating an entire system at once creates too long a context and makes details easy to lose. Generating page by page and attaching the relevant requirements fragment to each request can significantly reduce omissions.
    2. Ask the model to output a function point list before generating code. Let the model restate the requirements so the team can catch misunderstandings before coding.
    3. Require the model to attach the corresponding code location to each validation rule. This makes manual review faster.
    4. Extract key logic into pure functions with tests. Even if the model-generated code has an imperfect structure, tests can still determine correctness.
    5. Fix the evaluation set. When switching models or upgrading versions, use the same requirements document and the same test set so results are comparable.

    7. Recommendations for Team Adoption

    For most teams, models are suitable as draft generators, not final deliverers. Generated pages need functional testing, code review, and visual confirmation before going live.

    Adoption can proceed in three steps. First, select two or three low-risk pages for a pilot and collect evaluation data. Second, use the data to determine which page types are suitable for generation and which require human leadership. Third, turn the evaluation process into a checklist and include it in pre-merge review.

    At the same time, record the requirements version, prompt content, and model version used for each generation. Without these records, problems cannot be reproduced, and it is impossible to tell whether the requirements were unclear or the model capability was insufficient.

    8. Key Takeaways

    Requirement understanding is a core metric for evaluating LLMs in front-end scenarios. It reflects delivery quality better than whether a page can render. During evaluation, write clear requirements first, then verify item by item across dimensions such as functional coverage, field validation, and interaction details, and use executable tests to fix conclusions. When omissions occur, look first for improvement opportunities in requirement decomposition and task granularity.