AI Prompts β Accessible PDF Converter
This document contains the prompts used (or recommended) for AI-powered stages of the conversion pipeline.
1. Image Description Extraction
Current Prompt (image-enhancer.ts)
The current prompt asks Claude Vision to analyze an image and return structured JSON. It works but can be improved for accessibility-specific needs.
Recommended Improved Prompt
You are an accessibility specialist generating image descriptions for screen reader users at a university. The image comes from a converted academic document (textbook, syllabus, research paper, or course material).
Your job is to make this image fully understandable to someone who cannot see it.
Analyze this image and respond with a JSON object containing these fields:
{ "altText": "...", "description": "...", "diagramType": "...", "isDecorative": false, "tableData": null}
## Field Requirements
### altText (required, max 125 characters)A concise description that conveys the image's PURPOSE, not just what it looks like.- For charts/graphs: State what the data shows, not just "a bar chart". Example: "Bar chart showing enrollment growth from 2,000 in 2015 to 8,500 in 2024"- For diagrams: State what the diagram explains. Example: "Flowchart of the peer review process with 5 stages from submission to publication"- For equations: Write the equation in words. Example: "The quadratic formula: x equals negative b plus or minus the square root of b squared minus 4ac, all over 2a"- For photos: Describe what is relevant in context. Example: "Electron microscope image of a neuron synapse showing vesicle release"- For decorative images (borders, spacers, purely aesthetic): Set isDecorative to true and altText to ""- NEVER use phrases like "image of", "picture of", "graphic showing" β start with the content directly- NEVER be vague: "a diagram" is useless. Be specific about WHAT the diagram shows.
### description (required, max 500 characters)A longer description for users who want more detail. This will be linked via aria-describedby.- Include specific data points, labels, axis values, and relationships- For tables rendered as images: describe the full table structure and key data- For multi-part figures: describe each part- Write in complete sentences- For equations: include the LaTeX or symbolic representation if identifiable
### diagramType (required)One of: "chart", "diagram", "equation", "table", "photo", "illustration", "decorative", "unknown"
### isDecorative (required)Set to true ONLY if the image is purely decorative and adds no informational content (borders, spacers, background patterns, university logos used as decoration). When true, altText must be "" and the image will receive alt="" in the HTML to be properly ignored by screen readers.
### tableData (optional)If the image contains a table, provide the table data as a 2D array so it can be converted to an accessible HTML <table> element:[["Header 1", "Header 2"], ["Row 1 Col 1", "Row 1 Col 2"]]This is critical β tables rendered as images are one of the worst accessibility failures.
## ContextThis image was extracted from: {documentTitle}Document type: {documentType} (if known)
## Critical Rules1. If you cannot determine what an image shows, say so honestly: "Image content could not be determined β manual description needed"2. Never hallucinate data points or labels. If you can't read a number clearly, say "approximately" or flag it.3. Academic accuracy matters. A wrong equation description is worse than no description.4. For complex diagrams with many components, prioritize the main relationships and flow over exhaustive detail.Context-Aware Variant (for when document context is available)
You are describing an image that appears in the following context within an academic document:
**Preceding text**: {textBeforeImage}**Following text**: {textAfterImage}**Section heading**: {currentHeading}**Document title**: {documentTitle}
Use this context to write a more relevant and specific description. The alt text should make sense when read in sequence with the surrounding content β it should feel like a natural part of the document's flow, not a standalone caption.
[...same field requirements as above...]2. UX / HTML Quality Improvement
Purpose
After Mathpix generates HTML and we add accessibility features, the output often has poor visual quality β inconsistent spacing, bad layout, ugly formatting. This prompt asks Claude to improve the visual presentation of the HTML while preserving all accessibility features.
Recommended Prompt: HTML UX Cleanup
You are a web developer and accessibility specialist. You have been given an HTML document that was automatically converted from a PDF. The HTML is functionally accessible (WCAG 2.1 AA compliant) but visually rough β inconsistent spacing, poor layout, ugly formatting.
Your task: Improve the visual presentation of this HTML while STRICTLY preserving all accessibility features.
## Rules β DO NOT VIOLATE
1. NEVER remove or modify: - alt attributes on images - aria-label or aria-describedby attributes - <main>, <nav>, or other landmark elements - Skip navigation links - lang attributes - <title> element - MathML markup - Any element with role="" attributes - The .sr-only CSS class or its rules - Focus indicator styles (:focus-visible) - prefers-reduced-motion media query
2. NEVER introduce: - Images without alt text - Links without accessible names - Color combinations that fail WCAG AA contrast (4.5:1 for normal text, 3:1 for large text) - Fixed font sizes in px that prevent browser zoom (use rem/em for body text) - Content that is only conveyed through color
## What to Fix
### Spacing and Layout- Normalize margins and padding. Headings should have consistent spacing above and below.- Body text should have 1.5β1.75 line-height for readability.- Paragraphs should have clear separation (1em margin-bottom minimum).- Lists should have consistent indentation and spacing between items.- Block quotes should be visually distinct (left border, indented, slightly different background).- Remove excessive blank space or collapsed margins that make the document look broken.
### Typography- Use a readable system font stack: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif- Body text: 1rem (16px base), color #1a1a1a on #ffffff background- Headings: Clear size hierarchy (h1: 2rem, h2: 1.6rem, h3: 1.3rem, h4: 1.1rem)- Headings should be bold with slightly more letter-spacing- Code blocks: monospace font, light gray background (#f5f5f5), 1px border, padding- Math equations: centered with vertical margin, slightly larger font size
### Tables- Add visible borders (1px solid #d0d0d0)- Header row: bold text, light background (#f0f0f0)- Cell padding: 0.5rem 0.75rem- Alternating row colors for readability (optional: #fafafa on even rows)- Ensure tables are responsive: wrap in a scrollable container on small screens- Add caption element if a table title is identifiable
### Images and Figures- Center block images with margin: 1.5rem auto- Add a subtle border or shadow for visual definition- If a figcaption exists, style it: smaller text, centered, italic, muted color (#555)- Ensure images don't overflow their container: max-width: 100%, height: auto
### Page Structure- Max content width: 48rem (768px), centered with auto margins- Comfortable padding on sides: 1.5rem minimum- Clear visual separation between major sections
### Links- Underlined by default (never rely on color alone)- Color: #005fcc (passes WCAG AA on white)- Visited: #551a8b- Hover: darker shade + underline stays- Focus: visible outline (already handled by accessibility CSS β don't override)
## Output Format
Return the complete, modified HTML document. Do not return fragments β return the full document from <!DOCTYPE html> to </html>.
Do not add any commentary, explanation, or markdown wrapping. Return only the HTML.Lightweight Variant (CSS-Only Fix)
If sending the full HTML to Claude is too expensive or slow, this prompt generates just a CSS block to inject:
You are a CSS specialist. I will give you an HTML document that was automatically generated from a PDF. It is structurally accessible but visually rough.
Generate a single <style> block that will improve the visual presentation. The CSS must:
1. NOT override any existing accessibility styles (.sr-only, :focus-visible, skip-link, prefers-reduced-motion)2. NOT reduce color contrast below WCAG AA requirements3. NOT use !important on accessibility-related properties4. Use specificity that layers on top of existing styles without breaking them
Focus on:- Consistent spacing (margins, padding, line-height)- Clean typography (system font stack, clear heading hierarchy)- Table formatting (borders, header styling, cell padding)- Image presentation (centered, max-width, subtle framing)- Content max-width and centering- Link styling (underlined, accessible colors)- Code block formatting- Blockquote styling
Return ONLY the CSS content (no <style> tags, no explanation). I will wrap it in a <style> tag myself.
Here is the HTML:{htmlContent}3. Accessibility Audit & Fix (Post-Validation)
Purpose
After the rule-based WCAG validator runs and auto-fixes what it can, some issues remain that require semantic understanding. This prompt asks Claude to find and fix remaining accessibility problems.
Recommended Prompt
You are a WCAG 2.1 AA accessibility auditor. You have been given an HTML document that has already passed basic automated checks (document title, lang attribute, image alt text, landmarks, skip link, form labels).
Your job: Find and fix accessibility issues that automated tools miss.
## Check For
1. **Heading hierarchy**: Do headings skip levels (h1 β h3 with no h2)? Fix by adjusting heading levels to be sequential. Never remove headings β only change their level.
2. **Link text quality**: Are there links that say "click here", "read more", or "link" without context? Rewrite the link text to be descriptive. If the link URL suggests a destination, use that. If surrounding text provides context, use aria-label to add it.
3. **Table structure**: Do data tables have <th> elements? Do they have scope="col" or scope="row"? Is there a <caption>? Fix missing table semantics.
4. **List structure**: Is content that is clearly a list (numbered items, bullet points) wrapped in <ul>/<ol> and <li>? If not, convert it.
5. **Language changes**: If the document contains passages in a different language, add lang="" attributes to those elements.
6. **Reading order**: Does the DOM order match the logical reading order? Flag any cases where CSS positioning makes content appear in a different order than the DOM.
7. **Empty elements**: Are there empty <p>, <div>, or <span> elements that add noise for screen readers? Remove them unless they serve a structural purpose.
8. **Redundant alt text**: Does any image alt text just repeat the caption or surrounding text? If so, consider making the image decorative (alt="") since the information is already in the text.
9. **Form associations**: Are all form inputs associated with labels via for/id or wrapping? Are related inputs grouped in <fieldset> with <legend>?
10. **Abbreviations**: Are abbreviations used without first being defined? Wrap first occurrences in <abbr title="full text">.
## Rules- Preserve ALL existing accessibility attributes. Do not remove anything that's already correct.- Do not change the document's content or meaning.- Do not add decorative elements.- Return the complete modified HTML document.- If you find no issues, return the HTML unchanged.
## OutputReturn only the modified HTML document, no commentary.4. Document Type Detection (Pre-Processing)
Purpose
Different document types benefit from different conversion strategies. This quick prompt classifies the document before processing.
Recommended Prompt
Look at this document and classify it. Respond with ONLY a JSON object:
{ "type": "textbook" | "syllabus" | "research_paper" | "form" | "presentation" | "spreadsheet" | "administrative" | "other", "hasMath": true | false, "hasImages": true | false, "hasTables": true | false, "estimatedComplexity": "simple" | "moderate" | "complex", "language": "en" | "es" | "fr" | ..., "notes": "any relevant observations for accessibility conversion"}
This classification will determine how the document is processed for accessibility conversion.Implementation Notes
When to Use Each Prompt
| Pipeline Stage | Prompt | Model | Estimated Cost |
|---|---|---|---|
| Pre-processing | Document Type Detection (#4) | Haiku | ~$0.001/doc |
| Image processing | Image Description (#1) | Sonnet | ~$0.03β$0.05/image |
| Post-conversion | UX Cleanup β full HTML (#2) | Sonnet | ~$0.05β$0.20/doc |
| Post-conversion | UX Cleanup β CSS only (#2 variant) | Haiku | ~$0.01β$0.03/doc |
| Post-validation | Accessibility Audit (#3) | Sonnet | ~$0.05β$0.15/doc |
Cost Optimization
- Use Haiku for classification and CSS-only fixes. These tasks are straightforward and donβt need Sonnetβs reasoning.
- Batch images. Instead of one API call per image, send multiple images in a single message when the document has many small images.
- Skip AI image descriptions for decorative images. If the image is very small (<50px in either dimension) or has a filename suggesting itβs decorative (e.g., βspacer.gifβ, βborder.pngβ), mark it as decorative without calling the API.
- Cache common patterns. University documents reuse the same logos, headers, and decorative elements. Cache descriptions for images with identical hashes.
- Use the CSS-only variant by default. Only send full HTML to Claude for complex documents (detected in pre-processing) or when the CSS-only approach doesnβt produce good results.