Introduction
While Large Language Models (LLMs) have revolutionized text-based educational tools, their ability to generate and verify visual content remains a significant hurdle. In mathematics, diagrams are indispensable for conceptual understanding. However, evaluating the TikZ code (a LaTeX-based vector graphics language) generated by LLMs is currently a bottleneck, requiring either expensive human expertise or unreliable "LLM-as-a-Judge" approaches. Standard LLMs often lack the spatial reasoning necessary to detect subtle errors, such as misplaced labels, open shapes, or mathematically inconsistent proportions.
To address this, we present DiagramIR, an automated pipeline designed to evaluate the mathematical and spatial accuracy of AI-generated math diagrams with high precision and low cost.
The DiagramIR Pipeline
DiagramIR utilizes a "back-translation" approach that shifts the evaluation task from probabilistic prediction to deterministic computation. The process follows three distinct stages:
- Translation to IR: An LLM acts as a deterministic parser, converting raw TikZ code into a structured Intermediate Representation (IR). This JSON-like schema explicitly defines geometric primitives such as vertices, shapes, line segments, and arcs.
- Rule-Based Verification: Once structured, the diagram undergoes a suite of deterministic mathematical checks. These algorithms verify if numerical labels match coordinate-based geometry (e.g., checking if a labeled 45° angle is actually 45° in the code).
- Spatial Auditing: The system performs automated spatial checks to ensure the diagram is fully within the frame, elements are scaled for readability, and labels do not overlap with geometric lines.
By decoupling perception (parsing) from verification (math), DiagramIR provides specific, auditable failure reasons that standard LLM judges cannot offer.
Experimental Setup
The pipeline was evaluated using the Coteach Dataset, comprising 398 geometric constructions (208 2D and 190 3D diagrams). These instances were sourced from 6,000 real-world interactions between educators and "Coteach," an AI assistant. A human baseline was established through expert annotation of 386 test diagrams based on a rigorous rubric of mathematical and spatial correctness.
Performance and Cost Analysis
DiagramIR demonstrated superior alignment with human experts compared to traditional LLM-as-a-judge methods. The pipeline achieved a Cohen’s $\kappa$ (inter-rater agreement) between 0.48 and 0.56, whereas standard AI judging methods peaked at 0.47.
Crucially, DiagramIR enables smaller models to punch above their weight. Using GPT-4.1 Mini within the DiagramIR pipeline outperformed much larger frontier models like GPT-5 acting as a standalone judge. This efficiency resulted in a 10x reduction in cost, with evaluation expenses dropping from $4.83 (GPT-5) to just $0.47 (GPT-4.1 Mini) for the entire dataset.
Conclusion and Future Work
DiagramIR proves that moving from purely neural evaluation to a hybrid back-translation approach significantly improves the reliability of AI-generated educational content. While the current system is limited to basic geometric primitives and does not yet account for pedagogical utility, it provides a scalable foundation for automated diagram verification. Future work will focus on expanding the IR schema to support complex function plots and fine-tuning specialized, small-scale models for the TikZ-to-IR translation task to further optimize performance.
Summary updated