Skip to content
Goal: Proficient✓ Sources verified 2026-11-24EvalLLM-as-judgeLangfuse

Prompt Versioning and Evaluation ​

The hidden requirement of "traceability": for any result you can say which prompt version and which model produced it, and after changing a prompt you can prove nothing got worse.

Core concepts ​

  • Prompts are code: prompt templates get version numbers and live in Git or a prompt management platform. Every call records prompt_name@version.
  • Eval set: a set of samples with "reference answers" or "grading criteria". It is the only trustworthy basis for changing a prompt or switching models.
  • Offline evals vs online monitoring: offline evals run before release; online you watch the human correction rate, validation failure rate and user feedback.
  • Grading methods: exact match / rules (per field), semantic similarity, LLM-as-judge, human scoring.

How it works ​

Why you must have an eval set ​

LLM output is probabilistic. Changing one sentence of a prompt might fix 3 cases and break 5 others. Without an eval set, all you have is "it feels better".

Known biases of LLM-as-judge ​

The paper Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena (Zheng et al., 2023) summarizes:

  • Position bias: in pairwise comparison the judge favors the answer in a particular position → judge twice with the order swapped.
  • Verbosity bias: it prefers longer answers → state explicitly in the rubric that length earns no points.
  • Self-enhancement bias: it prefers answers generated by the same model → use a different model as the judge.
  • Conclusion: LLM judges can agree with humans at a fairly high rate, but they need human spot checks for calibration.

In practice ​

Field-level evaluation for extraction tasks (the most practical and cheapest) ​

python
from dataclasses import dataclass

@dataclass
class Case:
    doc_id: str
    expected: dict      # human-labelled reference answer

def score(pred: dict, exp: dict) -> dict:
    fields = exp.keys()
    hit = {f: normalize(pred.get(f)) == normalize(exp[f]) for f in fields}
    return {"field_acc": sum(hit.values()) / len(fields), "miss": [f for f, ok in hit.items() if not ok]}

async def run_eval(cases: list[Case], prompt_version: str, model: str):
    rows = [score(await extract(c.doc_id, prompt_version, model), c.expected) for c in cases]
    return {"prompt": prompt_version, "model": model,
            "field_acc": sum(r["field_acc"] for r in rows) / len(rows)}

Output a comparison table: prompt v2 + model A vs prompt v3 + model A vs prompt v3 + model B, and look per field at what improved and what regressed.

Minimal versioning practice ​

prompts/
  contract_extract/
    v1.md
    v2.md
    v3.md        ← the live version is set in config: CONTRACT_EXTRACT_PROMPT=v3
evals/
  contract_extract.jsonl   ← 30–100 labelled samples

Or use the Prompt Management feature of a platform such as Langfuse: manage versions and labels (e.g. production) on the platform, fetch by label at call time, and traces are linked to the version automatically.

Common pitfalls ​

  1. An eval set that is too small or too "clean": include real messy data such as scans, missing fields and malformed formats.
  2. Human corrections from production never flow back: results a human has corrected are the best new eval samples.
  3. Only looking at the overall score: the total stays the same but a key field (the amount) gets worse, which is far more serious. Look per field.
  4. Relying entirely on LLM-as-judge: do regular human spot checks and compute the judge's agreement rate with humans.

Common interview questions ​

  1. How do you prove a prompt change didn't make results worse?
  2. What biases does LLM-as-judge have? How do you mitigate them?
  3. How do you build an eval set? How many samples are enough?
  4. How do you detect prompt or model regressions in production?

How it relates to my projects ​

Sources ​

Vin Amory · AI development × content creation · Technical notes cite official docs in each page’s sources section