1. Purpose & LLM Regression Risks
In continuous software development, modifying an application component requires executing regression test suites to guarantee existing functionality remains uncompromised. In LLM-powered applications, system prompt adjustments, few-shot exemplar additions, or model upgrades (e.g. migrating from GPT-4o to GPT-4o-mini, or Claude 3 Opus to 3.5 Sonnet) frequently introduce unexpected behavioral regressions:
- Schema Drift: The candidate prompt introduces conversational pleasantries (e.g. "Sure! Here is your requested JSON:") that cause strict JSON deserializers to throw parsing exceptions.
- Token Inflation & Latency Spikes: The new prompt doubles output length without improving factual accuracy, driving up API bills and degrading Time to First Token (TTFT).
- Instruction Drift: Rephrasing one section of a prompt inadvertently relaxes negative constraints elsewhere, introducing subtle compliance or security risks.
2. How to Use the Diff Tool
- Paste Baseline: Enter your verified production output or historical golden standard into the left textarea.
- Paste Candidate: Enter the output generated by your updated prompt or newer model checkpoint into the right textarea.
- Or Test Presets: Click Sample: JSON Output Drift or Sample: Prose Refinement.
- Run Comparison: Click Compare Outputs. The diff engine tokenizes both texts, calculates Jaccard word similarity, computes net character delta, and generates an inline visual diff.
- Inspect Changes: Green highlighted blocks represent additions; red strikethroughs indicate deletions. Click Copy JSON Report to log the diff telemetry into your CI/CD test artifacts.
3. Reproducible Cases & Walkthrough
Case A: Subtle JSON Schema Key Renaming
{"status": "success", "code": 200, "data": {"user_id": "usr_9912"}}Candidate:
{"status": "success", "status_code": 200, "data": {"id": "usr_9912"}}
Diff Output: Highlights that "code" was renamed to "status_code" and "user_id" was mutated to "id". In production, this would cause catastrophic schema failure for downstream API clients expecting the legacy key names.
4. Methodology & Mathematical Scoring
The tool computes word-level set similarity and positional token alignment:
- Jaccard Word Similarity ($J$): Evaluates token overlap independent of sentence length: $$J(A, B) = \frac{|A \cap B|}{|A \cup B|}$$ where $A$ is the set of unique words in the baseline and $B$ is the set of words in the candidate.
- Length Delta ($\Delta L$): Tracks absolute character drift: $$\Delta L = \text{len}(Candidate) - \text{len}(Baseline)$$
- Token Delta ($\Delta T$): Segregates insertions ($+N$) from deletions ($-N$) to differentiate expansion from total semantic rewriting.
5. Scope & Syntactic Limitations
Methodology Notice: Syntactic vs Semantic Diffs
This utility performs fast, deterministic syntactic token diffing:
- A syntactic diff identifies word shifts and formatting alterations, but cannot judge whether a paraphrased answer has altered factual truth.
- For semantic evaluation, combine this visual diff with automated unit test assertions and structured LLM-as-a-judge pipelines.
6. Related Tools
- AI Evaluation Dataset Builder — Build structured golden test suites with assertion metrics.
- AI API Cost Calculator — Model the cost impact of token length inflation.
- AI Failure Test Library — Review test case
FAIL-003: Strict JSON Schema Adherence Drift.