mistralM

Docs

sideBar

Workflow evaluation plugin API reference

Reference for evaluation.run(), its result, and the imports of the workflows evaluation plugin.

Reference for evaluation.run(), its result, and the plugin's imports. The plugin reuses the SDK types: see the SDK API reference for Project, Evaluation, Evaluator, RunEvaluator, Goal, and System. For the other methods, see Decorators, Optimization, Rescoring, and Building blocks.

evaluation.run()

Runs an evaluation from a workflow. Call it from a @workflow.entrypoint.

from mistralai.workflows.plugins.evaluations import evaluation

result = await evaluation.run(
    dataset=...,
    task=...,
    evaluators=...,
    # optional parameters below
)

Parameter

Type

Default

Description

datasetSequence[Mapping[str, Any]] | DatasetrequiredInline input records, or a Studio dataset selected with Dataset(id=...) or Dataset(slug=...) (0.6.3+). Up to 10,000 records for a Studio dataset; inline lists are bounded by payload size. See Datasets and limits.
taskfunction, class, or strrequired@evaluation.task function, @workflow.define class, or workflow name. See Task modes.
evaluatorslist[Evaluator | EvaluatorGroup]requiredPer-record evaluators, and groups of evaluators scored by one scorer call (0.9.0+). Their scorers must be decorated with @evaluation.scorer. Pass [] for a task-only run.
run_evaluatorslist[RunEvaluator] | NoneNoneRun-level evaluators. Their scorers must be decorated with @evaluation.run_scorer.
projectProject | NoneNoneProject to save to (created if it doesn't exist).
evaluationEvaluation | NoneNoneEvaluation to save to (created if it doesn't exist).
namestr | NoneNoneRun name.
descriptionstr | NoneNoneRun description.
tagslist[str] | NoneNoneTags for filtering in Studio.
metadatadict | NoneNoneStatic run metadata, or an @evaluation.run_metadata callback.
record_metadatafunction | NoneNone@evaluation.record_metadata callback, run once per record.
systemSystem | NoneNoneSystem config passed to the task and scorers via context objects.
num_generationsint1Task executions per record, from 1 to 100.
localboolFalseIf True, skip every call to Studio.

Concurrency, timeouts, and retries are set on the decorators, not on run().

It returns an EvalResult:

Field

Type

Description

run_idstrRun ID, or "local" in local mode.
run_urlstr | NoneLink to the run in Studio. None in local mode.
statisticsdict[str, EvaluatorStatistics]Per-evaluator aggregate statistics, without failed generations and scores.
run_scoresdict[str, Score]Run-level evaluator scores, by evaluator name. Each value is a score object with value, rationale, metadata, status, and error.
failed_record_countintRecords whose task or a score failed (0.7.0+). What failed is not in statistics.
potentially_stale_run_evaluatorslist[str]Set by rescore() only. See Rescoring.

EvalResult is a Pydantic model: return result.model_dump() from your workflow to expose it as the workflow output.

Execution flow

  • 1.

    Setup: creates the project, evaluation, and run in Studio, and marks the run as running.
  • 2.

    Fan-out: starts one child workflow per record, in batches.
  • 3.

    Per record: fetches the record from the Studio dataset (if any), uploads the input record, runs the task and its scorers for each generation, runs the record_metadata callback, and uploads the output record.
  • 4.

    Statistics: aggregates scores per evaluator.
  • 5.

    Run evaluators: runs the run-level evaluators and uploads their scores.
  • 6.

    Run metadata: runs the run_metadata callback and updates the run.
  • 7.

    Completion: marks the run as completed, or failed.

While the run is in progress, the workflow sends a heartbeat to Studio. If the worker dies, or the workflow is cancelled or terminated, Studio marks the run as cancelled instead of leaving it in progress.

A failed task or scorer is recorded as an error on its record; the other records continue.

evaluation.add_dataset_records()

Adds records to an existing Studio dataset from a workflow, for example the cases a workflow collected before it evaluates them. Each record is the record's payload: the JSON object a run reads as its input record. Requires plugin 0.9.0+.

from mistralai.workflows.plugins.evaluations import evaluation
from mistralai.workflows.plugins.evaluations.types import Dataset

ids = await evaluation.add_dataset_records(
    dataset=Dataset(slug="customer-support-golden-set"),
    records=[{"input": "How do I reset my password?", "expected": "Settings > Security"}],
)

It returns the IDs of the new records, in order. The records go through the workflow history: one eval: add dataset records activity adds each batch of up to 100 records and about 1 MB, whole or not at all. The workflow generates the record IDs, so a retried activity or a replayed workflow doesn't add a record twice.

A record over 1 MB, or more records than the workflow history can hold (about 40 MB with what it already holds), fail the call before any record is added. Add those with the SDK's client.evaluation.add_dataset_records() from an activity.

A run reads at most 10,000 records, so a dataset larger than that can't be evaluated in one run.

To set a record's properties, pass a CreateDatasetRecordRequest instead of its payload:

from mistralai.client.models import CreateDatasetRecordRequest

ids = await evaluation.add_dataset_records(
    dataset=Dataset(slug="customer-support-golden-set"),
    records=[CreateDatasetRecordRequest(payload={"input": "How do I reset my password?"}, properties={"category": "account"})],
)

Imports

Import types from mistralai.workflows.plugins.evaluations.types. This module only re-exports SDK types, so it's safe to import from workflow code running in the Temporal sandbox:

from mistralai.workflows.plugins.evaluations.types import (
    Dataset,                # Studio dataset selector (id or slug)
    Evaluation,             # Evaluation identifier (name or slug)
    Evaluator,              # Per-record evaluator
    EvaluatorGroup,         # Several evaluators scored by one scorer call (0.9.0+)
    Goal,                   # Pass/fail gate: gte, lte, between
    Project,                # Project identifier (name or slug)
    RecordMetadataContext,  # Context for @evaluation.record_metadata
    RunEvaluator,           # Run-level evaluator
    RunEvaluatorContext,    # Context for @evaluation.run_scorer
    RunMetadataContext,     # Context for @evaluation.run_metadata
    Score,                  # Scorer return type
    ScorerContext,          # Context for @evaluation.scorer
    Statistic,              # Run-level statistic factories
    System,                 # System config (name + params)
    TaskContext,            # Context for @evaluation.task
    Tunable,                # Optimizable parameter slot
    TunableSystem,          # Search space for optimization
)

The evaluation namespace and the optimization types come from the package root:

from mistralai.workflows.plugins.evaluations import (
    evaluation,         # run, rescore, optimize, building blocks, and decorators
    EvalResult,         # Result of run() and rescore()
    GEPA,               # Pareto-based reflective optimizer
    SimpleOptimizer,    # Greedy hill-climb optimizer
    OptimizeResult,     # Result of optimize()
    OptimizeCandidate,  # One candidate in the trajectory
    OptimizeVariant,    # Baseline, winner, or best attempt
    MutatorRequest,     # Input of a custom mutator
    MutatorProposal,    # Output of a custom mutator
)

evaluation.optimize()

Same parameters as the SDK's client.evaluation.optimize(), except the ones that don't apply in a workflow. See Optimize prompts and parameters for the shared parameters and algorithms, and Optimization for the workflow specifics.

Parameter

Type

Default

Description

systemTunableSystemrequiredThe search space. Must contain at least one Tunable slot.
datasetlist[dict[str, Any]] | DatasetrequiredInput records, or a Studio dataset selected with Dataset(id=...) or Dataset(slug=...) (0.9.0+). See Datasets.
taskfunction, class, or strrequiredSame as in run().
evaluatorslist[Evaluator | EvaluatorGroup]requiredPer-record evaluators. They define the objective and the gates.
algoSimpleOptimizer | GEPArequiredThe search strategy.
run_evaluatorslist[RunEvaluator] | NoneNoneRecorded on each candidate's run. They don't drive selection.
projectProject | NoneNoneProject to save to.
evaluationEvaluation | NoneNoneEvaluation to save to.
steerstr | NoneNonePlain-language goal for the mutator, up to 4,000 characters.
namestr | NoneNoneOptimization name. Generated from steer when omitted.
descriptionstr | NoneNoneOptimization description. Generated from steer when omitted.
tagslist[str] | NoneNoneTags for filtering in Studio.
metadatadict[str, Any] | NoneNoneMetadata attached to each candidate's run.
localboolFalseNot supported: raises ValueError.