How to Evaluate LLM Spatial Reasoning and Code Generation

    Learn how to evaluate large language models using parameterized 3D scene generation. This article explains how to design text-only tasks, run generated scripts in a sandbox, test parameter changes, and diagnose failures in geometry, code execution, and scene consistency.

    1. Why Evaluate Spatial Reasoning and Code Generation Separately?

    Large language models increasingly deliver similar results on text-based question answering and routine code completion. As scores on public benchmarks converge, those scores alone become less useful for distinguishing practical engineering capabilities.

    Two capabilities offer a more revealing test:

    1. Spatial reasoning: Can a model construct a three-dimensional scene, understand the positions, orientations, and dependencies between objects, and express those relationships mathematically? This capability underpins work in 3D graphics, robotics simulation, and digital twins.
    2. Creative programming: Can a model build a complete, runnable program from a text description alone, without reference images, rather than simply assemble familiar code fragments?

    Both capabilities produce results that can be checked programmatically. Whether a 3D modeling script runs, and whether geometric relationships remain valid after parameter changes, can be tested with limited subjective judgment. That makes these tasks a useful foundation for reproducible evaluation.

    2. Evaluation Design: From Writing Code to Building a Model

    Traditional code evaluations often focus on whether a function passes unit tests. Spatial reasoning evaluation goes further: the generated code must preserve dependencies between parameters and geometry.

    A complex 3D scene task can be organized into three layers:

    • Narrative layer: Describe the scene in natural language. For example: “A waterbird is riding a bicycle along a path at dusk, leaning forward with its wings extended to hold the handlebars and one foot on a pedal.”
    • Parameter layer: Define global constants at the top of the script, such as wingspan, wheelbase, chainring tooth count, and crank phase angle. All geometry must derive from these constants, rather than from unrelated magic numbers inside functions.
    • Acceptance layer: The evaluator changes only the constant values, leaves the rest of the code untouched, and reruns the script to check whether the scene remains valid.

    A model that merely reproduces familiar code may generate a plausible scene under the initial parameters. But changing the chainring from 44 to 52 teeth requires the chain length to be recalculated. Changing the crank phase angle requires the pedal positions and the bird’s foot-to-pedal contact to update together.

    A script that breaks when its parameters change suggests that the model has not established a coherent spatial model—it has reproduced a surface-level pattern.

    3. A Practical Evaluation Prompt Template

    The following simplified prompt can be adapted to 3D modeling scripts, physics simulations, or game-level generation:

    1. Task: Using only the text description, write a Python script that runs
    2. in headless mode and generates a 3D scene of a waterbird riding a bicycle.
    3. Mandatory requirements:
    4. 1. Define the following global constants at the top of the script:
    5. WINGSPAN = 1.15 # Wingspan in meters; determines handlebar width and grip spacing
    6. WHEELBASE = 1.02 # Wheelbase in meters; drives frame geometry
    7. CHAINRING_TEETH = 44 # Chainring tooth count; determines chain length and gear ratio
    8. COG_TEETH = 16 # Rear cog tooth count
    9. CRANK_PHASE = 35.0 # Crank phase angle in degrees; determines pedal and foot positions
    10. 2. Derive all generated geometry from these constants.
    11. Do not use independent magic numbers inside functions.
    12. 3. Keep the bird's riding pose consistent with the drivetrain phase:
    13. when the pedal angle changes, both foot positions and leg bends
    14. must update accordingly.
    15. 4. The script must run successfully in a single execution and output
    16. a scene file without manual intervention.
    17. Acceptance procedure: Change only the constants above, rerun the script,
    18. and check the following:
    19. - When wingspan increases, do the handlebars widen, and do the grips
    20. remain aligned around the wingtips?
    21. - When the chainring grows, is the chain path recalculated correctly,
    22. without intersecting geometry or floating away from the drivetrain?
    23. - When the phase angle changes, is foot-to-pedal contact preserved?

    The central idea is simple: move beyond “Does it run?” to “Does it still work correctly after the parameters change?”

    4. Implementing the Evaluation Pipeline

    To compare multiple models, build an automated evaluation pipeline with the following stages.

    4.1 Distribute Tasks and Collect Outputs

    Send the same prompt independently to each candidate model. Repeat each task several times—for example, five runs—to reduce the influence of sampling variability.

    Collect the complete script returned by each run.

    4.2 Execute Scripts in a Sandbox

    Run each script in headless mode inside a containerized sandbox, using consistent timeouts and resource limits.

    Assign a score of zero to execution failures, including syntax errors, runtime exceptions, and timeouts. Record the failure category for later analysis.

    1. # Pseudocode: core workflow for a single evaluation
    2. def evaluate(model_output: str, mutated_params: dict) -> Score:
    3. script = sanitize(model_output) # Basic safety checks
    4. result = run_in_sandbox(script, timeout=120)
    5. if not result.success:
    6. return Score(passed=False, reason=result.error)
    7. scene = result.scene
    8. checks = [
    9. geometric_consistency(scene), # Validate geometric relationships
    10. parametric_linkage(scene), # Validate parameter dependencies
    11. collision_check(scene), # Detect intersections and unsupported gaps
    12. narrative_match(scene) # Check consistency with the text description
    13. ]
    14. return Score(passed=all(checks), details=checks)

    4.3 Run Parameter Mutation Tests

    Parameter mutation is the core of the evaluation.

    For every script that passes the initial checks, automatically test several parameter variations: change the wingspan, tooth counts, and crank phase angle. Then measure the proportion of modified cases that still pass:

    1. Parametric consistency pass rate =
    2. Passed mutation test cases / Total mutation test cases

    A model should perform consistently on both the initial pass rate and the parametric consistency pass rate before its output can be considered reliable evidence of parameterized spatial modeling capability.

    4.4 Compare Models by Failure Stage

    This type of evaluation can reveal several distinct capability levels:

    • Some models produce a working script on the first attempt and preserve the required relationships after parameter changes.
    • Others generate a correct initial scene but lose consistency under parameter mutation.
    • Some fail to produce a script that runs in headless mode at all.

    These distinctions are more diagnostic than a single leaderboard score. They identify the stage at which a model’s output fails.

    5. Use Evaluation Results to Identify Improvement Areas

    This framework does more than assign scores. It helps locate recurring failure modes:

    • Hard-coded magic numbers: Coordinates are fixed inside functions, leaving the global parameters with little or no effect.
    • Missing dependencies: Chain length or pedal positions do not update with tooth counts or phase changes. The script reflects local imitation rather than a coherent model of the entire scene.
    • Implicit environment dependencies: The script requires a graphical interface or a particular runtime environment, indicating insufficient attention to deployment constraints.
    • Narrative mismatch: The scene runs, but details such as the bird’s posture or foot contact do not match the description.

    On the training side, these failures point toward greater emphasis on parameterized derivation tasks and the principle that geometry should be driven by declared constants.

    On the application side, acceptance checks can be included directly in the system prompt, encouraging the model to check parameter dependencies while generating the script.

    6. Conclusion

    Evaluating a newly released LLM need not stop at repeating its published benchmark scores. A reproducible benchmark with automated acceptance checks can provide a more practical view of its capabilities.

    Parameterized 3D script generation tests four capabilities together: spatial reasoning, mathematical representation, engineering execution, and adaptation to the runtime environment. Its outputs also support largely objective validation.

    The same approach can be adapted to enterprise workflows such as automated modeling, simulation validation, and code generation pipelines. The practical question is not simply whether a model earns a high score, but whether the world it generates remains coherent after the parameters change.