Skip to main content
This example demonstrates how to create comprehensive SVG generation evaluations using the Eval Protocol (EP) framework. The evaluation combines automated SVG rendering with LLM judge assessment to measure how well models can generate visual content that meets specific requirements.
You can find the complete code for this example at test_svgbench.py.

Understanding SVG Generation Evaluation

SVG generation evaluation assesses a model’s ability to:
  • Interpret visual requirements: Understand textual descriptions of visual elements
  • Generate valid SVG code: Create syntactically correct SVG markup
  • Meet specific criteria: Fulfill detailed visual requirements like colors, shapes, positions
  • Follow formatting conventions: Use proper SVG code block formatting
Unlike traditional text evaluations, SVG generation testing evaluates visual creativity and technical precision - essential capabilities for AI systems that need to create graphical content, diagrams, icons, and visual representations.

Understanding the Dataset Structure

The SVG generation dataset contains diverse test cases that evaluate different aspects of visual content creation, from simple geometric shapes to complex multi-element compositions.

Dataset Format

Each entry in the dataset contains:
  • id: Unique identifier for the test case
  • prompt: Base textual description of what to create
  • requirements: List of specific visual criteria that must be met
  • total_requirements: Number of requirements for scoring normalization

Example Dataset Entry

Complex UI Recreation - Google Homepage:

Dataset Characteristics

Requirement Categories:
  • Structural: Presence of specific shapes, elements, or text
  • Aesthetic: Colors, proportions, visual balance, style consistency
  • Technical: SVG formatting, dimensions, code validity
  • Functional: Scalability, accessibility, professional appearance
Evaluation Approach:
  • Automated rendering: SVG to PNG conversion using Selenium WebDriver
  • LLM judge scoring: GPT-4.1 vision model evaluates requirement fulfillment
  • Ratio-based scoring: Score = fulfilled_requirements / total_requirements

Step 1: Import Required Dependencies

First, we import the necessary modules for SVG evaluation:
Key dependencies:
  • base64: For encoding rendered images for LLM judge evaluation
  • litellm: For calling the GPT-4.1 vision model as LLM judge
  • selenium: For automated SVG to PNG rendering (imported conditionally)
  • pydantic: For structured response validation from LLM judge
  • Standard EP framework components for evaluation structure

Step 2: Create the Dataset Adapter

We need to convert the SVG dataset format to the EP’s expected format:
This adapter:
  • Formats visual requirements as a clear numbered list
  • Provides SVG code block formatting instructions with examples
  • Preserves original prompt and requirements for evaluation reference
  • Creates structured metadata for scoring calculations

Step 3: Implement SVG Code Extraction

Extract SVG code from model responses with robust parsing:
Key features:
  • Multiple parsing strategies: Handles both code blocks and raw SVG tags
  • Fallback logic: Tries different extraction methods sequentially
  • Robust extraction: Handles various formatting styles from different models
  • Error handling: Returns None for invalid or missing SVG content

Step 4: Implement SVG to PNG Rendering

Convert SVG code to PNG images for visual evaluation:
Rendering process:
  1. Dimension detection: Extracts SVG dimensions from attributes or viewBox
  2. HTML wrapping: Creates proper HTML container with CSS styling
  3. Browser automation: Uses headless Chrome for consistent rendering
  4. Screenshot capture: Generates PNG image of rendered SVG
  5. Cleanup: Removes temporary files and browser instances

Step 5: Implement LLM Judge Evaluation

Use GPT-4.1 vision model to evaluate requirement fulfillment:
LLM judge features:
  • Vision analysis: Uses GPT-4.1’s multimodal capabilities to examine rendered images
  • Structured evaluation: Provides clear requirements and expects JSON response
  • Strict assessment: Instructs the judge to be thorough in requirement checking
  • Response validation: Ensures proper JSON format and required fields

Step 6: Configure and Run the Evaluation

We use the @evaluation_test decorator to configure the comprehensive evaluation:
Configuration parameters:
  • input_dataset: Path to SVG generation dataset JSONL file
  • completion_params: Multiple model configurations for comparison
  • passed_threshold: 50% average score required to pass evaluation
  • max_concurrent_rollouts: Limits parallel processing for resource management

Evaluation Pipeline Explained

Complete Evaluation Flow

The SVG generation evaluation follows a comprehensive multi-stage pipeline:
  1. Prompt Construction: Formats visual requirements with clear instructions
  2. SVG Generation: Model generates SVG code following specified format
  3. Code Extraction: Robust parsing extracts SVG from various response formats
  4. Visual Rendering: Selenium WebDriver converts SVG to PNG image
  5. LLM Judge Assessment: GPT-4.1 vision model evaluates requirement fulfillment
  6. Score Calculation: Ratio-based scoring provides normalized evaluation results

Evaluation Scenarios and Results

Perfect Generation (Score: 1.0)
Partial Fulfillment (Score: 0.6)
Technical Issues (Score: 0.0)
Requirements Mismatch (Score: 0.2)

Advanced Features and Capabilities

Debug File Generation

The evaluation supports saving debug files for analysis:

Multi-Model Comparison

The evaluation supports comparing multiple models simultaneously:

Conclusion

This SVG generation evaluation example demonstrates how to create comprehensive assessments of AI models’ visual content creation capabilities. The multi-stage evaluation process ensures models can understand visual requirements, generate syntactically correct SVG code, meet specific criteria consistently, and follow proper formatting standards. This evaluation approach is particularly valuable for visual AI development, design automation, educational applications, and creative tooling. The SVG generation evaluation complements other evaluation types by focusing on visual-technical accuracy and requirement adherence, making it essential for developing reliable AI systems that can bridge the gap between textual understanding and visual creation.