ai-visual-accuracy-check
Use AI to compare rendered HTML to original PDF page. AI makes contextual judgment about visual accuracy with explainable reasoning. BLOCKING quality gate - stops pipeline if score below 85%.
What this skill does
# AI Visual Accuracy Check Skill
## Purpose
This is a **BLOCKING quality gate** that uses **AI to validate visual accuracy** of generated HTML against the original PDF page. Unlike pixel-perfect comparison, AI understands:
- Visual hierarchy and layout intent
- Contextual differences (web rendering vs PDF)
- Whether readers would have similar experience
- Trade-offs between CSS limitations and HTML accuracy
The AI provides:
- Objective similarity score (0-100%)
- Breakdown by evaluation criteria
- Specific differences noted
- Clear pass/fail recommendation
- Explanation for decisions
This combines **AI's contextual understanding** with **deterministic gating** (must pass 85+ to continue).
## What to Do
1. **Load input files**
- Read `chapter_XX.html` (generated consolidated HTML)
- Read `02_page_XX.png` (original PDF page image)
2. **Render HTML to image**
- Use headless browser (Playwright/Selenium) to render HTML as PNG
- Capture full page screenshot
- Save rendered image for comparison
3. **Invoke Claude with visual comparison**
- Attach original PDF PNG as image 1
- Attach rendered HTML screenshot as image 2
- Request detailed visual comparison
- Ask AI to score on multiple criteria
4. **Parse AI response**
- Extract overall similarity score
- Extract criterion-specific scores
- Parse differences noted
- Get recommendation (PASS/FAIL)
5. **Save comparison report**
- Save to: `output/chapter_XX/chapter_artifacts/ai_visual_accuracy.json`
- Include timestamp, inputs used, AI model
6. **Make gate decision**
- If score ≥ 85: PASS (exit code 0, continue)
- If score < 85: FAIL (exit code 1, trigger hook)
## Input Parameters
```
html_file: <str> - Path to chapter_XX.html
pdf_page_png: <str> - Path to original PDF page PNG (or multiple for multi-page)
output_dir: <str> - Directory for report
chapter: <int> - Chapter number (for reporting)
book_pages: <str> - Page range (for reporting)
threshold: <float> - Minimum score to pass (default: 85.0)
```
## AI Prompt Template
```
You are validating the visual accuracy of a generated HTML page against the original PDF.
ORIGINAL PDF PAGE:
[PNG Image of original PDF page attached]
GENERATED HTML (Rendered):
[PNG Image of rendered HTML page attached]
TASK:
Compare these two images and determine if the HTML accurately recreates the visual appearance and layout of the PDF page.
EVALUATION CRITERIA:
1. Layout Match (40% weight)
- Overall page structure matches original
- Sections in correct order and position
- Spacing between elements appropriate
- Page dimensions/aspect ratio similar
2. Visual Hierarchy (30% weight)
- Headings stand out with appropriate prominence
- Section breaks clearly visible
- Emphasis (bold, italic) preserved or equivalent
- Visual relationships between elements clear
3. Content Positioning (20% weight)
- Elements aligned correctly (left, center, right)
- Lists indented with proper spacing
- Tables/exhibits positioned and aligned correctly
- Paragraph flow matches original
4. Typography & Styling (10% weight)
- Font sizes relative to each other correct
- Text styling appropriate (bold, italic, caps)
- Color scheme preserved (if applicable)
- Overall readability equivalent or better
SCORING GUIDELINES:
For each criterion:
- 90-100%: Excellent, no issues
- 80-89%: Good, minor cosmetic differences
- 70-79%: Acceptable, noticeable but not critical
- Below 70%: Poor, significant differences
IMPORTANT CONTEXT:
- HTML rendering in browser may differ slightly from PDF (spacing, fonts)
- Focus on INTENT and READABILITY, not pixel-perfect match
- Small spacing/margin differences (2-5px) are acceptable
- Font rendering differences are acceptable if hierarchy preserved
- Web rendering constraints are acceptable (no absolute PDF positioning)
OUTPUT FORMAT:
Provide your analysis in this exact JSON format:
```json
{
"overall_score": 92.5,
"threshold": 85.0,
"recommendation": "PASS",
"criteria_analysis": {
"layout_match": {
"score": 94,
"feedback": "Overall page structure matches well. Section order correct, spacing appropriate."
},
"visual_hierarchy": {
"score": 90,
"feedback": "Headings clearly distinguished. Visual relationships preserved. Minor font size variance acceptable."
},
"content_positioning": {
"score": 91,
"feedback": "Element alignment correct. Lists properly indented. Tables positioned correctly."
},
"typography_styling": {
"score": 88,
"feedback": "Text styling preserved. Bold and italic distinctions clear. Readability excellent."
}
},
"differences_noted": [
"Paragraph line-height 1.6 vs 1.5 in PDF (acceptable, improves readability)",
"Bullet list indentation 20px vs 15px in PDF (acceptable, clear and readable)"
],
"visual_fidelity_assessment": "EXCELLENT",
"confidence_level": 0.95,
"explanation": "The HTML accurately recreates the PDF page layout and visual hierarchy. All major elements are positioned correctly. Minor spacing and font differences are within acceptable tolerances for web rendering and actually improve readability.",
"pass_fail_verdict": "PASS"
}
```
VALIDATION:
- Overall score must be numeric (0-100)
- All criteria must have scores
- Recommendation must be PASS or FAIL
- Explanation must be clear and actionable
```
## Process Flow
```
┌─ Load HTML & PNG ──────────────────┐
│ • chapter_XX.html │
│ • 02_page_XX.png │
└────────┬────────────────────────────┘
│
▼
┌─ Render HTML to PNG ───────────────┐
│ • Headless browser │
│ • Full page screenshot │
│ • Save to temp location │
└────────┬────────────────────────────┘
│
▼
┌─ Invoke Claude API ────────────────┐
│ • Send original PDF PNG │
│ • Send rendered HTML PNG │
│ • Multi-modal comparison prompt │
│ • Request JSON response │
└────────┬────────────────────────────┘
│
▼
┌─ Parse & Save Report ──────────────┐
│ • Extract JSON from response │
│ • Validate score 0-100 │
│ • Save to JSON file │
└────────┬────────────────────────────┘
│
▼
┌─ Gate Decision ────────────────────┐
│ • If score ≥ 85: PASS │
│ • If score < 85: FAIL │
└────────┬────────────────────────────┘
│
▼
Exit with code 0 or 1
```
## Output File Format
**Path**: `output/chapter_XX/chapter_artifacts/ai_visual_accuracy.json`
```json
{
"chapter": 2,
"book_pages": "16-29",
"validation_type": "ai_visual_accuracy",
"validation_timestamp": "2025-11-08T14:45:00Z",
"overall_score": 92.5,
"threshold": 85.0,
"status": "PASS",
"ai_model": "claude-3-5-sonnet-20241022",
"inputs": {
"html_file": "chapter_02.html",
"original_pdf_png": "02_page_16.png",
"rendered_html_png": "rendered_chapter_02.png"
},
"criteria_scores": {
"layout_match": 94,
"visual_hierarchy": 90,
"content_positioning": 91,
"typography_styling": 88
},
"differences": [
"Paragraph line-height 1.6 vs 1.5 in PDF (acceptable)",
"Bullet list indentation 20px vs 15px in PDF (acceptable)"
],
"visual_fidelity": "EXCELLENT",
"confidence": 0.95,
"explanation": "The HTML accurately recreates the PDF page layout and visual hierarchy...",
"recommendation": "PASS",
"notes": "All criteria well within acceptable ranges. Minor web rendering differences do not impact readability or intent."
}
```
## Multi-Page Chapters
For chapters spanning multiple pages:
1. **Option A: Compare key pages**
- Compare opening page (establishes style)
- Compare middle pages (continuation pages)
- Compare final pages (consistency check)
- Average scores across pages
2. **Option B: Compare consolidated view**
- Render fuRelated in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.