How to Evaluate Large Language Models on Complex Logic and Code Generation

    This article presents a reproducible benchmark for evaluating how well large language models follow multi-step geometric instructions and translate mathematical reasoning into executable HTML, JavaScript, Canvas, or SVG code. It examines experimental design, single-run observations, common failure modes, model-selection trade-offs, and safeguards for validating generated code.

    1. Why Design High-Difficulty Tests?

    Frontend development and data visualization are widely used to evaluate large language models. Asking a model to generate HTML or JavaScript containing mathematical logic can test its ability to understand requirements, reason through them, and implement the result. Earlier evaluations often focused on page layouts or simple animations, which provided limited differentiation between models.

    This article uses the construction of a regular heptagon with a two-mark ruler as the benchmark task. The model must derive and follow a sequence of geometric construction steps, then map each step to a Canvas or SVG coordinate system. Skipping even one step can distort the final figure, making the task useful for determining whether a model genuinely follows the instructions.

    2. Key Requirements for Reproducible Testing

    The original test described the construction steps in reasonable detail, but several important parameters were not recorded. This made the results difficult to reproduce. The following parameters should be fixed and documented in every replication:

    1. Square side length: A unit length of 1 is recommended to simplify subsequent algebraic calculations.
    2. Coordinate system: Use the midpoint of the square’s bottom edge as the origin, with the bottom edge placed on the x-axis. The perpendicular bisector can then be represented as x = 0.
    3. Distance between the two ruler marks: The numerical value must be specified, along with its ratio to the side length of the square.
    4. Rendering rules: A compass movement leaves a complete trajectory, but the code should render only the line segments and points required for the construction. The test must define which elements belong to the rendering layer and which are used only for computation.
    5. GIF export: The frame rate, resolution, and export library version should be recorded.

    These parameters determine whether the regular heptagon can be constructed correctly. For example, if the distance between the two marks is incorrect, the point obtained when the second marked line crosses the perpendicular bisector will be displaced from its intended position. The resulting figure may look close to a regular heptagon, but the error can accumulate throughout the construction.

    3. Observations from a Single Run

    Using the same prompt, we tested a lightweight model and a flagship model. The conclusions below are based on a single run and have not yet been independently repeated.

    Evaluation Item Lightweight Model Flagship Model
    Total runtime Several tens of minutes Nearly 20 minutes
    Adherence to geometric steps No obvious deviation was found in this run Did not reproduce the specified steps; appeared to use an alternative construction
    GIF export Implemented as requested in this run Not recorded
    Code executability Requires local verification Requires local verification
    Manual review conclusion Requires repeated runs for confirmation Requires code inspection for confirmation

    The lightweight model produced an intermittent output process, with some stages showing reasoning but no text output. Despite its relatively long runtime, the final code did not show any obvious violation of the geometric constraints in this run.

    The flagship model responded more quickly and generated a page that displayed a regular heptagon. However, code inspection showed that it did not perform the two-mark ruler steps. Instead, it introduced auxiliary constructions that were not present in the task and ultimately fitted the target shape. This result requires further review and should not be treated as correct without qualification.

    A single run cannot be used to rank models. Model output is stochastic, and repeated executions of the same task can produce different results even with the same model.

    4. Common Failure Modes

    The following issues deserve particular attention in practical evaluations:

    • Coordinate transformation errors: In a mathematical coordinate system, the y-axis points upward, while in a screen coordinate system it usually points downward. If the two systems are not reconciled, the figure may be vertically flipped.
    • Omitted steps: The model may skip constructing the perpendicular bisector used to determine the circle center and directly insert the center coordinates.
    • Hallucinated completion: The model may add auxiliary lines or parameters that were not specified, concealing gaps in its reasoning.

    5. Model Selection and Risk Control

    Reasoning depth and response latency must be balanced according to the use case. For real-time scenarios such as customer support and live translation, latency is a hard requirement. For backend batch processing and the generation of complex data-analysis pipelines, accuracy and instruction adherence should take priority, and longer waiting times may be acceptable.

    The following checklist can support model selection:

    • Suitable scenarios: Batch code generation for backend workflows, tasks with clearly defined steps, and use cases where accuracy is important and longer runtimes are acceptable.
    • Unsuitable scenarios: High-concurrency, low-latency online APIs or conversational features that require immediate feedback.
    • Reproducibility: Fix the parameters, record software versions, run the same task multiple times, and analyze the distribution of outcomes rather than relying on a single result.
    • Manual review cost: Geometry and algorithmic code must be checked step by step. This review effort should be included in the total cost.

    Generated code should not be deployed directly to production. Run it in a sandbox first, then use independent test cases to validate the geometric constraints. If the generated code calls cloud infrastructure services such as object storage or message queues, also review its permission configuration and business logic to prevent unauthorized access or unintended operations.

    6. Conclusion

    Evaluating a large language model’s ability to generate complex code requires fixed test parameters, repeated executions, step-by-step code inspection, and a use-case-specific assessment of latency versus accuracy. The single-run comparison suggests that model size alone does not directly determine instruction-following ability, but this conclusion requires validation with a larger sample.

    Developers should establish their own evaluation benchmarks before selecting a model.