Evaluating LLM Front-End Generation and Prompt Iteration: A Practical Guide

    This article explains why a rendering page is not the same as a usable one, and how to turn front-end generation quality into a measurable process. It covers building high-discrimination test cases, a reusable four-part prompt structure, root-cause analysis for failed iterations, and engineering practices such as single-variable iteration, automated acceptance checks, versioned storage, and monitoring. Readers will find concrete prompt and code examples for building testable, reproducible, and iterable front-end outputs.

    1. Background: Why “Can Generate a Web Page” Is Not “Can Generate a Usable Web Page”

    Over the past two years, LLMs have steadily improved at code generation, especially the scenario of “generating a runnable front-end page from a single sentence.” This has become a common way for developers to evaluate a model’s engineering capabilities in daily practice. However, a frequent mistake is treating “the page renders” as the definition of success. What actually determines usability is whether the interaction logic is consistent, whether state management is correct, whether visual details match the description, and how the output performs under high-frequency calls.

    The core value of the original test cases is not to compare which specific model is stronger, but that they expose a common problem: the same prompt can produce noticeably different output quality across different entry points, different loads, and different iteration rounds. We therefore need to turn “feel” into a “measurable evaluation.”

    2. Building a High-Discrimination Test Set

    Low-discrimination tasks (for example, “build a login page”) can hardly separate models. High-discrimination tasks usually have three characteristics: many interaction states, a lot of implicit domain knowledge, and many boundary conditions.

    Take “replicate the window dragging and 3D switching effects of a classic desktop system” as an example. It simultaneously tests:

    • Coordinate transformation and boundary constraints for dragging;
    • Window layering (z-index) and focus management;
    • Visual details such as translucent materials, blur, and shadows;
    • Perspective, animation timing, and performance trade-offs for 3D switching.

    Another example, “convert a turn-based strategy game into a real-time strategy game,” operates at a higher level of abstraction:

    1. Domain concept understanding: real-time means both sides have equal time and no manual turn ending is required; the game loop is driven by time rather than clicks.
    2. Requirement extrapolation: adding an “automated research assistant” is a feature that does not exist in the original system, so the model must understand the intent of the “assistant system” and design automatic decisions under resource constraints.
    3. Algorithmic capability: automatic enemy and city seeking for units involves path planning and target addressing.
    4. Detail compliance: the speed slider (1x to 10x), hexagonal grid, keyboard-based view panning, and object icons are all required; missing any one counts as a failure.

    It is recommended to organize test cases as a table of “requirement list + acceptance criteria,” checking off items one by one to avoid subjective judgment.

    3. A Reusable Prompt Structure

    A structured prompt can significantly reduce randomness. The recommended format is a four-part structure: Role, Goal, Constraints, and Acceptance.

    1. Role: You are a senior front-end engineer. Output a single runnable HTML file.
    2. Goal: Implement a prototype of a real-time strategy mini-game.
    3. Feature list:
    4. 1. A time-driven main game loop where both sides' resources grow over time;
    5. 2. A checkable "auto research" option that unlocks technologies automatically when resources are sufficient;
    6. 3. All units can automatically seek enemies and cities;
    7. 4. Speed slider from 1x to 10x; hexagonal grid; arrow keys to pan the view; icons for cities and units.
    8. Technical constraints:
    9. - Native implementation with no external resources;
    10. - Use requestAnimationFrame to drive the loop, with the time step decoupled from the speed multiplier;
    11. - Separate the rendering layer from the logic layer; use axial coordinates for the grid.
    12. Acceptance: Map each item to the feature list, self-check before output, and explain where it is implemented.

    Here, “decoupling the time step from the speed multiplier” is a key engineering constraint that prevents physics and logic instability at high speeds:

    1. let last = performance.now();
    2. let accumulator = 0;
    3. const STEP = 1000 / 60; // Fixed logic step
    4. function loop(now) {
    5. accumulator += (now - last) * speedMultiplier;
    6. last = now;
    7. while (accumulator >= STEP) {
    8. update(STEP); // Logic update
    9. accumulator -= STEP;
    10. }
    11. render(); // Render
    12. requestAnimationFrame(loop);
    13. }

    4. Common Root Causes of Failed Iterations and How to Locate Them

    When multiple rounds of iteration make things worse, it is usually not that the model “regressed,” but that the prompt introduced conflicts or context pollution. A four-layer approach is recommended:

    1. Requirement layer: whether the new description conflicts with existing constraints (for example, requiring both turn-based and real-time).
    2. Structure layer: whether the output file was truncated, leaving styles or scripts incomplete.
    3. Visual layer: whether descriptions of materials, rounded corners, blur, and shadows are drowned out by generic wording.
    4. Performance layer: whether high-frequency calls or rendering overhead caused degraded output.

    In practice, keep the prompt and output snapshot for each round and make single-variable changes: change only one constraint at a time and keep the acceptance checklist fixed.

    5. Engineering Recommendations for Production

    • Separate rendering from logic to make it easier to swap rendering backends (DOM, Canvas, or a containerized rendering service).
    • Store versioned complex outputs in object storage, and use logging services and monitoring alerts to observe generation latency and failure rates.
    • Build automated acceptance: use a headless browser to run interaction scripts and compare screenshots of key visual features.
    • Pay attention to accessibility: keyboard reachability, visible focus, and sufficient contrast; avoid pursuing visual showmanship only.
    • Keep costs under control: for long-output scenarios, set up segmented generation and incremental continuation strategies.

    6. Conclusion

    Evaluating an LLM’s front-end generation capability should shift from “looks right” to “acceptable, reproducible, and iterable.” High-discrimination test cases, structured prompts, single-variable iteration, and automated acceptance form a stable methodology; combined with versioned storage, logging, and monitoring on the engineering side, a one-off impressive demo can be turned into sustainable, deliverable productivity.