DeepEvaldeepeval 4.2 ยท Python 3.9+
0%
1
Curious builder0 XP earned ยท 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
23 small wins to finish your pathNext lesson โ†’

Real LLM judge: using GPT instead of the stand-in

Every score in this course came from a judge that compares words. That was the point: the whole course runs with no account. Here is the line that swaps it for a real model.

python
from pretend_judge import PretendJudge

relevancy = AnswerRelevancyMetric(model=PretendJudge())
python
relevancy = AnswerRelevancyMetric(model="gpt-4.1")

That is the change. The model argument takes an OpenAI model name, and DeepEval builds the judge for you. The metric, the test case, the threshold and the report are all unchanged.

bash
export OPENAI_API_KEY="sk-..."

The key goes in the environment, not in your code. DeepEval also reads a .env file if there is one.

No output on this page
Every other page in this course shows what the code printed. This one cannot: running it costs money and needs a key, and a made-up score would be worth nothing. This is the one lesson you have to run yourself.

What changes when the judge is real

  • Scores stop being repeatable. The same test case can score 0.8 and then 0.7. Thresholds need a little room, and a metric that flips around is a metric to look at again.
  • It reads meaning. The refund answer that scored 0.33 in lesson 18 scores properly, because a real judge understands that the answer answers the question.
  • It costs time and money. Every metric is one or more model calls per test case. The cache, -c from lesson 20, stops you paying twice for the same thing.
  • Your criteria matter more. A vague G-Eval criterion gives a vague score, and the evaluation_steps from lesson 9 are how you tighten it.

Other providers

The same argument takes any model wrapped as a DeepEvalBaseLLM, which is exactly what you built in lesson 8. DeepEval ships wrappers for Azure OpenAI, Anthropic, Gemini, Ollama and LiteLLM, so a local model through Ollama is a reasonable middle ground: no bill, and a judge that reads meaning.

Keep the stand-in judge in the repository even so. It is the fastest way to check that a new metric is wired up correctly before you spend anything on it.

Try it yourself
  • Run lesson 14's padded answer with a real judge and compare the two scores.
  • Swap the model for a local one through Ollama and run the same test file.

Little by little, you're building something great.