Three-Tier Gradient Testing for LLM Code Generation: Mapping the Boundaries of Logic, Aesthetics, and Agentic Ability

    This article presents a three-tier gradient testing framework for evaluating large language models (LLMs) on front-end code generation. It explains why front-end pages are a demanding benchmark that simultaneously stresses logical correctness, visual aesthetics, and interaction completeness, and why a single screenshot or demo is not enough to judge a model. The framework layers tasks by difficulty—logic and correctness, aesthetics and information hierarchy, and agentic self-correction—and defines four scoring dimensions: runnability, structural quality, visual reasonableness, and interaction completeness. It also documents common failure modes, provides reusable prompt templates, and offers engineering recommendations such as building regression test sets and keeping a human in the loop. Readers get a repeatable, attributable, and regression-friendly method for model selection and capability assessment.

    1. Why Front-End Code Generation Is a Tough Benchmark for LLMs

    In almost every discussion about AI-assisted coding evaluation, front-end page generation stands out as a special case. It pressures three categories of model capability at once:

    • Logical correctness: the DOM structure, event bindings, and state transitions must be self-consistent.
    • Visual aesthetics: spacing, type scale, color, and hierarchy must follow design common sense.
    • Interaction completeness: loading states, empty states, error states, and boundary validation cannot be missing.

    Many models perform well on algorithm problems or backend API generation, yet “crash” the moment they touch a page. The reason is not mysterious: the correctness of backend code can be strictly verified by test cases, whereas front-end correctness carries an extra layer of subjective judgment—“does it look right?” Conversely, some models only learn to pile up a good-looking static skeleton. Once you ask them to add or remove features, handle concurrent clicks, or validate a form, the logic collapses immediately.

    So evaluating a model’s front-end ability from a single screenshot or a one-off demo is not enough. I recommend a gradient testing approach: design tasks in tiers by difficulty, widen the evaluation dimensions layer by layer, and observe at which tier the model’s capability starts to degrade. This method has been repeatedly validated on several LLMs available through model service platforms such as Baidu AI Cloud, and readers can treat it as a standardized script for team model selection.

    2. Methodology: Tiered Design and Scoring Dimensions

    2.1 Three-Tier Task Structure

    The core of gradient testing is “each tier adds only one main variable,” which avoids throwing a complex requirement all at once and leaving the failure cause unattributable.

    • Tier 1 | Logic and correctness: given a clear data structure and interaction rules, generate a cleanly structured, runnable single-page implementation. The focus is on semantic markup, event handling, state management, and boundary handling.
    • Tier 2 | Aesthetics and information hierarchy: the same functional requirement, plus added design constraints (design tokens, type-scale ratio, whitespace rules, accessible contrast). The focus is whether the model translates “aesthetics” into executable style rules rather than picking colors at random.
    • Tier 3 | Agentic and self-correction: package the task as a complete multi-step workflow—first retrieve information, then write code, then self-review, then iterate. The focus is whether the model can close the loop rather than dumping code in one shot.

    2.2 Scoring Dimensions and Criteria

    I suggest scoring with four rulers, each from 1 to 5, to avoid subjective conclusions like “feels pretty good”:

    Dimension What to observe Common deductions
    Runnability Can it run directly from a single generation Missing key dependencies, undefined variables, unbound events
    Structural quality Component breakdown, naming, style organization Thousand-line single file, inline-style sprawl, meaningless names
    Visual reasonableness Type scale, spacing, colors, contrast Default purple-blue gradient, low-contrast text, overly heavy card shadows
    Interaction completeness Empty/loading/error states, validation Only the happy path, no failure branches

    A practical trick: change only one variable per retest. For example, in Tier 2 add just the single constraint “spacing follows multiples of 4,” and observe whether the model actually applies it rather than agreeing verbally while the code stays the same. This ablation-style comparison cleanly separates “model capability problems” from “prompt problems.”

    3. Tier 1: Logical Reasoning and Code Correctness

    The failure modes at this tier are highly concentrated and worth summarizing separately:

    1. State synchronization omissions. For example, the input box is not cleared after adding to a list, or an async response directly overwrites a form the user has already edited. These problems are completely invisible in a static screenshot; you have to click through to catch them.
    2. Missing boundary handling. Rendering an empty list throws an error, plural wording is wrong when the count is 1, or overly long text breaks out of its container.
    3. Duplicate event bindings. A listener is attached inside a render function but never cleaned up, so the trigger count doubles after several switches.
    4. Async race conditions. When filter conditions are switched quickly, an earlier request returns later and overwrites the results.

    The most effective way to reduce these errors is not to shout “don’t write bugs,” but to write the acceptance criteria into the prompt. For example:

    1. Task: Implement a task list page with search and filtering (single file, vanilla HTML/CSS/JS).
    2. Data: Use the JSON structure below; do not add fields.
    3. Must satisfy:
    4. 1. When the array is empty, show an empty state and do not throw;
    5. 2. Debounce search input at 200ms; cancel the previous unfinished request when filters change;
    6. 3. Render all list items with event delegation; do not use per-item addEventListener;
    7. 4. Keyboard accessible: Tab can focus all interactive elements; Enter triggers the primary action.
    8. Output: First give the file structure, then the complete code, and finally list 3 potential issues you find yourself.

    Note the last item—require the model to disclose risks itself. It turns “reflection” from an implicit behavior into an explicit output. This makes it easier for you to review and significantly lowers the chance the model slips through.

    4. Tier 2: Visual Aesthetics and Information Hierarchy

    Aesthetics is hard to teach because it must be broken down into computable rules. Saying “make it look premium” directly is nearly useless; switching to design tokens makes an immediate difference:

    1. :root {
    2. /* Spacing: multiples of 4 to build a consistent rhythm */
    3. --space-1: 4px; --space-2: 8px; --space-3: 16px;
    4. --space-4: 24px; --space-5: 32px;
    5. /* Type scale: ratio ~1.25 to avoid level jumps */
    6. --fs-body: 16px; --fs-h3: 20px; --fs-h2: 25px; --fs-h1: 31px;
    7. /* Neutrals + a single accent color, semantic naming */
    8. --color-bg: #0f1115;
    9. --color-surface: #171a21;
    10. --color-text: #e6e8ee;
    11. --color-muted: #9aa3b2;
    12. --color-accent: #4f8cff;
    13. --radius-md: 10px;
    14. --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    15. }

    Around these tokens, you can set three hard constraints. In practice they improve generated output far more than any adjective:

    • Color restraint: no more than one accent color across the site, and the accent is used only for the primary action point and the current state.
    • Adequate contrast: body text against its background should not fall below 4.5:1; de-emphasize secondary information by lowering opacity rather than pairing random grays and blues.
    • Whitespace first: container padding should not be smaller than the mid-range spacing step; better to include less content than to compress the whitespace.

    It is also critical to require the model to “do layout before color.” You can have it output the structure and grid first (the height and proportions of Header / Main / Sidebar / Footer), and only after confirming it is correct, add the visual layer. This way, when a result is wrong, you can immediately tell whether the layout was misunderstood or the color scheme went off track.

    5. Tier 3: Agentic Ability and the Self-Correction Loop

    The essence of agentic coding is turning “one-shot text generation” into “a multi-step task with feedback.” A usable loop usually has four steps: understand the requirement → retrieve and verify → generate the implementation → run, self-check, and iterate. In engineering practice, this requires two things working together:

    First, give the model tools and context. Allow it to look up documentation, read existing code conventions, write output back to the file system, and execute it. The quality of the context you feed directly determines the output quality; providing component specs, design tokens, and code style notes all at once is often more effective than repeatedly asking follow-up questions.

    Second, feed error information back. When a build or run fails, do not just paste “it errored.” Instead, provide the full error stack, the relevant code snippet, and the expected behavior:

    1. Current state: After clicking submit, the list does not update.
    2. Error: Uncaught TypeError: Cannot read properties of undefined (reading 'map')
    3. Location: line 42 in render(list); list is undefined
    4. Expected: After a successful submit, append the new item to the list and clear the input.
    5. Requirement: First explain your root-cause hypothesis, then give a minimal fix patch; do not rewrite the entire file.

    The “minimal fix patch” constraint matters a lot. When correcting errors, models have a typical tendency to rewrite from scratch, which introduces new regressions. Requiring them to change only the necessary lines significantly improves stability across multiple rounds of iteration.

    In real tuning, price and context length are also practical variables. Many of the models available through these platforms are competitive on invocation cost, and ultra-long context capability keeps improving, which makes feeding an entire requirements document plus snippets of the existing codebase in one shot a viable approach. For teams with high call volume, routing, rate limiting, and usage observability through a unified model service gateway is safer than binding to a single model.

    6. A Reusable Advanced Prompt Structure

    Consolidating the experience above into a template, a four-part structure covers the vast majority of front-end generation tasks:

    1. [Role] You are a senior front-end engineer; deliver production-grade code that runs as-is.
    2. [Context] Stack: ___; design tokens: see the CSS variables below;
    3. code conventions: ___; existing files: ___.
    4. [Task] Implement the ___ page with ___ feature points; data structure is ___.
    5. [Constraints] 1. Semantic tags + accessibility attributes;
    6. 2. Spacing uses --space-* steps; colors only from tokens;
    7. 3. Event delegation, no leak-prone listeners;
    8. 4. Cover empty / loading / error states;
    9. 5. Do not introduce dependencies not present in the context.
    10. [Deliverables] 1) File structure; 2) Complete code; 3) Self-test checklist and known risks;
    11. 4) If further optimization is desired, give 3 suggestions ranked by benefit.

    Three easily overlooked details: explicit prohibitions (to prevent inventing dependencies out of nowhere), requiring structured output (easy for machines to parse and archive), and requiring benefit-ranked suggestions (which exposes the model’s aesthetic judgment for your review).

    7. Limitations and Engineering Recommendations

    It must be stated clearly that gradient testing conclusions change as model versions iterate, and any claim that “a certain model is comprehensively ahead” is not rigorous. Shortcomings that commonly appear in practice include declining code consistency after very long generations, implicit dependencies in complex state machines, API recall bias for niche framework ecosystems, and “aesthetic drift” in visual details after multiple iterations.

    For engineering adoption, I recommend three things:

    1. Build a regression test set. Fix the three-tier gradient tasks along with their scoring criteria into a repository, and run them on every model upgrade—letting data replace gut feeling.
    2. Keep a human in the loop at critical gates. Generated code must pass type checking, static scanning, and human review, especially for logic involving permissions, payments, and data masking; such logic should not be finalized directly by the model.
    3. Unify access and manage cost. Access models uniformly through services such as Baidu AI Cloud, combined with logging, monitoring and alerting, and quota management, to turn call volume, failure rate, and average repair rounds into observable metrics.

    8. Conclusion

    Front-end code generation is moving from “it runs” to “it’s usable,” and the standard for measuring it is shifting from the impressiveness of a single demo to the stability and maintainability after multiple iterations. The value of three-tier gradient testing is not to rank a particular model, but to provide a repeatable, attributable, and regression-friendly evaluation framework: break aesthetics into rules, break interactions into states, and break reflection into explicit output. Only when the evaluation method itself is rigorous enough will progress in model capability be accurately seen.