Emailens
Engine Package

LLM Export

Generate LLM-ready prompts from email analysis results for automated fixing.

generateFixPrompt

Generates a structured Markdown prompt that an LLM can use to fix email compatibility issues.

function generateFixPrompt(options: ExportPromptOptions): string

Parameters

interface ExportPromptOptions {
  originalHtml: string;                      // The original email HTML/JSX/MJML
  warnings: CSSWarning[];                    // Warnings from analyzeEmail()
  scores: Record<string, {
    score: number;
    errors: number;
    warnings: number;
    info: number;
  }>;
  scope: "all" | "current";                 // Fix all clients or just one
  selectedClientId?: string;                 // Required when scope is "current"
  format?: "html" | "jsx" | "mjml" | "maizzle"; // Input format (default: "html")
}

Returns

A Markdown string containing:

  1. Context — format, scope, issue counts
  2. Original email code — the full source in a code block
  3. Compatibility scores table — per-client scores
  4. Detected issues — grouped by severity with before/after fixes
  5. Instructions — what the LLM should do

Example

import {
  analyzeEmail,
  generateCompatibilityScore,
  generateFixPrompt,
} from "@emailens/engine";

const warnings = analyzeEmail(html);
const scores = generateCompatibilityScore(warnings);

const prompt = generateFixPrompt({
  originalHtml: html,
  warnings,
  scores,
  scope: "all",
  format: "html",
});

// Send `prompt` to Claude, GPT, or any LLM to get a fixed version

Scoped to a single client

const prompt = generateFixPrompt({
  originalHtml: html,
  warnings,
  scores,
  scope: "current",
  selectedClientId: "outlook-windows-legacy",
  format: "html",
});

This generates a focused prompt with only Outlook Classic (Word engine) issues and fixes.

Framework-specific prompts

When format is set to "jsx", "mjml", or "maizzle", the generated prompt includes framework-specific instructions. For example, with format: "jsx" the prompt tells the LLM to use React Email components (Row, Column, Font, etc.) rather than raw HTML tables.

const prompt = generateFixPrompt({
  originalHtml: jsxSource,
  warnings,
  scores,
  scope: "all",
  format: "jsx",
});
// Prompt includes: "Use React Email components..."

Use with the MCP server

The MCP server's preview_email tool returns data in a format that pairs well with generateFixPrompt. After previewing an email in Claude, you can ask Claude to fix the issues and it will have all the context it needs.

On this page