Skip to main content

Mistral Evaluations

Namespace package for Mistral AI evaluation (Dora) utilities.

Overview

This package sets up the mistralai.evaluations namespace for Dora-specific utilities. It extends the Mistral AI SDK v2 namespace structure to allow evaluation features to be developed and released from this repository.

SDK v2 Namespace Package

This package follows PEP 420 implicit namespace packaging to integrate with the Mistral AI SDK v2 structure. The code lives in this repository (Dora) but will be importable from mistralai.evaluations once SDK v2 is released.

Package Structure

mistralai/                  # Shared namespace (no __init__.py)
├── client/                 # Core SDK (mistralai package on PyPI)
├── workflows/              # Workflows SDK
├── evaluations/            # This package (Dora utilities)
└── extra/                  # Extra utilities

The mistralai/ directory has no __init__.py, allowing multiple packages to coexist under the shared mistralai namespace.

Installation

This package is currently under development. Once SDK v2 is released, it will be available as part of the mistralai namespace.

For local development:

uv sync

Usage

Basic evaluation

from mistralai.evaluations import Evaluation, Evaluator, Project

run = await client.evaluation.run(
    project=Project(name="My Project"),
    evaluation=Evaluation(name="My Evaluation"),
    dataset=[{"input": "hello", "expected": "greeting"}],
    task=lambda input_record: classify(input_record["input"]),
    evaluators=[
        Evaluator(name="accuracy", scorer=lambda input_record, output: 1 if output == input_record["expected"] else 0),
    ],
)
run.show(level="scores")

Run-level evaluators

Run evaluators execute after all records are processed and receive the full run context (records, statistics, metrics, metadata). Use them for global assertions or aggregate metrics.

from mistralai.evaluations import RunEvaluator

run = await client.evaluation.run(
    ...,
    evaluators=[
        Evaluator(name="accuracy", scorer=lambda input_record, output: 1 if output == input_record["expected"] else 0),
    ],
    run_evaluators=[
        RunEvaluator(
            name="accuracy_above_50pct",
            scorer=lambda ctx: ctx.statistics["accuracy"].avg > 0.5,
        ),
        RunEvaluator(
            name="all_records_scored",
            scorer=lambda ctx: all(
                len(r.output.generations) > 0 for r in ctx.records
            ),
        ),
    ],
)
# Results are in run.run_scores
print(run.run_scores)  # {"accuracy_above_50pct": True, "all_records_scored": True}

The RunEvaluatorContext provides:

Field Type Description
records list[RunEvaluatorRecord] Each record's input and output (with scores).
statistics dict[str, EvaluatorStatistics] Run-level statistics from regular evaluators.
metrics dict[str, JsonValue] Run-level run_aggregator results.
metadata dict[str, JsonValue] Metadata attached to the run.

Retrying failed records

If an evaluation only partially fails, use retry_failed_records instead of re-running the entire evaluation from scratch. It re-runs only the failed records and patches the original run in place, avoiding work on successful records when failures came from transient API errors, rate limits, or a bug in the task or scorer.

from mistralai.evaluations import Evaluation, Evaluator

run = await client.evaluation.run(
    evaluation=Evaluation(name="My Evaluation"),
    dataset=dataset,
    task=flaky_task,
    evaluators=[Evaluator(name="accuracy", scorer=scorer)],
)

# Fix the task or scorer if needed, then retry only the failed records.
result = await client.evaluation.retry_failed_records(
    run_id=run.run_id,
    dataset=dataset,
    task=fixed_task,
    evaluators=[Evaluator(name="accuracy", scorer=scorer)],
)

print(f"Retried: {result.retried_count}, Patched: {result.patched_count}")

Pass the same dataset used in the original run so the SDK can map failed records back to their inputs. You can pass a fixed task or updated evaluators before retrying. When run-level evaluators are provided, their scores are recomputed after patching.

get_score helper

When writing run evaluators, accessing individual scores requires navigating through generations and score lists. The get_score helper simplifies this:

from mistralai.evaluations import RunEvaluatorContext, Score, get_score

def f1_scorer(ctx: RunEvaluatorContext) -> Score:
    tp = fp = fn = 0
    for record in ctx.records:
        expected = str(record.input["expected"]).lower()
        # Instead of: record.output.generations[0].scores["accuracy"][0].value
        is_correct = get_score(record, "accuracy").value == 1
        ...

Returns a Score object (with value, rationale, metadata).

Parameter Type Default Description
record RunEvaluatorRecord The record to extract scores from.
evaluator_name str Name of the evaluator whose scores to retrieve.
aggregate Callable[[list[Score]], Score] None Required when multiple scores exist (multiple generations).

Raises if no scores are found. When num_generations > 1, raises with a helpful message unless an aggregate function is provided. For pre-computed aggregations, use record.output.statistics[evaluator_name] instead.

Development

# Install dependencies
uv sync

# Run tests
uv run pytest

# Lint and format
uv run ruff check --fix .
uv run ruff format .

# Type check
uv run mypy mistralai

Publishing

Release from GitHub

The version is not stored in code. This package uses uv-dynamic-versioning: the published version comes from the release tag (evaluations-sdk/vX.Y.Z), and the workflow stamps the version you pass onto the build via UV_DYNAMIC_VERSIONING_BYPASS. There is no version-bump PR — just run the workflow with the version you want.

Run the "Release Evaluations SDK" GitHub workflow manually. Choose which registries to publish to via the boolean inputs — they're independent, so you can dogfood internally without shipping to clients:

  1. PyPI (public), via a trusted publisher (OIDC) — the primary channel. Default on.
  2. Gemfury, for internal distribution. Default on.
  3. Cloudsmith (mistral-ai/sdk-distribution), for private-preview client distribution. Default off — opt in when previewing to specific clients.

Run the workflow from main for normal SDK releases, or from the relevant mais-* release branch for on-prem patch lines. Enter the version as the workflow version input (PEP 440, e.g. 0.7.0 or 0.7.0rc1); the workflow fails if the tag evaluations-sdk/vX.Y.Z already exists.

The git tag evaluations-sdk/vX.Y.Z records the released commit for that version, so it is created as soon as any selected registry publishes successfully (and none of the selected ones failed). To dogfood privately, publish an rc to Gemfury only; the rc tag won't collide with the later public release.

If one registry succeeds and another fails, rerun the failed GitHub Actions jobs only. Do not rerun the full workflow, because the already-successful registry may reject the duplicate version.

The TypeScript mirror (ts/packages/local-observability-sdk/) still carries its own package.json / cli.ts version and is not published by this workflow; keep it in sync when practical.

Manual Gemfury publish

Retrieve the "Gemfury Upload Token - Mistral" credentials from Bitwarden. The make publish command expects GEMFURY_USERNAME and GEMFURY_PASSWORD environment variables.

# Publish to Gemfury
# this will clean up the dist/ directory then build and publish
make publish

Installing from PyPI (public)

pip install mistralai-evaluations

Installing from Gemfury (internal)

pip install --index-url https://pypi.fury.io/mistralai/ mistralai-evaluations --extra-index-url https://pypi.org/simple/

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mistralai_evaluations-0.7.0.tar.gz (139.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mistralai_evaluations-0.7.0-py3-none-any.whl (78.6 kB view details)

Uploaded Python 3

File details

Details for the file mistralai_evaluations-0.7.0.tar.gz.

File metadata

  • Download URL: mistralai_evaluations-0.7.0.tar.gz
  • Upload date:
  • Size: 139.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mistralai_evaluations-0.7.0.tar.gz
Algorithm Hash digest
SHA256 e4214b8b442ef03bb5671232191bc1b098dd5ba649b0167819b1bf85cad2853d
MD5 da6d4a608923146fe3c673de82b9b026
BLAKE2b-256 327995b56305d9952859200c55cd397f210cf8a18b104c787549fb5d034d3582

See more details on using hashes here.

Provenance

The following attestation bundles were made for mistralai_evaluations-0.7.0.tar.gz:

Publisher: evaluations-sdk-release.yaml on mistralai/dashboard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mistralai_evaluations-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mistralai_evaluations-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a97380ee8f74e2a200f9225e2614408d05f20856c5173a54d0bf253c184523f
MD5 09a359d7dd7b1a4006b375b5fcc853c4
BLAKE2b-256 b59a5bb0c108d27bb07394ed8f3c8f04c70d28913e2d7bc04368b49da6463ffe

See more details on using hashes here.

Provenance

The following attestation bundles were made for mistralai_evaluations-0.7.0-py3-none-any.whl:

Publisher: evaluations-sdk-release.yaml on mistralai/dashboard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page