judge
The judge: decides whether the bot did what a scenario asks.
A judge answers a natural-language criterion, an eval: on a scripted
turn or a simulation’s success: and metrics, about the conversation it
was given. It keeps that conversation, fed as it happens: the user’s turns,
the bot’s replies, and the tool calls the bot makes. A terse reply (“That’s
four”) is judged in context, and a whole run is judged over the same record.
How it decides:
Every question goes to a BaseClassifier,
which answers with an option and a probability for each of the options it
was offered. Two classifiers come with Pipecat:
LLMClassifier, over any Pipecat LLM service withrun_inference(): OpenAI, Ollama, Together, and others. This is the default.JevClassifier, over TypeSafe’s Jev, a hosted classification model. Jev answers in a few hundred milliseconds, costs little, and its probabilities are calibrated, so a scenario can tell a sure verdict from a close call.
A scenario picks one in its judge.eval: block. All the options:
judge:
eval:
service: ollama # the LLM that classifies (the default), or
model: gemma4:12b # factory: a dotted path to a callable that
# takes this block and returns a classifier
explainer: # optional; the LLM that gives reasons
service: ollama # (the judging LLM if omitted, the default
model: gemma4:12b # LLM for a factory's classifier; none if
# set to false)
explain_below: 0.75 # optional; see "The explainer" below
allow_continue: true # optional; false judges a reply yes or no only
A factory may also return an LLM service, which the judge then classifies with.
What the judge asks:
The harness asks three kinds of question, and each is one classifier call:
A reply, for an
eval:on a scripted turn. The state holds the conversation so far and, separately, the bot’s latest reply. The answers areyes(the reply meets the criterion),no(it’s a real answer that doesn’t, including a reply that waits for the user instead), andcontinue(the bot is still working toward its answer: it only greeted, said it’s checking, or the reply is still arriving). Oncontinuethe harness waits for more of the reply and asks again. A suite whose judged replies are all final answers, with nothing for the bot to fetch first, setsallow_continue: false, and a reply is then yes or no; a reply that is still arriving is still judged again as more of it comes.A function call, for an
eval:on afunction_call. The state holds the call’s name and arguments and the conversation as context. The answer is yes or no.A whole simulation, at the end of the run. The goal is one yes/no question over the whole conversation, tool calls included. Each bot turn is asked about on its own, once per criterion, with only the conversation before that turn as context. The answers are
meets,fails, andnot_applicable(the criterion only covers some situation, like “when the time is taken, apologise”, and this turn isn’t in it); onlyfailsfails the turn. All of a run’s questions go out at once.
How each question is written:
The reply or function call being judged is sent separately from the conversation before it (
latest_bot_replyorcall), so the classifier knows which part to judge.Every possible answer is one of the options. “The bot hasn’t answered yet” is the option
continue, and “this criterion doesn’t apply to this turn” is the optionnot_applicable. Don’t write these as rules in the instructions instead: a classifier follows an instruction for every criterion, even where it doesn’t fit. A rule like “a criterion about some situation passes when that situation doesn’t come up” also passes turns that never state a price against “the reply states a price”.The instructions hold only the question and the criterion.
How answers become verdicts:
Each verdict carries a confidence from 0 to 1, and its reason starts out as
the probabilities the classifier gave (for example P(yes)=0.97):
A reply’s verdict is the option chosen, with the confidence in it.
A yes/no question (a function call, a goal) is
yeswhen the probability of yes is at least 0.5; its confidence is the probability of the answer given.A turn’s confidence is the probability of the verdict given: for a pass, the probability of
meetsandnot_applicabletogether.
Each question’s verdict is cached by its criterion and state, so asking the same question about the same conversation twice costs one call.
The explainer:
A classifier gives no reasons, so the judge asks an LLM of its own, the explainer, for them, in a one-shot inference outside the pipeline with the prompts in this module. It is asked for:
every
no, on a reply, a function call, a turn or a goal;every verdict the classifier is unsure of, meaning a confidence below
explain_below(0.75 by default). When a verdict is close to 50/50, the next run can go the other way, so these are worth a second look. An LLM classifier’s probabilities are not calibrated and rarely fall this low, so in practice it is thenoverdicts that are explained;never a
continue, which is only a request to wait for more text.
explain_below: 0 limits it to the no verdicts, and a value above 1
has every verdict explained.
The explainer never decides a verdict. It is told the classifier’s and asked
what in the conversation supports it, so the reason points to evidence for the
verdict that counts, not to how the classifier reached it. Its reason takes the
place of the probabilities as the verdict’s reason, and the probabilities
stay in probabilities. For a simulation, every verdict of the run that needs
a reason is explained in one call. Each question names the reasons it wants in
a response schema, so an LLM that can enforce one answers in exactly that
shape, and a question whose call fails or times out, or whose answer leaves a
reason out, is asked once more. A verdict still without a reason keeps the
probabilities.
When a call fails:
A question that times out, can’t connect, or comes back unusable is asked
once more. A second failure fails the question: a reply or a function call
gets a no with the reason “judge call failed”, and each verdict of a
failed simulation question is a none (the verdict the harness reports as
not given).
Lifecycle:
The judge sets its classifier up before its first question and cleans it up when the session closes it at the end of the run, so a classifier that keeps a connection opens it once and a simulation’s questions share it.
Example:
from pipecat.classifiers.llm.classifier import LLMClassifier
from pipecat.services.ollama.llm import OLLamaLLMService
service = OLLamaLLMService(settings=OLLamaLLMService.Settings(model="gemma4:12b"))
judge = EvalJudge(LLMClassifier(llm=service), explainer=service)
judge.add_user_message("What can you help me with?")
judge.add_assistant_message("I can answer questions, set reminders, and look things up.")
verdict = await judge.evaluate("describes the bot's capabilities")
if not verdict.passed:
print(f"judge said no: {verdict.reason}")
- class pipecat.evals.judge.JudgeVerdict(verdict: str, reason: str, raw_response: str, confidence: float | None = None, probabilities: dict[str, float]=<factory>)[source]
Bases:
objectOutcome of a single judge call.
- Parameters:
verdict –
"yes"(satisfies),"no"(substantive answer that fails), or"continue"(interim/filler/incomplete — re-judge once more text arrives).reason – The explainer’s one-sentence reason for the verdict, or the classifier’s probabilities when nothing explained it.
raw_response – The judge’s raw answer, for diagnostics.
confidence – How sure the judge is of the verdict, from 0 to 1.
probabilities – The probability of each outcome the classifier was offered; empty when the question failed.
- class pipecat.evals.judge.RunVerdicts(goal: JudgeVerdict, turns: dict[str, list[JudgeVerdict]])[source]
Bases:
objectA whole simulation run’s verdicts.
- Parameters:
goal – The verdict on the goal, over the whole conversation.
turns – Per criterion name, a verdict per bot turn, in order.
- class pipecat.evals.judge.EvalJudge(classifier: BaseClassifier | LLMService[Any] | None = None, *, explainer: LLMService[Any] | None = None, explain_below: float = 0.75, allow_continue: bool = True, max_tokens: int = 200, service: LLMService[Any] | None = None)[source]
Bases:
objectJudges a conversation with a classifier, and asks an LLM for the reasons.
- Parameters:
classifier – The classifier that decides the verdicts. The judge sets it up and cleans it up with itself.
explainer – The LLM asked for the reason behind a
noor an unsure verdict;Nonereports the probabilities alone.explain_below – A
yesless sure than this is explained too.allow_continue – Whether a reply may be judged
continue(the bot is still working toward its answer, so the harness waits for more of it). A suite whose judged replies are all final answers turns it off, and a reply is thenyesorno.max_tokens – Cap on the explainer’s response length for one reason. Default 200, enough for a short sentence.
- __init__(classifier: BaseClassifier | LLMService[Any] | None = None, *, explainer: LLMService[Any] | None = None, explain_below: float = 0.75, allow_continue: bool = True, max_tokens: int = 200, service: LLMService[Any] | None = None)[source]
Initialize the judge with an empty conversation.
- Parameters:
classifier – The classifier that decides the verdicts. An LLM service is still accepted here, deprecated like
service: it classifies through anLLMClassifierand explains with itself.explainer – The LLM asked for the reason behind a verdict.
explain_below – A
yesless sure than this is explained too.allow_continue – Whether a reply may be judged
continue.max_tokens – Cap on the explainer’s response length for one reason.
service –
The LLM service that classifies and explains, in place of
classifier.Deprecated since version 1.12.0: Use
LLMClassifierover the service as theclassifier, passing the service as theexplainerfor the reasons. Will be removed in 2.0.0.
- Raises:
ValueError – If no classifier is given.
- classmethod from_config(judge_config: dict | None) EvalJudge[source]
Build a judge from a scenario’s
judge.eval:block.The block names an LLM,
ollamaby default, and the judge classifies and explains with it. Afactory(a dotted path to a callable taking the config) builds the classifier instead, or an LLM service to classify with; the explainer is then theexplainer:block’s LLM, or the default LLM when the block names none. For a fully custom judge, constructEvalJudgedirectly and pass it to the session.- Parameters:
judge_config – The
judge.eval:block, with the keys the module docstring lists.Noneuses all defaults.- Returns:
A configured EvalJudge.
- Raises:
ValueError – If the block names an unknown service, or its factory returned neither a classifier nor an LLM service.
Example:
# In the scenario: judge.eval.factory: "my_pkg.make_judge" def make_judge(config): return JevClassifier(api_key=...) # or any LLM service with run_inference()
- property classifier: BaseClassifier
The classifier that decides the verdicts.
- add_user_message(text: str | None) None[source]
Record a user turn, so a later reply is judged in context.
- Parameters:
text – The user’s utterance, or
Nonefor a bot-first turn (ignored).
- add_assistant_message(text: str | None) None[source]
Add a segment of the bot’s current reply to the conversation the judge sees.
Consecutive segments are one reply: a judged run counts them as one bot turn.
- Parameters:
text – The new reply segment; empty or
Noneis ignored.
- add_tool_call(text: str | None) None[source]
Record a tool call the bot made, as evidence for a judged run.
- Parameters:
text – The call on one line, e.g.
book({"time": "6pm"})orbook was cancelled; empty orNoneis ignored.
- async evaluate(criterion: str) JudgeVerdict[source]
Judge whether the bot’s latest reply satisfies
criterion, in the conversation so far.- Parameters:
criterion – Natural-language description of what the reply should express.
- Returns:
A
yes, ano, or, whenallow_continueis on, acontinuewhen the bot is still working toward its answer, cached by criterion and conversation. A final verdict that needs a reason is explained, and a failed call is anowith the failure as its reason.
- async evaluate_call(name: str, args: dict | None, criterion: str) JudgeVerdict[source]
Judge whether a function call the bot made satisfies
criterion, in the conversation so far.- Parameters:
name – The function’s name.
args – The call’s arguments.
criterion – Natural-language description of what the call should be.
- Returns:
A
yesor ano, cached by call, criterion and conversation, and explained when it needs a reason.
- async evaluate_run(criteria: dict[str, str], success: str, transcript: Sequence[dict] | None = None) RunVerdicts[source]
Judge the whole conversation: every bot turn on every criterion, and the goal.
The goal is asked over the whole conversation. Each bot turn is its own call, judged in the light of the conversation before it, with the turn itself as
latest_bot_reply; the calls run concurrently. When any verdict needs a reason, the explainer judges the run once and its reasons go with the classifier’s verdicts.- Parameters:
criteria – The per-turn criteria to decide, by name.
success – The goal criterion, decided over the whole conversation.
transcript –
A conversation to judge in place of the one the judge kept: dicts with a
roleofuser,assistantortooland thecontent. Also accepted first, beforecriteriaandsuccess.Deprecated since version 1.11.0: Feed the judge with
add_user_message(),add_assistant_message()andadd_tool_call()instead. Will be removed in 2.0.0.
- Returns:
The goal’s verdict and, per criterion, a verdict per bot turn in order. A failed call is a
nonefor each verdict it asked for.