DevTools Logo

Prompt Diff Comparator

Prompt Diff Comparator

Compare prompt versions and map expected A/B outputs locally

Version A

Version B

A/B output matrix

InputExpected AExpected B

Examples

Added placeholder

Input
comparePlaceholders("Summarize the report.", "Summarize the report for {audience}.")
Output
{ added: ["audience"], removed: [], shared: [] }

The v2-only {audience} variable surfaces as added so the caller knows to supply it.

Brace-style equivalence

Input
comparePlaceholders("Hello {name}", "Hello {{name}}")
Output
{ added: [], removed: [], shared: ["name"] }

Single- and double-brace spellings normalize to the same variable name.

About this tool

Prompt Diff Comparator diffs two prompt versions with comparePromptVersions(versionA, versionB, rows): diffPromptLines runs a line-oriented LCS diff with stable oldLine/newLine numbers, comparePlaceholders diffs added/removed/shared placeholders, analyzePrompt reports characters, lines, chars/4 tokens, instruction counts, and placeholders, and validateABMatrix flags blank input/outputA/outputB cells.

Placeholders normalize across syntaxes: extractPlaceholders finds {var}, {{ var }}, and $VAR forms and returns one sorted unique list, so {name} and {{name}} compare as the same variable. Instruction counting is deterministic — short imperative sentences starting with verbs like summarize, explain, list, or return.

Edge behavior is well-defined: identical prompts produce an all-equal diff with zero added/removed lines, an empty v1 marks every v2 line added, empty prompts analyze to zeros, and blank matrix cells are reported as { row, column } entries without throwing.

How to use this tool

  1. Paste both versions

    Put v1 on the left and v2 on the right; the LCS diff marks equal, added, and removed lines with stable numbers.

  2. Check placeholder drift

    Read added/removed/shared to catch renamed or dropped {vars} before a template breaks in production.

  3. Compare metrics

    Use characters, estimatedTokens, and instruction counts per version to confirm the rewrite stayed in budget.

  4. Validate the A/B matrix

    Add input/outputA/outputB rows and fix any missingCells entries so every test case is runnable.

Use cases

Reviewing prompt pull requests

Show line-level additions and removals plus placeholder drift when a teammate edits a system prompt.

Catching renamed template variables

Detect a {tone} → {style} rename before the serving path passes the old variable and renders blank.

Sizing prompt rewrites

Compare per-version token and instruction counts to prove a shorter rewrite kept the same directives.

Common mistakes

Mistake:Treating {var} and {{var}} as different variables.

Fix:Both spellings extract to the same name — unify on one style for readability, not correctness.

Mistake:Ignoring blank A/B matrix cells.

Fix:Whitespace-only input/outputA/outputB counts as missing; fill or delete the row before running the comparison.

Mistake:Reading the diff as word-level.

Fix:The diff is line-oriented LCS — split long paragraphs into lines to get precise change locations.

Frequently asked questions

What does this tool do?

It diffs two prompt versions with comparePromptVersions: an LCS line diff, {var}/{{var}}/$VAR placeholder drift (added/removed/shared), per-version token and instruction metrics, plus blank-cell detection for the A/B input/output matrix.

Are {var} and {{var}} treated as different?

No. Both spellings extract to the same name, so Hello {name} versus Hello {{name}} reports zero added and zero removed with name shared.

Is my prompt data uploaded or stored?

No. Diffing, placeholder extraction, and metrics run entirely in your browser.

What does an empty v1 or a missing matrix cell mean?

An empty v1 marks every v2 line added with null oldLine numbers. A whitespace-only matrix cell reports as { row, column } in missingCells — fill it before running the comparison.

References & standards