Evaluating Instruction Following in Code Generation Models with Geometric Construction Tasks
This article explains how geometric construction tasks can test whether code generation models follow complex multi-step instructions, not just produce correct-looking output. It covers how to decompose instructions into verifiable checks, six evaluation dimensions, methods for detecting superficially correct implementations, an automated evaluation workflow, result interpretation cautions, relevant geometry background, and suggestions for engineering adoption.
1. Why Use Geometric Construction as a Test Task
Code generation models are often evaluated with algorithm problems such as sorting or string processing. The correctness of these problems is easy to judge, but they rarely reflect how well a model understands complex process instructions. Geometric construction tasks are different. They specify a clear sequence of operations, each step has a mathematical meaning, and the final result can be verified with coordinates and distances.
Geometric construction tasks also have another characteristic: they easily produce results that are “superficially correct.” A figure on the page may match the target figure, but the method used to generate it may have nothing to do with the construction steps required by the task. This kind of deviation is hard to find in ordinary output checks, which makes it suitable as a focus for evaluation.
2. Breaking Multi-Step Instructions into Verifiable Checks
The first step in evaluation is to break the instructions apart. A typical task usually contains the following types of requirements:
- Initial conditions, such as a given square, a specified vertex, or a specified edge.
- Construction actions, such as drawing a perpendicular bisector, drawing a circle centered at a point, or using a restricted tool to determine an intersection point.
- Completion of omitted parts, such as a note that “routine operations are omitted,” requiring the model to fill them in.
- Additional features, such as exporting an animation file or preserving the construction trace.
Each action should correspond to a check that can be verified. The structure below can serve as a checklist template:
checks = [{"id": "S1","step": "Take the square and draw the perpendicular bisector of the bottom edge","verify": "The perpendicular bisector passes through the midpoint of the bottom edge and is perpendicular to it",},{"id": "S2","step": "Draw a circle centered at the specified vertex with the diagonal length as the radius","verify": "The distance from each point on the circumference to the center equals the diagonal length",},{"id": "S3","step": "Use the restricted tool to determine the intersection point that satisfies the conditions","verify": "The intersection point lies on the specified line or circle",},{"id": "S4","step": "Complete the omitted routine construction steps","verify": "Each new point can be uniquely determined from the preceding steps",},]
Checks should be written specifically. “The figure looks right” cannot be a check criterion; “the distance from a point to the circle center equals the radius” can be reviewed by a program or a human.
3. Designing Evaluation Dimensions
A single “completed or not” judgment cannot distinguish differences in model capability. It is better to score separately across the following six dimensions.
1. Instruction Following
Check whether the model constructs the figure using the tools and order required by the task. If the task restricts the use of a certain tool, the output must not replace it with another method. This dimension focuses on “how it is done,” not only on “what is produced.”
2. Mathematical Correctness
Use coordinate calculations to verify geometric relationships. For example, all vertices of a regular polygon should lie on the same circle, and adjacent vertices should be equally spaced. This kind of check can be performed with a simple function:
import mathdef all_on_circle(points, center, radius, tol=1e-6):"""Check whether all points lie on the same circle."""return all(abs(math.dist(p, center) - radius) < tol for p in points)
Numerical error requires a tolerance. Floating-point operations inevitably produce small deviations in drawing. A tolerance that is too small causes false positives, while a tolerance that is too large lets real errors pass.
3. Output Completeness
Check whether the page contains all elements required by the task, such as completion of omitted parts, animation, or export functionality. Completeness problems are especially common in long outputs; models often omit content in the final additional requirement.
4. Engineering Quality
The page should run directly in a browser, not depend on undeclared external resources, and have no uncaught errors in the console. This dimension can use a headless browser to automatically collect runtime logs.
5. Process Transparency
Record whether the model’s output stream is continuous and whether there are cases with reasoning only and no final result. These phenomena do not necessarily affect the final result, but they directly affect the user experience and often reflect the model’s stability on long tasks.
6. Time Cost
Record the time to the first useful character and the total time for the complete output separately. Time data should be interpreted together with task scale and measured under the same network and hardware conditions; otherwise, results cannot be compared across runs.
4. Identifying “Apparently Correct” Implementations
This is the most valuable part of geometric construction evaluation. Common deviations include:
- Directly calculating vertex coordinates with trigonometric functions, bypassing the required construction process.
- Using built-in graphics functions to draw the target shape directly, skipping intermediate construction lines.
- Intermediate construction lines that are only decorative and have no logical relationship with the final result.
The following code shows the first case. Its final figure matches a regular polygon, but it does not reflect any construction steps:
// Deviating implementation: calculate vertices directly without the construction processconst vertices = Array.from({ length: 7 }, (_, k) => [cx + r * Math.cos((2 * Math.PI * k) / 7),cy + r * Math.sin((2 * Math.PI * k) / 7),]);
The way to identify these problems is to inspect the code structure, not just the rendered result. You can require the model to label each construction point and check whether each labeled point can be traced back to an operation specified by the task. If a key point cannot be derived from preceding steps, it should be judged as a deviation.
5. Building an Automated Evaluation Workflow
A reusable workflow usually contains four stages:
- Fix the prompt and generation parameters, and record version information so that multiple tests are comparable.
- Extract the page code from the model output and save it as a standalone file.
- Load the page with a headless browser, collect console logs, and capture the rendered result.
- Execute the check functions from Sections 2 and 3, and output per-item scores and failure reasons.
The skeleton of the workflow can be written as follows:
def evaluate(sample_html, checks, runner):report = {}report["loads"] = runner.load_without_errors(sample_html)report["geometry"] = runner.check_geometry(sample_html, checks)report["complete"] = runner.check_features(sample_html, checks)return report
Here, runner is a wrapper around the headless browser; the specific implementation depends on the runtime environment used by the team.
6. Cautions When Interpreting Results
A single test result lacks representativeness. For the same prompt, the model output may differ each time, so multiple samples should be taken and the distribution of pass rates should be analyzed rather than looking only at one success or failure.
Evaluation tasks also need to guard against data contamination. If the task and its standard solution have been widely published, the model may have memorized the answer, and the pass rate then cannot reflect reasoning ability. Task parameters can be changed periodically, such as changing the side length of the square or the construction order, to reduce this risk.
Human review is still necessary. Automated checks can cover most mathematical relationships, but semantic questions such as “whether the specified construction method was followed” still require judgment by experienced reviewers.
7. Geometry Background
Understanding the task itself requires some background knowledge. Using only a straightedge and compass, it is impossible to construct a regular heptagon exactly. This conclusion comes from the Gauss-Wantzel theorem: a regular n-gon can be constructed with straightedge and compass if and only if every odd prime factor of n is a distinct Fermat prime. Since 7 is not a Fermat prime, it cannot be constructed with ordinary straightedge and compass.
The ancient Greek scholar Archimedes proposed methods for solving such problems with a marked ruler, a type of tool also known as a neusis construction. With a marked ruler, a line can be made to pass through a certain point while a marked segment satisfies a specified length, thereby expanding the range of constructible figures. The regular heptagon is a typical example that can be completed with this kind of method.
Therefore, a high-quality generation result should reflect correct use of tool restrictions and construction logic. If the model ignores this restriction and calculates vertices directly, it shows that it has not truly understood the requirements of the task.
8. Suggestions for Engineering Adoption
When incorporating the above evaluation into daily workflows, consider the following practices:
- Build a fixed test set containing geometry, algorithm, and interface tasks of different difficulty levels, and record historical results by category.
- Classify failure cases by cause, distinguishing understanding errors, mathematical errors, implementation errors, and output truncation, so that prompts can be improved in a targeted way.
- Turn key checks into regression tests that run automatically after model or prompt changes, so that degradation is detected in time.
- When reporting results externally, include the sample size, sampling parameters, and distribution of failure types, rather than showing only the best output.
With this approach, teams can move from “does the page look right” to “is the method correct and is the result verifiable,” which is the core of evaluating instruction-following capability.
