Testing Instruction Following in Lightweight LLMs: HTML Geometric Construction as a Case Study
This article examines how a lightweight language model handles a multi-step, process-constrained HTML animation task: a marked-ruler construction of a regular heptagon. It describes the task design, observed results, and a practical method for auditing whether generated code preserves intermediate construction states. It also provides implementation notes for animation and GIF export, plus a checklist for evaluating models on workflow-strict code generation. The observations come from a small number of runs and are not intended to represent overall model capability.
Introduction
Requirements for code generated by large language models have moved beyond “it runs” to “it is logically rigorous and fully complies with constraints.” Lightweight models offer low deployment cost and fast response, but reliable public data on their performance in multi-step tasks with physical processes is still limited. This article uses an HTML animation task—constructing a regular heptagon with a marked ruler—to record observed behavior and provide a reusable code audit method and model selection checklist. The data comes from a small number of runs by the author and should not be extrapolated to the model’s overall capability.
1. Test Task and Step Design
The task requires the model to generate an HTML page that uses frontend code to dynamically demonstrate the marked-ruler construction of a regular heptagon. The main steps and constraints are as follows:
| No. | Step or constraint | Verification point |
|---|---|---|
| 1 | Take a square and construct the perpendicular bisector of its base. | Do the square and perpendicular bisector appear correctly on the canvas? |
| 2 | With the lower-right vertex E as the center and the diagonal length as the radius, draw circle E. | Are the center and radius computed from the diagonal length? |
| 3 | Place the marked ruler against the lower-left vertex D; move the first mark along circle E until the second mark passes through the perpendicular bisector of the base. | Does the code simulate the movement process rather than directly giving the result? |
| 4 | Continue the standard straightedge-and-compass construction to determine subsequent centers. | Is the subsequent construction coherent? |
| 5 | Complete all omitted straightedge-and-compass parts, leaving compass marks only where necessary. | Are traces retained only where necessary? |
| 6 | Add a function to export the drawing process as a GIF. | Does the exported file play normally? |
The steps in the table come from the main content of the test prompt. The full original prompt and version number should be recorded separately for reproduction; this article cannot replace the original prompt.
The difficulty of this task is that the final geometric conclusion can be calculated directly with trigonometry, but the task requires simulating the construction process. If the model bypasses intermediate steps, the page may look the same while the process does not meet the requirements. Verification therefore needs to check whether the code truly preserves intermediate states.
2. Observed Results
In one test run by the author, the page generated by the lightweight model completed the drawing of the square, perpendicular bisector, circle E, and marked-ruler movement step by step. Trace control and GIF export also had corresponding code. This is an observation from one run in one environment and is not enough to show that the model is stable and reliable on all geometry problems.
Time and output stability were the more obvious issues in this test. The author recorded one run that took about 34 minutes, with long pauses in output. Because hardware configuration, concurrency, input/output length, and sampling parameters were not saved at the time, and there were no statistics from multiple runs, this number only describes that single run. For real-time service, the distribution of time-to-first-token and total latency should be measured first.
3. How to Audit Whether the Model Draws Step by Step
A correct page image does not mean a correct process. The author recommends checking the code with the following three questions:
- Does the code contain state variables representing the position or angle of the marked ruler, and are they updated with animation frames?
- Are the vertices of the regular heptagon obtained from the drawing process rather than generated directly by an analytic formula?
- Are traces implemented through clipping or segmented drawing rather than being fully retained or fully cleared?
Only code that satisfies these three points implements the process required by the task. Checking only the final shape makes it easy to miss this type of problem.
4. Code Implementation Notes
Below is a simplified illustration of the core animation logic; it is not directly runnable.
const EPS = 1e-6;const MAX_FRAMES = 2000;function isAtScaleLength(p1, p2, length) {// Floating-point calculations have rounding error; do not use === directly; set a tolerance.return Math.abs(distance(p1, p2) - length) < EPS;}function animateNeusis() {let angle = 0;let frame = 0;function step() {ctx.clearRect(0, 0, canvas.width, canvas.height);drawBaseShapes(ctx);const p1 = pointOnCircleE(angle);const p2 = intersectWithPerpendicular(p1, vertexD);// Set both the target condition and a maximum frame count to prevent an infinite loop if the condition is never met.if (isAtScaleLength(p1, p2, SCALE_LENGTH) || frame >= MAX_FRAMES) {drawFinalState(ctx, p1, p2);finishGifExport();return;}angle += ANGLE_STEP;frame += 1;requestAnimationFrame(step);}step();}
The following points need attention during implementation:
- Floating-point comparison: Distance calculations have rounding error, so a tolerance must be used when checking whether the scale length has been reached.
- Termination condition: In addition to the target condition, a maximum frame count should be set.
- GIF dependency: For example, with gif.js, include it via npm or CDN and point the
workerScriptparameter togif.worker.js. Check the API of the version being used before use. This article does not pin a version number. - GIF export: Call
addFramefor each frame, callrenderafter all frames have been added, and download the generated file in thefinishedevent.
A minimal runnable example usually contains the following files:
index.html: page structure and canvas element.main.js: animation and construction logic.gif.jsandgif.worker.js: GIF encoding library and its worker file.
The runtime environment needs to be a modern browser that supports Canvas 2D and requestAnimationFrame.
5. Model Selection Checklist
When choosing a model for tasks with strict workflows, record each item in the following table:
| Dimension | Check method | Record item |
|---|---|---|
| Instruction following | Compare intermediate states against the step table item by item | Number of steps covered |
| Logical constraints | Check whether traces appear only where necessary | Pass or fail |
| Inference latency | Run the same prompt multiple times and take the distribution rather than a single value | Time-to-first-token, total latency |
| Output stability | Repeat runs and count failures | Failure count and failure types |
| Cost | Calculate by token or compute time | Cost per task |
| Reproducibility | Record model version, sampling parameters, and runtime environment | Whether logs are complete |
6. Conclusion
In this limited test, the lightweight model completed the main requirements of a multi-step construction, but latency and output stability still need more samples for verification. For code generation tasks with strict workflows, the process should first be audited using the method in Section 3, and then model size should be compared. Deployment should be chosen according to the team’s cost and compliance requirements; both cloud platforms and self-hosted inference services are possible, based on measured data.
