Evaluating Large Language Model Code Generation: Geometry Construction as a Test Case
This article examines why conventional code-generation benchmarks often fail to distinguish models in practical use. Using compass-and-straightedge geometry tasks as an example, it presents a structured evaluation framework covering result accuracy, procedural compliance, delivery quality, and engineering metrics such as latency, streaming stability, recovery, and run-to-run consistency.
1. Why Code Generation Evaluation Needs to Be Reconsidered
Code-generation models have improved rapidly over the past two years. Traditional function-level programming problems are approaching saturation, with most models achieving relatively high scores. As a result, teams often find that models with similar benchmark scores can provide very different experiences in real-world use.
Generating web animations and small visualization pages has often been used as a quick test because the output is visually intuitive and easy to inspect. However, these tasks also have clear limitations. Prompts can become highly templated, and a model may have seen similar examples in its training data. In addition, a page that runs and looks correct does not necessarily contain correct internal logic. These tasks are therefore better suited as an initial capability screen rather than as the sole basis for a comprehensive evaluation.
2. Characteristics of a Good Evaluation Task
1. Verifiable. The result should be determinable through programmatic checks or clear human judgment. For example, the error in geometric side lengths and angles can be quantified against defined tolerances.
2. Discriminative. The task should have a difficulty level at which models demonstrate meaningful differences. Tasks that are too easy cannot distinguish capabilities, while tasks that are too difficult may cause every model to fail.
3. Clearly constrained. The prompt should specify the required steps or methods so that evaluators can verify whether the model followed the intended approach.
4. Resistant to shortcuts. Checking only the final result encourages models to approximate or “hack” the answer. An evaluation should also inspect the intermediate process.
Evaluation rules can be organized as a structured checklist for item-by-item scoring:
rubric = {"Result accuracy": "The relative error of each side is no more than 1%","Step consistency": "Key construction steps appear in the order specified by the prompt","No extra steps": "No auxiliary construction not required by the prompt is introduced","Complete delivery": "The page runs directly and additional features work",}
3. Compass-and-Straightedge Construction as an Example
Compass-and-straightedge construction is a classic setting for testing geometric reasoning. A standard straightedge and compass can perform only a limited set of constructions. A regular heptagon cannot be constructed exactly using only these tools, a result derived from the algebraic work of Gauss and Wantzel.
If a marked ruler with two scales is allowed as an auxiliary tool—known as a neusis construction—the regular heptagon can be constructed by sliding the marked ruler so that it passes through designated points. This is the central design challenge of the task: the model must understand the constraint of using an auxiliary tool and turn each construction step into an observable dynamic demonstration.
Such a task typically includes the following substeps:
- Construct a square and draw the perpendicular bisector of its bottom edge.
- Draw a circle centered at a specified vertex, using the diagonal length as the radius.
- Simulate sliding the marked ruler so that one end touches the specified vertex, another mark lies on the circle, and the ruler passes through the perpendicular bisector.
- Use the resulting intersection point to determine subsequent circle centers through conventional compass-and-straightedge methods, and continue the construction.
- Preserve construction traces only where necessary and support exporting the process as an animated image file.
The result can be evaluated from three dimensions:
- Result: Whether the generated figure is a regular heptagon, and the errors in its side lengths and interior angles.
- Process: Whether the construction order matches the prompt and whether undeclared auxiliary lines or extra steps are introduced.
- Delivery: Whether the page runs directly, the animation is smooth, and the export function works.
A common problem in practice is that the final figure looks correct even though the construction path does not match the task description at all. A model may independently add steps and force the target shape into existence. Such an output may appear successful in a demonstration, but it cannot be reliably reused and does not show that the model truly understood the prompt. Process validation is therefore indispensable.
Result accuracy can be checked automatically. The following example computes the side lengths and interior angles of the vertices and compares them with those of an ideal regular polygon:
import mathdef side_length(p, q):return math.hypot(p[0] - q[0], p[1] - q[1])def interior_angle(a, b, c):v1 = (a[0] - b[0], a[1] - b[1])v2 = (c[0] - b[0], c[1] - b[1])cos_t = (v1[0] * v2[0] + v1[1] * v2[1]) / (math.hypot(*v1) * math.hypot(*v2))return math.degrees(math.acos(max(-1.0, min(1.0, cos_t))))def check_regular_polygon(points, n, tol=0.01):# points contains the coordinates of n vertices in ordersides = [side_length(points[i], points[(i + 1) % n]) for i in range(n)]mean = sum(sides) / nsides_ok = all(abs(s - mean) / mean <= tol for s in sides)ideal = (n - 2) * 180 / nangles_ok = all(abs(interior_angle(points[i - 1], points[i], points[(i + 1) % n]) - ideal) <= tol * 180for i in range(n))return sides_ok and angles_ok
This check can validate the result but cannot determine whether the construction process complied with the requirements. Process consistency still requires a human evaluator to compare the output against the step checklist. Reliable conclusions require combining both methods.
4. Engineering Observations on Process and Delivery Quality
In addition to the result itself, an evaluation should record engineering metrics from the execution process:
- Time to first output and total duration: Long reasoning or generation phases directly affect the interactive experience. The distribution of timings should be recorded rather than only the total duration.
- Streaming stability: Observe whether the output pauses for extended periods or produces only reasoning content without a final deliverable.
- Interruption and retry behavior: If a request fails midway, determine whether the system can recover and whether the recovered result is complete.
- Consistency across runs: Run the same prompt multiple times and measure the degree of variation between outputs.
Each run should use a standardized record format, including fields such as case ID, run order, time to first output, completion time, interruption status, result score, and process score. A consistent format makes horizontal comparisons easier and supports later analysis.
5. Recommendations for Team Adoption
- Build a tiered evaluation set. Separate test cases for basic syntax, API usage, algorithm implementation, visualization generation, and long-context understanding.
