Inferensys

Prompt

Reference-Guided Precision and Recall Scoring Prompt Template

A practical prompt playbook for using Reference-Guided Precision and Recall Scoring Prompt Template in production AI workflows.
Developer doing prompt engineering on laptop, prompt variations visible on screen, casual coding session.
PROMPT PLAYBOOK

When to Use This Prompt

Define the job, reader, and constraints for the Reference-Guided Precision and Recall Scoring Prompt Template.

This prompt is for evaluation leads and AI engineers who need to move beyond 'looks good to me' when comparing a model's output against a known-correct reference answer. The job-to-be-done is automated, structured measurement of how much of the reference content the model captured (recall) and how much of the model's output was actually correct (precision), producing standard IR metrics adapted for LLM-generated text. The ideal user is someone maintaining a golden dataset of reference answers and building a regression gate that must fail a deployment when factual completeness or accuracy drops below a defined threshold. Required context includes the model's raw output, the reference answer, and an optional unit of analysis specification (token-level, fact-level, or entity-level).

Do not use this prompt when the reference answer is one of many valid interpretations, when the task is open-ended creative generation, or when you need a single holistic quality score rather than decomposed precision and recall metrics. This prompt is also inappropriate for evaluating outputs where the reference is a policy document or style guide rather than a factual answer—use a rubric-based or pairwise comparison prompt instead. If your evaluation requires numerical tolerance awareness (e.g., 'within 5% of 42.7'), use the Numerical Tolerance Evaluation prompt. If you need to detect contradictions specifically, pair this with the Contradiction Detection prompt rather than relying on precision/recall alone to catch safety-critical conflicts.

Before implementing this prompt, ensure you have a stable set of reference answers that represent ground truth for your domain. The prompt assumes the reference is authoritative and complete. If your reference answers are incomplete, your recall scores will be misleadingly high and your precision scores will penalize the model for adding correct information the reference missed. Start with a small calibration set of 20-30 examples where you've manually computed precision and recall to validate that the LLM judge's scores align with human judgment before scaling to your full regression suite.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Reference-Guided Precision and Recall Scoring Prompt delivers reliable, automatable evaluation—and where it introduces risk.

01

Good Fit: Regression Gates with a Golden Dataset

Use when: you have a stable set of reference answers and need to block prompt or model changes that cause factual regressions. Guardrail: version-lock your golden dataset and run this prompt as a required CI gate before any production deployment.

02

Good Fit: Measuring Factual Recall in Summarization

Use when: evaluating whether a summary captures all key facts from a source document. Guardrail: pre-extract key facts from the reference to use as the ground-truth fact list, rather than asking the judge to infer what counts as a key fact on each run.

03

Bad Fit: Open-Ended Creative Evaluation

Avoid when: judging quality dimensions like tone, style, or creativity where no single reference answer exists. Risk: the prompt will penalize valid stylistic variation as a recall failure. Guardrail: use a pairwise comparison or rubric-based judge instead for subjective quality dimensions.

04

Bad Fit: Single-Reference Truth in Ambiguous Domains

Avoid when: multiple factually correct answers exist and you only provide one reference. Risk: the prompt will mark correct alternative phrasings as false negatives, inflating the apparent error rate. Guardrail: provide multiple reference answers or use a semantic similarity judge that accepts paraphrases.

05

Required Input: Token-Level or Fact-Level Alignment Target

Risk: without clear instructions on whether to align at the token, span, or fact level, the judge will produce inconsistent scores across runs. Guardrail: explicitly define the alignment granularity in the prompt template and include examples of what counts as a match at that level.

06

Operational Risk: Threshold Drift Without Human Calibration

Risk: precision and recall thresholds set without human calibration will either pass bad outputs or block good ones. Guardrail: run a calibration batch with human-annotated scores, compute alignment between human and LLM judge, and set thresholds based on your tolerance for false positives versus false negatives in production.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable prompt template for computing precision, recall, and F1 scores by aligning model output against a reference answer at the token or fact level.

This template provides the core instruction set for an LLM judge tasked with evaluating a model's output against a known-correct reference. It is designed to be dropped directly into your evaluation harness. The prompt instructs the judge to decompose both the reference and the candidate output into discrete, checkable units—either tokens or atomic facts—before computing standard information retrieval metrics. Use this when you have a golden dataset and need automated, repeatable scoring that goes beyond simple string matching to capture semantic equivalence.

text
You are an evaluation judge. Your task is to compare a model's output against a reference answer and compute precision, recall, and F1 scores.

# INPUTS
## Reference Answer (Ground Truth)
[REFERENCE]

## Model Output to Evaluate
[CANDIDATE]

## Decomposition Strategy
[STRATEGY: token | fact | entity]

## Output Schema
You must respond with a single JSON object conforming to this schema:
{
  "precision": <float 0.0-1.0>,
  "recall": <float 0.0-1.0>,
  "f1_score": <float 0.0-1.0>,
  "reference_units": ["<extracted unit 1>", "<extracted unit 2>", ...],
  "candidate_units": ["<extracted unit 1>", "<extracted unit 2>", ...],
  "matched_units": ["<unit matched in both>", ...],
  "missed_units": ["<unit in reference but not in candidate>", ...],
  "extraneous_units": ["<unit in candidate but not in reference>", ...],
  "justification": "<brief explanation of the scoring decision>"
}

# CONSTRAINTS
- Decompose the reference and candidate into discrete units based on the specified [STRATEGY].
- For 'token' strategy: split on whitespace and punctuation, normalize case.
- For 'fact' strategy: extract standalone, verifiable atomic claims.
- For 'entity' strategy: extract named entities (people, places, organizations, dates, quantities).
- A candidate unit matches a reference unit if they are semantically equivalent, not just string-identical.
- Precision = (number of matched units) / (total number of candidate units).
- Recall = (number of matched units) / (total number of reference units).
- F1 = 2 * (Precision * Recall) / (Precision + Recall). If both are 0, F1 is 0.
- Do not include any text outside the JSON object.

To adapt this template, replace the [REFERENCE] and [CANDIDATE] placeholders with your data at runtime. The [STRATEGY] placeholder should be set to token, fact, or entity depending on the granularity you need. For most knowledge-work evaluations, fact provides the best signal-to-noise ratio. For code or structured data, token may be more appropriate. The output schema is strict JSON, which allows your harness to parse the score and the detailed unit lists directly. The justification field is critical for debugging scoring disagreements and should be logged alongside the metrics. Before deploying this into a production gate, run it against a calibration set of 20-50 examples scored by a human to verify that the LLM judge's precision and recall values align with your team's expectations for semantic equivalence.

IMPLEMENTATION TABLE

Prompt Variables

Required inputs for the Reference-Guided Precision and Recall Scoring prompt. Each placeholder must be populated before the prompt is sent to the model. Validation notes describe how to verify the input is well-formed before execution.

PlaceholderPurposeExampleValidation Notes

[MODEL_OUTPUT]

The generated text to evaluate against the reference

The capital of France is Paris, a city known for its cuisine.

Must be a non-empty string. Truncate if longer than the model's context window minus prompt overhead. Null or whitespace-only strings should abort evaluation.

[REFERENCE_ANSWER]

The ground-truth or known-correct answer for comparison

Paris is the capital of France.

Must be a non-empty string. Verify source provenance before use. If multiple valid references exist, use the multi-reference variant of this prompt instead.

[GRANULARITY]

Controls whether scoring operates at token, fact, or sentence level

fact

Must be one of: token, fact, sentence. Token-level is strictest and most sensitive to phrasing differences. Fact-level requires the model to decompose both texts into atomic claims first.

[SCORE_THRESHOLD]

Minimum F1 score required for a pass in production gates

0.75

Must be a float between 0.0 and 1.0. Values below 0.6 are lenient; above 0.9 are strict. Document the threshold rationale in your eval config. Null allowed if only raw scores are needed.

[OUTPUT_SCHEMA]

Expected structure for the evaluation result

{"precision": float, "recall": float, "f1": float, "alignment": [...]}

Must be a valid JSON Schema or example object. The prompt will instruct the model to return JSON conforming to this shape. Validate with a JSON Schema validator before sending.

[DOMAIN_CONTEXT]

Optional domain-specific terminology or entity normalization rules

Medical: 'MI' and 'myocardial infarction' are equivalent.

Null allowed. If provided, must be a string under 500 tokens. Use this to prevent false negatives from synonym mismatch in specialized domains. Test with a small sample before full runs.

[FEW_SHOT_EXAMPLES]

Optional input-output pairs demonstrating desired scoring behavior

[{"input": {...}, "output": {...}}]

Null allowed. If provided, must be an array of 1-3 objects, each with model_output, reference_answer, and expected_scores fields. Validate each example's expected scores against a human baseline before inclusion.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the precision/recall scoring prompt into a production evaluation pipeline with validation, retries, and gating logic.

The Reference-Guided Precision and Recall Scoring Prompt Template is designed to be called programmatically as a scoring function within an evaluation harness, not as a one-off chat interaction. The prompt expects a model output, a reference answer, and a scoring configuration (token-level or fact-level alignment, threshold preferences). The harness is responsible for assembling these inputs, invoking the LLM judge, parsing the structured score response, and routing the result to your evaluation database or CI/CD gate. Treat this prompt as a deterministic scorer: same inputs should produce consistent precision, recall, and F1 scores, though minor LLM variance is expected. Log the raw judge response alongside the parsed scores for auditability.

Validation and Retry Logic: The prompt instructs the judge to return a JSON object with precision, recall, f1, and alignment_details fields. Your harness must validate this schema before accepting the score. If the response fails JSON parsing or is missing required fields, implement a retry with the same prompt but append the malformed response and a terse correction instruction: Your previous response was not valid JSON or was missing required fields. Return ONLY the JSON object with precision, recall, f1, and alignment_details. Set a maximum of 2 retries. If validation still fails after retries, log the failure, mark the evaluation as SCORING_ERROR, and escalate for human review rather than silently assigning a default score. For high-stakes evaluation pipelines (regression gates, model release decisions), require a human to spot-check a random sample of scored pairs, especially those near your F1 threshold boundary.

Model Choice and Configuration: Use a model with strong instruction-following and structured output capabilities for the judge role. Temperature should be set low (0.0–0.2) to maximize scoring consistency across repeated runs. If your evaluation platform supports it, pin the judge model version to avoid score drift from silent model updates. For cost-sensitive pipelines running thousands of evaluations, consider using a smaller, fine-tuned judge model that has been calibrated against human precision/recall annotations on your domain data. The prompt template includes a [CONSTRAINTS] placeholder where you can inject domain-specific scoring rules, such as 'Treat synonyms as matches' or 'Penalize extra information that contradicts the reference.'

Integration with Evaluation Pipelines: Wire this prompt into your existing evaluation framework (e.g., Braintrust, LangSmith, custom eval harness) as a scorer function. The scorer should accept (output, reference, config) and return {precision, recall, f1, alignment_details, raw_response}. Store all scores in your evaluation database with metadata: prompt version, judge model version, timestamp, and the raw judge response. For CI/CD gating, define thresholds in your pipeline configuration—for example, f1 >= 0.8 for automated pass, f1 < 0.6 for automated fail, and 0.6 <= f1 < 0.8 for human review. These thresholds should be calibrated against your domain's tolerance for false positives versus false negatives. Do not use the same threshold for a chatbot's factual accuracy as you would for a medical coding system.

Failure Modes to Monitor: The most common production failure is the judge hallucinating alignment spans that don't exist in either text. Mitigate this by including span-grounding instructions in the prompt (already present in the template) and by periodically auditing alignment_details against the source texts. A second failure mode is score inflation on short outputs where precision appears perfect because the model said very little. Consider adding a coverage or completeness check alongside precision/recall for outputs that are suspiciously brief. A third failure mode is judge bias toward the reference's phrasing style rather than semantic content. If you observe this, add explicit instructions in [CONSTRAINTS] to prioritize meaning over surface-form matching. Log all three metrics (precision, recall, F1) separately—a high F1 can mask a precision-recall trade-off that matters for your use case.

IMPLEMENTATION TABLE

Expected Output Contract

Define the exact shape of the evaluation report. Use this contract to validate the LLM judge's output before accepting scores into your pipeline.

Field or ElementType or FormatRequiredValidation Rule

precision_score

float (0.0–1.0)

Must be a number between 0 and 1 inclusive. Parse as float and check range.

recall_score

float (0.0–1.0)

Must be a number between 0 and 1 inclusive. Parse as float and check range.

f1_score

float (0.0–1.0)

Must equal 2 * (precision * recall) / (precision + recall) within 0.01 tolerance. Recalculate and compare.

matched_facts

array of strings

Each string must be a non-empty fact from [MODEL_OUTPUT] that aligns to [REFERENCE_ANSWER]. Empty array is valid if no matches.

missed_facts

array of strings

Each string must be a non-empty fact present in [REFERENCE_ANSWER] but absent from [MODEL_OUTPUT]. Empty array is valid if recall is 1.0.

spurious_facts

array of strings

Each string must be a non-empty fact present in [MODEL_OUTPUT] but not supported by [REFERENCE_ANSWER]. Empty array is valid if precision is 1.0.

justification

string

Must be non-empty and reference specific facts from both [MODEL_OUTPUT] and [REFERENCE_ANSWER]. Check for hallucinated citations.

confidence

float (0.0–1.0) or null

If present, must be a number between 0 and 1. If null, downstream systems should treat as unscored. No default assumption.

PRACTICAL GUARDRAILS

Common Failure Modes

Reference-guided scoring breaks when the reference is incomplete, the alignment is fuzzy, or the metric hides more than it reveals. These cards cover the most common production failure patterns and how to guard against them.

01

Over-Penalizing Paraphrases

What to watch: Token-overlap metrics flag semantically equivalent answers as false negatives because the model used different words. Precision and recall scores collapse when synonyms, reordering, or grammatical restructuring are treated as mismatches. Guardrail: Add a semantic similarity pre-check before token-level alignment. Use embedding cosine similarity with a calibrated threshold (typically 0.85–0.92) to distinguish meaning-preserving rewrites from factual deviations before computing precision/recall.

02

Reference Incompleteness Masking Recall Failures

What to watch: A sparse or incomplete reference answer makes recall look artificially high because there are fewer facts to miss. The model can omit critical information and still score well if the reference didn't include it. Guardrail: Audit reference coverage before scoring. Run a completeness check on each reference answer against source material. Flag references with coverage below 80% and exclude them from recall gates or weight them lower in aggregate metrics.

03

Entity Normalization Mismatches

What to watch: Precision drops sharply when the model outputs 'US' and the reference says 'United States', or 'Q3 2024' versus 'third quarter 2024'. String-level comparison treats these as misses even though they're factually identical. Guardrail: Preprocess both model output and reference through an entity normalization layer. Resolve dates, currencies, abbreviations, and known entity aliases to canonical forms before computing alignment. Log normalization decisions for audit.

04

Threshold Selection Without Business Context

What to watch: Teams pick a single F1 threshold (e.g., 0.80) without considering whether precision or recall matters more for their use case. A customer-facing summary needs high precision to avoid misinformation; a search pipeline needs high recall to avoid missing relevant results. Guardrail: Define separate precision and recall gates based on failure cost. For high-risk domains, set precision ≥ 0.95 with recall ≥ 0.70. For recall-critical workflows, invert. Document the rationale and review thresholds quarterly against production incident data.

05

Fact Granularity Mismatch

What to watch: The prompt extracts facts at a different granularity than the reference was written at—sentence-level facts versus clause-level facts, or atomic claims versus composite statements. Alignment becomes noisy and scores become uninterpretable. Guardrail: Define and enforce a consistent fact decomposition schema before scoring. Specify whether facts are atomic claims, sentences, or spans. Use the same decomposition prompt for both model output and reference. Validate inter-annotator agreement on fact boundaries during calibration.

06

Score Drift Across Reference Batches

What to watch: Precision and recall thresholds that worked for one reference dataset produce different pass/fail rates on another batch because reference quality, length, or domain varies. Gates become unreliable and teams lose trust in automated evaluation. Guardrail: Calibrate thresholds per reference batch using a small human-annotated sample. Run a calibration pass of 50–100 examples with human judgments, compute optimal thresholds per batch, and monitor score distributions for drift. Trigger recalibration when distribution KS statistic exceeds 0.15.

IMPLEMENTATION TABLE

Evaluation Rubric

How to test output quality before shipping. Use this rubric to score the LLM judge's precision and recall assessment against a reference, ensuring the evaluation itself is trustworthy before it gates a production pipeline.

CriterionPass StandardFailure SignalTest Method

Token-level precision alignment

Precision score is within 0.05 of a human-annotated gold score for the same [OUTPUT] and [REFERENCE] pair

LLM judge precision deviates by more than 0.10 from human score on 3 or more samples in a 20-sample calibration set

Run judge on 20 pre-annotated pairs; compute MAE between LLM precision and human precision

Token-level recall alignment

Recall score is within 0.05 of a human-annotated gold score for the same [OUTPUT] and [REFERENCE] pair

LLM judge recall deviates by more than 0.10 from human score on 3 or more samples in a 20-sample calibration set

Run judge on 20 pre-annotated pairs; compute MAE between LLM recall and human recall

F1 score consistency

F1 score computed from judge precision and recall matches human-derived F1 within 0.05

Judge F1 and human F1 differ by more than 0.10 on any sample where human F1 is below 0.70

Derive F1 from judge precision/recall; compare to human F1 per sample; flag threshold misses

Fact-level granularity correctness

Judge identifies the same number of distinct facts as human annotator within ±1 fact for outputs under 200 tokens

Judge reports 0 facts when human annotator found 3 or more; or judge reports more than double the human fact count

Count fact spans in judge output; compare to human fact count on 10 short-output samples

Overlap classification accuracy

Judge correctly classifies each token or fact as true-positive, false-positive, or false-negative with 90% agreement against human labels

Agreement drops below 80% on any single overlap category across a 20-sample set

Confusion matrix per category; require per-category F1 >= 0.85 against human labels

Threshold gate reliability

Judge correctly passes outputs above [PASS_THRESHOLD] and fails outputs below [FAIL_THRESHOLD] with 95% agreement against human gate decisions

Judge passes an output that human reviewer marked as containing a critical factual error

Run 30 borderline samples through judge; compare binary pass/fail to human decisions; require <= 1 false pass

Edge case: empty reference handling

Judge returns precision=null, recall=null, F1=null and an explicit note when [REFERENCE] is empty or missing

Judge returns a numeric score or hallucinates reference content when [REFERENCE] is an empty string

Provide empty [REFERENCE] in 5 test cases; verify null output and presence of abstention note

Edge case: irrelevant output handling

Judge returns precision=0.0, recall=0.0, F1=0.0 when [OUTPUT] contains no information relevant to [REFERENCE]

Judge assigns non-zero recall to an output that is entirely off-topic or in a different language

Provide 5 outputs with unrelated content; verify zero scores and correct overlap classification

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a single reference and lighter validation. Drop the F1 threshold gating and focus on getting directional precision/recall numbers. Replace structured JSON output with a simple markdown table for faster iteration.

code
[SYSTEM]: You are an evaluation judge. Compare the [MODEL_OUTPUT] against the [REFERENCE_ANSWER]. Return precision, recall, and F1 as a markdown table with a one-sentence justification.

Watch for

  • Token-level overlap masquerading as factual alignment
  • No handling of partial credit or paraphrased correct answers
  • Missing null-reference handling when the reference is empty
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.