Skip to content

Writing custom Scorers to evaluate agents and LLMs

Databricks Agent Evaluation (via MLflow) allows engineers to define custom scorers when the built-in judges do not cover a specific business requirement. Custom scorers let you encode deterministic logic (e.g., regex, JSON schema checks) or LLM-as-a-judge logic tailored to your use case, and they run alongside built-in metrics during mlflow.evaluate() runs. This is essential for evaluating agent outputs against criteria unique to your domain, such as tone, specific factual grounding, or compliance rules.

1 · Learn the must-know

  • Custom scorers are typically implemented as Python functions decorated with @scorer (or passed as a list of custom metric objects) and registered in the evaluation call alongside standard Agent Evaluation judges.
  • A custom scorer function receives structured inputs like the request, response, retrieved context, and expected/ground-truth fields, and must return a score (numeric, boolean, or categorical) often with a rationale string.
  • Custom scorers can wrap an LLM as a judge (LLM-as-a-judge pattern) using a prompt template you control, giving flexibility beyond the built-in correctness/groundedness/relevance judges.
  • Results from custom scorers appear in the MLflow evaluation results table and Databricks UI alongside built-in metrics, enabling side-by-side comparison across runs.
  • Custom scorers must be deterministic or clearly documented if using an LLM judge, since inconsistent scoring logic undermines reproducibility of evaluation runs.
  • A common gotcha is mismatching the expected input/output schema of the scorer function with the evaluation dataset columns, which causes evaluation failures or silently skipped rows.

2 · Check your understanding

Check this objectiveFree · always available

A Generative AI Engineer is evaluating a support chatbot with mlflow.genai.evaluate() and needs a custom check that verifies every response contains a ticket reference number matching the pattern TICKET-#####. The engineer writes a Python function that inspects the outputs field and returns a boolean. Which approach correctly registers this function as a custom scorer for the evaluation run?

Your objective map0 tried · 0 answered correctly · 56 untouched

What you have tried across Databricks GenAI Engineer's objectives, not a readiness score.

Design Applications10.71% of the exam*0 of 6 tried
Data Preparation14.29% of the exam*0 of 8 tried
Application Development23.21% of the exam*0 of 13 tried
Assembling and Deploying Applications26.79% of the exam*0 of 15 tried
Governance7.14% of the exam*0 of 4 tried
Evaluation and Monitoring17.86% of the exam*0 of 10 tried

* Our estimate. Databricks publishes no section weights.

3 · Keep going