Evaluating AI Front-End Code Generation from Requirement Documents

    This article presents a reusable methodology for evaluating how accurately AI models generate front-end code from requirement documents. It covers the prerequisites for reliable evaluation, five scoring dimensions, a reproducible evaluation workflow with weighted checklists, the role of open-source models in AI-assisted development, common failure patterns, and practical recommendations for engineering teams.

    1. Background: From “Can It Generate Code?” to “How Accurately Does It Follow Requirements?”

    As the code generation capabilities of large language models improve, more teams are experimenting with letting models build page prototypes directly from product requirement documents. The results vary widely. Given the same document, one model may produce the full page skeleton with the main interactions, while another misses filter conditions or ignores dependencies between fields. The evaluation focus has therefore shifted: it is no longer about whether a model can generate code, but about how well it understands and reproduces the requirements.

    This article abstracts the evaluation method into a general workflow that developers, QA engineers, and technology decision-makers can reuse. It does not draw conclusions about any specific product.

    2. Prerequisite: Document Quality Sets the Ceiling for Evaluation

    Before evaluating a model, verify that the input material itself is reliable. If a requirement document consists of only a screenshot and one sentence, no model can consistently reproduce the details. A document suitable for both generation and acceptance testing typically includes:

    • Page objective: what problem the page solves and who its users are.
    • Component inventory: carousels, tables, filter bars, forms, modals, and so on.
    • Data sources: field names and types returned by APIs, and whether fields can be null.
    • Interaction rules: clicks, inputs, linked behavior, default values, and error messages.
    • Edge cases: empty data, loading, timeouts, and insufficient permissions.

    Ambiguity in the document gets amplified by the model. For example, the statement “filter conditions include status and time” does not specify whether the two conditions combine with AND or OR, or whether time is a single value or a range. Before evaluation, rewrite the document into verifiable items. Otherwise, the results cannot distinguish between “the model is not capable enough” and “the document is unclear.”

    3. Five Evaluation Dimensions

    Evaluate along five dimensions and score each one separately. Avoid summarizing everything with a vague “good” or “bad.”

    3.1 Page Structure Completeness

    Check whether the layout blocks match the requirements. For a list page, does it include the filter area, action area, data table, and pagination? Missing structural blocks are the easiest defects to spot and best indicate whether the model actually read the entire document.

    3.2 Functional Requirement Fidelity

    This dimension distinguishes deep understanding from shallow pattern matching. Verify each functional point individually rather than just checking that the page opens. For a list page, at minimum check:

    1. Whether every filter item exists and uses the correct control type.
    2. Whether the list data updates when filter conditions are combined.
    3. Whether the reset action restores default values.
    4. Whether filter state is preserved after pagination or refresh, as required.

    Missing filter items are a typical functional omission. Even with a correct page structure, such omissions make the page undeliverable.

    3.3 Form Fields and Validation Logic

    The difficulty of form requirements lies in relationships between fields. Common dependencies include: showing additional fields after a certain option is selected; requiring a start date earlier than an end date across two date fields; making a field required only when another field is empty. Construct both positive and negative test cases to verify field visibility, validation messages, and submission results.

    3.4 Visual and Interaction Consistency

    Visual evaluation focuses on information hierarchy, spacing, alignment, and state feedback—not personal aesthetic preference. Use a consistent screenshot comparison standard to check whether button states, loading indicators, and error messages share consistent styling. If the team has a design system, use it as the reference.

    3.5 Engineering Usability

    Whether the generated code runs and can be maintained in a real project is the bottom line. Check whether dependencies are complete, the directory structure is reasonable, components are reusable, and whether data or addresses are hard-coded. A page that loads in a browser only proves it runs; it does not prove the code is production-ready.

    4. Building a Reproducible Evaluation Workflow

    Subjective impressions are easily influenced by a single trial. To make results comparable, follow these steps:

    1. Fix the requirement set: use the same set of requirement documents covering typical pages such as login, list, and form pages.
    2. Fix the prompting strategy: use the same input format, context length, and supplementary instructions for all candidates, with no extra tuning for any single one.
    3. Record process metrics: time to first usable output, number of failed retries, and number of manual interventions required.
    4. Accept against a checklist: break requirements into check items and mark each as “pass,” “partial,” or “not implemented.”
    5. Retest and archive: after fixing the document, retest and keep outputs and scores for future regression.

    The checklist below shows how list page requirements can be broken into individually scorable items:

    1. {
    2. "page": "product_list",
    3. "checks": [
    4. {"id": "L-01", "item": "Includes a status filter dropdown", "weight": 2},
    5. {"id": "L-02", "item": "Includes a time range picker", "weight": 2},
    6. {"id": "L-03", "item": "List refreshes in real time when filters are combined", "weight": 3},
    7. {"id": "L-04", "item": "Reset button restores default filter values", "weight": 1},
    8. {"id": "L-05", "item": "Filter conditions are preserved after pagination", "weight": 2}
    9. ]
    10. }

    Scoring is weighted. Each item receives 0, 0.5, or 1, multiplied by its weight; the sum is then divided by the total weight to produce the requirement fidelity rate for that page. This shows both the overall level and the specific omissions. The calculation logic:

    1. score = 0
    2. total = 0
    3. for item in checklist:
    4. total += item.weight
    5. score += item.weight * item.result # result is 0, 0.5, or 1
    6. completion_rate = score / total

    5. Why Open-Source Models Matter in AI-Assisted Development

    Whether a model is open source affects not just usage cost but also the control an engineering team has. From a development perspective, open-source models offer:

    • Auditability: teams can review license terms, weight provenance, and dependencies to satisfy compliance reviews.
    • Private deployment: requirement documents and business data stay in internal environments, reducing leakage risk.
    • Customizability: fine-tuning on domain data or designing dedicated prompt templates can improve fidelity for specific page types.
    • Predictable cost: the cost of a self-hosted inference service depends on hardware and call volume, making capacity planning easier.

    Open source does not automatically mean better results. Model capability still needs to be verified through the evaluation workflow above. Treat open source as one selection criterion, and combine it with requirement fidelity, response speed, and maintenance cost for a more reliable conclusion.

    6. Common Failure Modes and Mitigations

    Generation problems usually concentrate in a few categories, and targeted adjustments to the input often produce clear improvements.

    6.1 Insufficient Requirement Decomposition

    Feeding an entire long document to the model at once often causes the later sections to be ignored. A safer approach is to split by page, generating one page per request and attaching the API and field specifications relevant to that page.

    6.2 Missing Data Model

    Without explicit field types and value ranges, the model makes its own assumptions. Include a field table in the prompt listing name, type, required or not, and enumeration values.

    6.3 Undefined States and Edge Cases

    Loading, empty, and error states are frequently neglected. Specifying display rules for these states in the requirements reduces the “happy path only” problem.

    6.4 Staged Acceptance

    Have the model first output the page structure and component breakdown; after human confirmation, implement the interaction logic. Staged generation adds rounds, but it exposes misunderstandings earlier and reduces rework.

    7. Recommendations for Team Practice

    1. Structure requirement documents so they serve as the shared basis for both model input and human acceptance.
    2. Build an internal evaluation set and run regression tests regularly with the same requirements to observe the impact of model version changes.
    3. Define the human-machine division of labor: the model generates first drafts and repetitive code; engineers handle architecture decisions, security review, and final acceptance.
    4. Record the input, output, and scores of every evaluation to build the team’s own capability baseline.

    The value of AI-generated code lies in shortening the path from requirements to a verifiable prototype. To realize that value, teams need to shift their focus from generation speed to requirement fidelity—and quantify it with a reproducible method.