What this thread does
Load shared reference data once, attach a configured evaluator with Dataset.add_evaluator(), and keep each case's metadata limited to the identifier it needs.
What changed
- This recipe targets the Pydantic Evals 2.63.0 dataset API, whose release is dated October 28, 2026. It is a setup pattern, not a release migration or a timeout fix.
- That version has dataset-wide evaluators and per-case
metadata; it does not define a dataset-widemetadataconstructor field.evaluate_sync(metadata=...)records experiment metadata in the report. It does not replace the per-case value seen by ordinary evaluators. Dataset API, EvaluatorContext.
Do first: put one small key in each case
1. Record python -m pip show pydantic-evals. Save this illustrative cases.yaml:
name: greetings
cases:
- name: hello
inputs: hello
metadata:
reference_id: en_hello
- name: goodbye
inputs: goodbye
metadata:
reference_id: en_goodbye
2. Load the dataset with explicit input, output and metadata types. Configure the shared check once in Python:
from dataclasses import dataclass
from pydantic_evals import Dataset
from pydantic_evals.evaluators import Evaluator, EvaluatorContext
@dataclass
class ReferenceMatch(Evaluator[str, str, dict[str, str]]):
references: dict[str, str]
def evaluate(
self, ctx: EvaluatorContext[str, str, dict[str, str]]
) -> bool:
if ctx.metadata is None:
raise ValueError("reference_id is required")
expected = self.references[ctx.metadata["reference_id"]]
return ctx.output == expected
references = {"en_hello": "Hello", "en_goodbye": "Goodbye"}
dataset = Dataset[str, str, dict[str, str]].from_file("cases.yaml")
dataset.add_evaluator(ReferenceMatch(references=references))
async def candidate(text: str) -> str:
return text.capitalize()
report = dataset.evaluate_sync(
candidate,
metadata={"reference_revision": "greetings-v1"},
)
report.print(include_input=True, include_output=True)
The mapping is tiny for illustration; replace it with one load of your reference file. The custom-evaluator guide documents dataclass configuration and boolean assertion outputs. The dataset-management guide documents loading typed YAML datasets.
3. Run a deliberately wrong candidate output alongside a matching one. Look for a failed ReferenceMatch assertion, not only completed case execution. Also try an absent reference ID: the explicit exception distinguishes malformed evaluation data from an incorrect answer. Do not silently count a missing reference as a successful check. 4. Keep reference_revision synchronized with the reference object loaded by your code. The metrics/attributes guide explains that experiment metadata describes configuration; it does not configure the evaluated function automatically.
Where each kind of data belongs
| Need | Put it here |
|---|---|
| A different reference ID for each case | Case.metadata, read through ctx.metadata |
| One reference corpus for all checks | One configured evaluator attached with add_evaluator() |
| A label for comparing evaluation runs | evaluate_sync(metadata=...) |
| Shared context needed by the evaluated function | Explicit function closure, bound object or wrapper |
The ordinary evaluated callable receives case inputs; it does not receive Case.metadata as an extra argument. Dataset callable signature. If both application code and evaluator need shared data, inject the appropriate object into each explicitly, while keeping expected answers out of the application's inputs.
If the evaluator must live in YAML
The example attaches it after loading, so YAML does not need to name ReferenceMatch. If you serialize custom evaluator declarations instead, register their classes using Dataset.from_file(..., custom_evaluator_types=[ReferenceMatch]). The serialization guidance explains this requirement. Putting the full reference mapping into a serialized evaluator can enlarge the file again; use that approach only when the configuration belongs in the artifact.
Avoid adding an ad hoc top-level _shared_metadata key just to host a YAML anchor: the 2.63.0 serialized dataset model forbids extra fields. YAML syntax alone does not establish compatibility with the dataset schema.
Evidence
On May 14, 2026, whillas-yougov asked how to share data without making each YAML case repeat it in discussion #13182. yudin-s suggested shared evaluator context or a lightweight per-case key; a May 15 follow-up also asks how application code can access it.
Limits
The sample checks exact strings and does not grade semantic quality. Treat shared references as read-only during concurrent evaluation. Not for: Pydantic Evals 2.63.0 stalled runs and per-attempt deadlines; see the timeout thread.
Started from a post by @whillas-yougov, packaged by the editor. Original post