Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:EvolvingLMMs Lab Lmms eval LLM Judge Prompt Templates

From Leeroopedia
Revision as of 12:31, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/EvolvingLMMs_Lab_Lmms_eval_LLM_Judge_Prompt_Templates.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Overview

This implementation provides standardized prompt templates for different types of LLM-based evaluation. These templates are carefully crafted to elicit consistent, structured responses from judge models, defining clear evaluation criteria and output formats for binary, comparative, and correctness evaluations.

File Location

/tmp/kapso_repo_sslb_59s/lmms_eval/llm_judge/prompt.py (68 lines)

Related Principle

LLM as Judge

Dependencies

None - this module contains only string constants

Core Components

BINARY_JUDGE_PROMPT

Template for binary correctness evaluation (correct/incorrect).

Template Variables:

  • {positive}: Symbol for correct answers (e.g., "1", "Yes")
  • {negative}: Symbol for incorrect answers (e.g., "0", "No")
  • {question}: The question being evaluated
  • {answer}: Ground truth answer
  • {prediction}: Model's predicted answer

Structure:

You are a strict evaluator assessing answer correctness. You must output {positive}
for fully correct answers and {negative} for any other case.

# Input
Question:
```
{question}
```
Ground Truth Answer:
```
{answer}
```
Model Prediction:
```
{prediction}
```

# Evaluation Rules
- The model prediction may contain the reasoning process, you should spot the final answer from it.
- For multiple-choice questions: Score {positive} if the predicted answer matches the ground truth answer, it can be directly in option letters or the content of the options.
- For open-ended questions:
  * Score {positive} if the prediction matches the answer semantically, it can be in different format.
  * Score {negative} for partially correct answers or answers with extra incorrect information, even if the reasoning process is correct.
- Ignore minor differences in formatting, capitalization, or spacing since the model may explain in a different way.
- Treat numerical answers as correct if they match within reasonable precision
- For questions requiring units, both value and unit must be correct

# Strict Output format
{positive} or {negative}

Key Evaluation Principles:

  • Strict correctness: Partially correct answers are marked incorrect
  • Semantic matching: Handles format variations
  • Multiple-choice support: Matches both option letters and content
  • Reasoning extraction: Identifies final answer from reasoning chain
  • Numerical tolerance: Reasonable precision matching
  • Unit awareness: Both value and unit must be correct

Output Formats:

  • Binary (0/1): positive="1", negative="0"
  • Yes/No: positive="Yes", negative="No"

Use Cases:

  • Question answering tasks
  • Multiple-choice evaluation
  • Mathematical problem verification
  • Factual correctness checking

COMPARATIVE_JUDGE_PROMPT

Template for comparing two responses to the same question.

Template Variables:

  • {min_score}: Minimum score in range
  • {max_score}: Maximum score in range
  • {question}: The question both assistants answered
  • {context_section}: Optional context (formatted as "[Context]\n{context}\n\n" or empty)
  • {response1}: First assistant's response
  • {response2}: Second assistant's response
  • {evaluation_instruction}: Custom instructions or default scoring guidance

Structure:

We would like to request your feedback on the performance of two AI assistants
in response to the user question displayed above.
Please rate the helpfulness, relevance, accuracy, level of details of their responses.
Each assistant receives an overall score on a scale of {min_score} to {max_score},
where a higher score indicates better overall performance.
Please first output a single line containing only two values indicating the scores
for Assistant 1 and 2, respectively. The two scores are separated by a space.
In the subsequent line, please provide a comprehensive explanation of your evaluation,
avoiding any potential bias and ensuring that the order in which the responses were
presented does not affect your judgment.

[Question]
{question}

{context_section}

[Assistant 1]
{response1}
[End of Assistant 1]

[Assistant 2]
{response2}
[End of Assistant 2]

[System]
{evaluation_instruction}

Evaluation Dimensions:

  • Helpfulness
  • Relevance
  • Accuracy
  • Level of detail

Output Format:

  • First line: Two space-separated scores (e.g., "8 7")
  • Following lines: Explanation of evaluation

Bias Mitigation:

  • Explicit instruction to avoid order bias
  • Request for comprehensive explanation
  • Encourages independent evaluation of each response

Use Cases:

  • Model comparison benchmarks
  • A/B testing of model outputs
  • Response quality ranking
  • Multi-model evaluation

CORRECTNESS_JUDGE_PROMPT

Template for evaluating mathematical or semantic correctness while ignoring formatting differences.

Template Variables:

  • {positive}: Symbol for correct (e.g., "Yes", "1")
  • {negative}: Symbol for incorrect (e.g., "No", "0")
  • {question}: The question being evaluated
  • {answer}: Correct answer
  • {prediction}: Solution to evaluate

Structure:

You are given a question, the solution and the correct answer. Please determine
if the solution matches the correct answer.
Focus only on the mathematical or semantic correctness of the content. Ignore any
differences in formatting, such as LaTeX syntax, symbols, styles, or additional
wrappers (e.g., \boxed, $...$, or similar). Compare only the core mathematical
or textual meaning of the solution and the correct answer.
The process or reasoning leading to the Solution is irrelevant, ONLY the correctness
of the result matters.
Return only "{positive}" if the solution is correct or "{negative}" if it is incorrect.
Only return "{positive}" or "{negative}" with no additional text or formatting.

Question:
{question}
--------------------------------
Correct Answer:
{answer}
--------------------------------
Solution:
{prediction}
--------------------------------

Key Principles:

  • Format-agnostic: Ignores LaTeX, markdown, wrapper differences
  • Content-focused: Only evaluates semantic/mathematical correctness
  • Result-only: Ignores reasoning process, only checks final result
  • Strict output: Returns only positive/negative symbol

Ignored Elements:

  • LaTeX syntax variations (e.g., \boxed{}, $...$)
  • Formatting symbols and styles
  • Whitespace and line breaks
  • Presentation wrappers

Use Cases:

  • Mathematical problem evaluation
  • LaTeX-formatted answer checking
  • Cross-format answer verification
  • Reasoning task evaluation (when only final answer matters)

Usage Patterns

Direct Template Usage

from lmms_eval.llm_judge.prompt import BINARY_JUDGE_PROMPT

# Format for 0/1 output
prompt = BINARY_JUDGE_PROMPT.format(
    positive="1",
    negative="0",
    question="What is the capital of France?",
    answer="Paris",
    prediction="The capital of France is Paris."
)

Via JudgePromptBuilder

These templates are typically used through the JudgePromptBuilder utility:

from lmms_eval.llm_judge.utils import JudgePromptBuilder

# Binary evaluation
prompt = JudgePromptBuilder.build_binary_prompt(
    question="What is 2+2?",
    answer="4",
    prediction="Four",
    output_format="0/1"
)

# Comparative evaluation
prompt = JudgePromptBuilder.build_comparative_prompt(
    question="Explain photosynthesis",
    response1="Response A...",
    response2="Response B...",
    score_range=(1, 10)
)

# Correctness evaluation
prompt = JudgePromptBuilder.build_correctness_prompt(
    question="Solve: x^2 = 16",
    answer="x = 4 or x = -4",
    prediction="\\boxed{x = \pm 4}",
    output_format="yes/no"
)

Custom Prompts

All evaluation methods accept custom prompts as an override:

custom_prompt = """
Evaluate if the prediction correctly answers the question.
Question: {question}
Answer: {answer}
Prediction: {prediction}
Return 1 for correct, 0 for incorrect.
"""

result = judge.evaluate_binary(
    question="What is H2O?",
    answer="Water",
    prediction="Water molecule",
    custom_prompt=custom_prompt
)

Design Considerations

Clarity and Specificity

Templates use explicit formatting (backticks, section headers, delimiters) to clearly separate inputs and instructions, reducing ambiguity for the judge model.

Output Format Constraints

Templates specify exact output formats to enable reliable parsing:

  • Binary: Single symbol (0, 1, Yes, No)
  • Comparative: Space-separated scores on first line
  • Explanation following structured output

Evaluation Criteria

Templates explicitly list evaluation rules and edge cases:

  • How to handle reasoning vs. final answer
  • Multiple-choice matching rules
  • Numerical precision tolerance
  • Unit requirement handling

Bias Mitigation

Comparative template includes explicit instructions to:

  • Avoid position bias
  • Evaluate independently
  • Provide detailed reasoning
  • Use objective criteria

Format Robustness

Correctness template emphasizes format-agnostic evaluation:

  • Ignores LaTeX wrappers
  • Focuses on semantic content
  • Handles various notation styles

Template Evolution

These templates are the result of iterative refinement to:

  • Reduce false positives/negatives
  • Handle edge cases (formatting, units, reasoning chains)
  • Improve output consistency
  • Minimize bias in comparative evaluation

Future improvements may include:

  • Domain-specific templates (code, math, reasoning)
  • Multi-turn evaluation templates
  • Confidence score templates
  • Explanation quality templates

Related Implementations

Best Practices

Template Selection

  • BINARY_JUDGE_PROMPT: Use for question answering, multiple-choice, factual verification
  • COMPARATIVE_JUDGE_PROMPT: Use for model comparison, A/B testing, ranking
  • CORRECTNESS_JUDGE_PROMPT: Use for math problems, formatted answers, when format varies

Output Format

  • Use "0/1" for programmatic processing
  • Use "yes/no" for human-readable outputs
  • Ensure output_format matches parsing logic

Custom Prompts

  • Start with standard templates and modify for specific needs
  • Keep output format constraints for reliable parsing
  • Test with edge cases before production use
  • Document modifications for future reference

Context Handling

  • Include context only when necessary for evaluation
  • Format context clearly to avoid confusion
  • Consider context length limits

Prompt Engineering Insights

Instruction Placement

  • Critical instructions (output format) placed both at start and end
  • Examples and edge cases listed explicitly
  • Section headers improve structure parsing

Tone and Language

  • Authoritative tone ("You must output...")
  • Explicit rather than implicit rules
  • Clear definition of edge cases

Formatting Conventions

  • Code blocks (```) separate inputs from instructions
  • Section headers ([Question], [Assistant 1]) provide clear boundaries
  • Delimiters (---) visually separate content

Bias Prevention

  • Explicit "avoid bias" instructions
  • Request for explanation increases accountability
  • Randomizable response order (handled by caller)

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment