application
Application orchestration layer for evaLLM.
This package coordinates dataset access and metric execution while exposing a stable public API for library and CLI consumers.
Abstract
evallm.application is the orchestration layer that turns validated requests into
executable evaluation flows. api exposes ergonomic construction primitives,
models defines canonical contracts, services resolves and executes requests,
adapters normalize raw reader output into DTOs, validation enforces
cross-object constraints, and errors defines user-facing failure semantics.
Design Decisions
- Decision: Use immutable DTOs as canonical request/result contracts.
- Motivation:
modelsuses frozen pydantic DTOs to keep boundary data validated, serializable, and mutation-safe across layers. - Decision: Separate structural validation from runtime/contextual resolution.
- Motivation: shape validation happens at DTO creation, while checks requiring runtime context (catalog membership, metric config validation, reader binding) happen in resolver/services.
- Decision: Resolve requests into two runtime artifacts.
- Motivation:
RequestResolverreturns(records_context_manager, composite_metric), decoupling data streaming from metric composition/execution. - Decision: Enforce result-key uniqueness before execution.
- Motivation: per-record results are merged into a single dictionary, so duplicate result keys would overwrite values unless rejected early.
- Decision: Keep request construction ergonomic via builder + helpers.
- Motivation:
BaseEvaluationBuilder/JsonlEvaluationBuilderand helper factories (metric,count_*,json_format) provide concise API ergonomics while still yielding canonical DTOs. - Decision: Depend on abstract contracts where possible.
- Motivation: using abstractions like
Catalogimproves testability and supports custom registries without changing orchestration logic.
| MODULE | DESCRIPTION |
|---|---|
adapters |
|
api |
|
errors |
|
models |
|
services |
|
validation |
| CLASS | DESCRIPTION |
|---|---|
BaseEvaluationBuilder |
Abstract mutable builder for creating evaluation requests. |
JsonlEvaluationBuilder |
Concrete builder for JSONL-based evaluations. |
BaseDatasetSpec |
Abstract base class for dataset specifications. |
DatasetRecord |
DTO representing a single record to evaluate in a dataset |
EvaluationRequest |
DTO specifying which configuration of metrics to evaluate a given dataset on |
EvaluationResult |
DTO representing the evaluated metrics' results for a single record |
JsonlDatasetSpec |
DTO specifying a structured JSONL dataset to evaluate |
MetricSpec |
DTO specifying a metric and its configuration |
Evaluator |
Component responsible for orchestrating the evaluation process. |
| FUNCTION | DESCRIPTION |
|---|---|
count_characters |
Create a metric spec for counting the number of characters in the evaluated text. |
count_encodings |
Create a metric spec for counting the number of model-specific encodings in a text. |
count_tokens |
Create a metric spec for counting the number of tokens in the evaluated text. |
json_format |
Create a metric spec for validating JSON output format. |
metric |
Create a generic metric spec using a metric's name. |
Classes
BaseEvaluationBuilder
BaseEvaluationBuilder(*, catalog: type[Catalog] = MetricsCatalog)
flowchart TD
evallm.application.BaseEvaluationBuilder[BaseEvaluationBuilder]
click evallm.application.BaseEvaluationBuilder href "" "evallm.application.BaseEvaluationBuilder"
Abstract mutable builder for creating evaluation requests.
| METHOD | DESCRIPTION |
|---|---|
use |
Attach a single metric spec and return the same builder instance. |
build_dataset |
Build the dataset spec for the concrete builder. |
build_request |
Build the canonical evaluation request. |
build_evaluator |
Build an evaluator from the current builder state. |
run |
Lazily execute evaluation and yield individual results. |
from_request |
Rebuild a concrete builder from a canonical request. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
catalog |
Immutable catalog used for metric resolution. |
metrics |
Immutable view of attached metric specs.
TYPE:
|
Source code in src/evallm/application/api.py
Attributes
catalog
property
metrics
property
metrics: tuple[MetricSpec, ...]
Immutable view of attached metric specs.
| RETURNS | DESCRIPTION |
|---|---|
tuple[MetricSpec, ...]
|
tuple[MetricSpec, ...]: Tuple of currently attached metric specs. |
Functions
use
use(metric_spec: MetricSpec) -> Self
Attach a single metric spec and return the same builder instance.
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The mutated builder instance.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
DuplicateMetricResultKeyError
|
If attaching the metric would cause a final result-key collision. |
Source code in src/evallm/application/api.py
build_dataset
abstractmethod
build_request
build_request() -> EvaluationRequest
Build the canonical evaluation request.
| RETURNS | DESCRIPTION |
|---|---|
EvaluationRequest
|
Canonical request assembled from current builder state.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If no metrics are attached. |
Source code in src/evallm/application/api.py
build_evaluator
build_evaluator() -> Evaluator
Build an evaluator from the current builder state.
| RETURNS | DESCRIPTION |
|---|---|
Evaluator
|
Evaluator configured with the built request and catalog.
TYPE:
|
Source code in src/evallm/application/api.py
run
run() -> Iterator[EvaluationResult]
Lazily execute evaluation and yield individual results.
| YIELDS | DESCRIPTION |
|---|---|
EvaluationResult
|
Per-record evaluation result.
TYPE::
|
from_request
abstractmethod
classmethod
from_request(
request: EvaluationRequest, *, catalog: type[Catalog] = MetricsCatalog
) -> Self
Rebuild a concrete builder from a canonical request.
Source code in src/evallm/application/api.py
JsonlEvaluationBuilder
JsonlEvaluationBuilder(
input_file: str | PathLike[str],
*,
text_key: str,
record_id_key: str = "#IDX#",
catalog: type[Catalog] = MetricsCatalog,
)
flowchart TD
evallm.application.JsonlEvaluationBuilder[JsonlEvaluationBuilder]
evallm.application.api.BaseEvaluationBuilder[BaseEvaluationBuilder]
evallm.application.api.BaseEvaluationBuilder --> evallm.application.JsonlEvaluationBuilder
click evallm.application.JsonlEvaluationBuilder href "" "evallm.application.JsonlEvaluationBuilder"
click evallm.application.api.BaseEvaluationBuilder href "" "evallm.application.api.BaseEvaluationBuilder"
Concrete builder for JSONL-based evaluations.
-
API Reference
evallmapplication
| METHOD | DESCRIPTION |
|---|---|
use |
Attach a single metric spec and return the same builder instance. |
build_request |
Build the canonical evaluation request. |
build_evaluator |
Build an evaluator from the current builder state. |
run |
Lazily execute evaluation and yield individual results. |
build_dataset |
Build a JSONL dataset spec from the builder state. |
from_request |
Rebuild a JSONL builder from an existing request. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
catalog |
Immutable catalog used for metric resolution. |
metrics |
Immutable view of attached metric specs.
TYPE:
|
input_file |
Input JSONL dataset path.
TYPE:
|
text_key |
Key of the field containing text to evaluate in each JSONL record.
TYPE:
|
record_id_key |
Key of the field containing record ids.
TYPE:
|
Source code in src/evallm/application/api.py
Attributes
catalog
property
metrics
property
metrics: tuple[MetricSpec, ...]
Immutable view of attached metric specs.
| RETURNS | DESCRIPTION |
|---|---|
tuple[MetricSpec, ...]
|
tuple[MetricSpec, ...]: Tuple of currently attached metric specs. |
input_file
property
input_file: Path
Input JSONL dataset path.
| RETURNS | DESCRIPTION |
|---|---|
Path
|
The input JSONL dataset as a normalized path.
TYPE:
|
text_key
property
text_key: str
Key of the field containing text to evaluate in each JSONL record.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The field's name.
TYPE:
|
record_id_key
property
record_id_key: str
Key of the field containing record ids.
| RETURNS | DESCRIPTION |
|---|---|
str
|
str | Literal["#IDX#"]: The field's name or the reserved literal "#IDX#" if record ids aren't present and should instead be auto-generated as 0-based indices. |
Functions
use
use(metric_spec: MetricSpec) -> Self
Attach a single metric spec and return the same builder instance.
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The mutated builder instance.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
DuplicateMetricResultKeyError
|
If attaching the metric would cause a final result-key collision. |
Source code in src/evallm/application/api.py
build_request
build_request() -> EvaluationRequest
Build the canonical evaluation request.
| RETURNS | DESCRIPTION |
|---|---|
EvaluationRequest
|
Canonical request assembled from current builder state.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If no metrics are attached. |
Source code in src/evallm/application/api.py
build_evaluator
build_evaluator() -> Evaluator
Build an evaluator from the current builder state.
| RETURNS | DESCRIPTION |
|---|---|
Evaluator
|
Evaluator configured with the built request and catalog.
TYPE:
|
Source code in src/evallm/application/api.py
run
run() -> Iterator[EvaluationResult]
Lazily execute evaluation and yield individual results.
| YIELDS | DESCRIPTION |
|---|---|
EvaluationResult
|
Per-record evaluation result.
TYPE::
|
build_dataset
build_dataset() -> JsonlDatasetSpec
Build a JSONL dataset spec from the builder state.
| RETURNS | DESCRIPTION |
|---|---|
JsonlDatasetSpec
|
JSONL dataset spec built from current builder fields.
TYPE:
|
Source code in src/evallm/application/api.py
from_request
classmethod
from_request(
request: EvaluationRequest, *, catalog: type[Catalog] = MetricsCatalog
) -> JsonlEvaluationBuilder
Rebuild a JSONL builder from an existing request.
| RETURNS | DESCRIPTION |
|---|---|
JsonlEvaluationBuilder
|
Builder reconstructed from the provided request.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
Source code in src/evallm/application/api.py
BaseDatasetSpec
pydantic-model
Abstract base class for dataset specifications.
Fields:
Attributes
data_format
pydantic-field
data_format: str
Dataset format discriminator used for dataset spec resolution.
Functions
create
classmethod
create(
obj: Any | None = None,
*,
json_payload: str | bytes | bytearray | None = None,
**kwargs: Any,
) -> Self
Convenience factory to create DTOs from various input sources.
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The DTO's fields as a native Python object (e.g. a dict).
TYPE:
|
json_payload
|
The DTO's fields as a JSON string- or bytes-payload. |
**kwargs
|
Keyword arguments corresponding to the DTO's fields.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
An instance of the DTO created from the provided input.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If 0 or more than 1 of the input sources are provided. |
Source code in src/evallm/application/models.py
infer_data_format
classmethod
Infer dataset format from the input-file suffix, if possible.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Raw dataset payload. |
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
str | None: Inferred dataset format, or |
Source code in src/evallm/application/models.py
resolve
classmethod
resolve(data: BaseDatasetSpec | Mapping[str, Any]) -> BaseDatasetSpec
Resolve a raw or already-validated dataset payload to a concrete dataset DTO.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Raw or typed dataset payload.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BaseDatasetSpec
|
Resolved dataset spec instance.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the dataset format is missing, unsupported, or conflicts with the inferred format. |
Source code in src/evallm/application/models.py
DatasetRecord
pydantic-model
DTO representing a single record to evaluate in a dataset
Fields:
Validators:
-
_stringify_text→text
Attributes
record_id
pydantic-field
record_id: str
The record's unique identifier, specified as a string. The value of this field
corresponds to the dataset field specified by
JsonlDatasetSpec.record_id_key.
-
API Reference
evallmapplication
text
pydantic-field
text: str
The record's value to evaluate. The value of this field corresponds to the
dataset field specified by
JsonlDatasetSpec.text_key,
and indexed by record_id.
Type coercion for text field
During validation, None values will be converted to the empty string
(i.e. ""), values of JSON-serializable types that aren't strings will be
converted to their string representation (e.g. {'key': 123} will become
"{'key': 123}"), and string values are kept as-is (e.g. " " will remain
" ").
metadata
pydantic-field
Optional dictionary containing any additional fields from the dataset record.
Functions
create
classmethod
create(
obj: Any | None = None,
*,
json_payload: str | bytes | bytearray | None = None,
**kwargs: Any,
) -> Self
Convenience factory to create DTOs from various input sources.
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The DTO's fields as a native Python object (e.g. a dict).
TYPE:
|
json_payload
|
The DTO's fields as a JSON string- or bytes-payload. |
**kwargs
|
Keyword arguments corresponding to the DTO's fields.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
An instance of the DTO created from the provided input.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If 0 or more than 1 of the input sources are provided. |
Source code in src/evallm/application/models.py
EvaluationRequest
pydantic-model
DTO specifying which configuration of metrics to evaluate a given dataset on
Fields:
Validators:
-
_validate_dataset_spec→dataset
Attributes
dataset
pydantic-field
dataset: BaseDatasetSpec
The dataset to evaluate, specified as a concrete
BaseDatasetSpec subtype.
-
API Reference
evallmapplicationapplication ClassesEvaluator
metrics
pydantic-field
metrics: list[MetricSpec]
List of one or more metrics to use for evaluation, each specified as a
MetricSpec.
Functions
create
classmethod
create(
obj: Any | None = None,
*,
json_payload: str | bytes | bytearray | None = None,
**kwargs: Any,
) -> Self
Convenience factory to create DTOs from various input sources.
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The DTO's fields as a native Python object (e.g. a dict).
TYPE:
|
json_payload
|
The DTO's fields as a JSON string- or bytes-payload. |
**kwargs
|
Keyword arguments corresponding to the DTO's fields.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
An instance of the DTO created from the provided input.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If 0 or more than 1 of the input sources are provided. |
Source code in src/evallm/application/models.py
EvaluationResult
pydantic-model
DTO representing the evaluated metrics' results for a single record
Fields:
Attributes
record_id
pydantic-field
record_id: str
The unique identifier for the evaluated record, specified as a string.
The value of this field corresponds to the dataset field specified by
JsonlDatasetSpec.record_id_key
and mirrors the value of the corresponding
DatasetRecord.record_id.
results
pydantic-field
A dictionary mapping metric result keys to their computed results.
Each key corresponds to the resolved metric instance's
result_key, which defaults to the
metric's name unless explicitly
overridden.
Functions
create
classmethod
create(
obj: Any | None = None,
*,
json_payload: str | bytes | bytearray | None = None,
**kwargs: Any,
) -> Self
Convenience factory to create DTOs from various input sources.
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The DTO's fields as a native Python object (e.g. a dict).
TYPE:
|
json_payload
|
The DTO's fields as a JSON string- or bytes-payload. |
**kwargs
|
Keyword arguments corresponding to the DTO's fields.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
An instance of the DTO created from the provided input.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If 0 or more than 1 of the input sources are provided. |
Source code in src/evallm/application/models.py
JsonlDatasetSpec
pydantic-model
DTO specifying a structured JSONL dataset to evaluate
Fields:
-
data_format(Literal['jsonl']) -
input_file(FilePath) -
record_id_key(str) -
text_key(str)
Validators:
-
_validate_jsonl_path→input_file -
_validate_keys
Attributes
input_file
pydantic-field
input_file: FilePath
Path to a local JSONL-file containing the dataset to evaluate.
record_id_key
pydantic-field
record_id_key: str = '#IDX#'
The dataset field/ column name that contains the unique identifier for each
record, specified as a non-empty string. Defaults to "#IDX#", which indicates
that record IDs should be generated based on the record's (0-indexed) position in
the dataset.
-
API Reference
evallmapplication
text_key
pydantic-field
text_key: str
The dataset field/ column name that contains the text to evaluate, specified as a non-empty string.
-
API Reference
evallmapplication
Functions
create
classmethod
create(
obj: Any | None = None,
*,
json_payload: str | bytes | bytearray | None = None,
**kwargs: Any,
) -> Self
Convenience factory to create DTOs from various input sources.
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The DTO's fields as a native Python object (e.g. a dict).
TYPE:
|
json_payload
|
The DTO's fields as a JSON string- or bytes-payload. |
**kwargs
|
Keyword arguments corresponding to the DTO's fields.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
An instance of the DTO created from the provided input.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If 0 or more than 1 of the input sources are provided. |
Source code in src/evallm/application/models.py
infer_data_format
classmethod
Infer dataset format from the input-file suffix, if possible.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Raw dataset payload. |
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
str | None: Inferred dataset format, or |
Source code in src/evallm/application/models.py
resolve
classmethod
resolve(data: BaseDatasetSpec | Mapping[str, Any]) -> BaseDatasetSpec
Resolve a raw or already-validated dataset payload to a concrete dataset DTO.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Raw or typed dataset payload.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BaseDatasetSpec
|
Resolved dataset spec instance.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the dataset format is missing, unsupported, or conflicts with the inferred format. |
Source code in src/evallm/application/models.py
MetricSpec
pydantic-model
DTO specifying a metric and its configuration
Fields:
Attributes
name
pydantic-field
name: str
Non-empty name under which a metric is registered.
-
API Reference
evallmapplication
config
pydantic-field
Runtime configuration for the metric or None (default), if not needed.
-
API Reference
evallmapplication
result_key
pydantic-field
result_key: str | None = None
Optional key to use in the evaluation result dictionary for this metric instance's value.
-
API Reference
evallmapplication
Functions
create
classmethod
create(
obj: Any | None = None,
*,
json_payload: str | bytes | bytearray | None = None,
**kwargs: Any,
) -> Self
Convenience factory to create DTOs from various input sources.
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The DTO's fields as a native Python object (e.g. a dict).
TYPE:
|
json_payload
|
The DTO's fields as a JSON string- or bytes-payload. |
**kwargs
|
Keyword arguments corresponding to the DTO's fields.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
An instance of the DTO created from the provided input.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If 0 or more than 1 of the input sources are provided. |
Source code in src/evallm/application/models.py
resolve_metric
resolve_metric(catalog: type[Catalog]) -> BaseMetric
Resolve the metric specification to a
BaseMetric instance.
Performs contextual validation of the DTO by:
- looking up the specified
namein the providedcatalogand - trying to instantiate the metric with the provided
config.
If either of these steps fail, an appropriate error is raised.
Metric instance's result_key
The resolved metric instance's result_key attribute is not yet set to
the value of this DTO's result_key field. This is because at this point
there's no guarantee that the provided result_key is unique among all
resolved metrics for a given evaluation request.
| PARAMETER | DESCRIPTION |
|---|---|
catalog
|
A catalog class to use for looking up the metric. |
| RETURNS | DESCRIPTION |
|---|---|
BaseMetric
|
An instance of the specified metric, if resolution and validation succeed.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the provided catalog does not implement the
|
UnknownMetricError
|
If the specified metric name is not registered in the catalog. |
MetricConfigurationError
|
If the metric cannot be instantiated from the provided config. |
Source code in src/evallm/application/models.py
Evaluator
Evaluator(request: EvaluationRequest, *, catalog: type[Catalog] = MetricsCatalog)
Component responsible for orchestrating the evaluation process.
Takes an EvaluationRequest as
initialization parameter, resolves it, and provides a run
method that executes the evaluation, lazily yielding individual
EvaluationResults for each record
in the specified dataset.
| PARAMETER | DESCRIPTION |
|---|---|
request
|
The evaluation request specifying the dataset and metrics to use for evaluation.
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
catalog |
An optional catalog class to use for
resolving metric specifications. Defaults to |
Usage
from pathlib import Path
from pprint import pprint
from evallm.application import Evaluator
from evallm.application.models import (
EvaluationRequest,
JsonlDatasetSpec,
MetricSpec,
)
from evallm.metrics import builtin # (1)!
request: EvaluationRequest = EvaluationRequest.create( # (2)!
obj={ # (7)!
"dataset": { # (3)!
"input_file": "C:/Users/.../Opus-4.6-Reasoning-3000x-filtered.jsonl",
"record_id_key": "id",
"text_key": "thinking",
},
"metrics": [ # (4)!
{
"name": "CountsMetric",
"config": {
"segments": "tokens",
},
},
{
"name": "JsonFormatMetric",
"config": {
"expected_schema": {
"type": "object",
"properties": {
"question": {"type": "string"},
"setup": {"type": "string"},
"joke": {"type": "string"},
"funniness_score": {
"type": "number",
"minimum": 0.0,
"maximum": 1.0,
},
},
"required": ["question", "joke"],
}
},
},
],
}
)
evaluator: Evaluator = Evaluator(request) # (5)!
for i, res in enumerate(evaluator.run()): # (6)!
if i > 3:
break
pprint(res.model_dump(), sort_dicts=False)
Output
{
"record_id": "orca_3452",
"results": {
"CountsMetric": 257,
"JsonFormatMetric": {
"question": False,
"setup": False,
"joke": False,
"funniness_score": False,
},
},
}
{
"record_id": "drive_minimax_m2.1_questions_220036",
"results": {
"CountsMetric": 121,
"JsonFormatMetric": {
"question": False,
"setup": False,
"joke": False,
"funniness_score": False,
},
},
}
{
"record_id": "orc_73480",
"results": {
"CountsMetric": 243,
"JsonFormatMetric": {
"question": False,
"setup": False,
"joke": False,
"funniness_score": False,
},
},
}
{
"record_id": "drive_minimax_m2.1_questions_184095",
"results": {
"CountsMetric": 181,
"JsonFormatMetric": {
"question": False,
"setup": False,
"joke": False,
"funniness_score": False,
},
},
}
- Important: Remember to import the module where the metrics that you're going to use are defined. Otherwise evaLLM won't be able to discover them!
- Construct an
EvaluationRequestprogramatically. - Define the dataset to evaluate. Here we specify a JSONL file, along with its record ID and text keys.
- Define a list of metrics to compute. Each
MetricSpecneeds a name under which the metric is registered and - depending on the metric - can optionally include runtime configuration. - Create an
Evaluatorwith the evaluation request. - Lazily iterate over the
EvaluationResults. - You could also post the same request as a JSON payload:
{ "dataset": { "input_file": "C:/Users/.../Opus-4.6-Reasoning-3000x-filtered.jsonl", "record_id_key": "id", "text_key": "thinking" }, "metrics": [ { "name": "CountsMetric", "config": { "segments": "tokens" } }, { "name": "JsonFormatMetric", "config": { "expected_schema": { "type": "object", "properties": { "question": { "type": "string" }, "setup": { "type": "string" }, "joke": { "type": "string" }, "funniness_score": { "type": "number", "minimum": 0.0, "maximum": 1.0 } }, "required": ["question", "joke"] } } } ] }
EvaluationRequest JSON schema
{'$defs': { 'JsonValue': {},
'JsonlDatasetSpec': {
'additionalProperties': false,
'description': 'DTO specifying a structured JSONL dataset to evaluate',
'properties': {
'input_file': {
'description': 'Path to a local JSONL-file containing the dataset to evaluate.',
'format': 'file-path',
'title': 'Input File',
'type': 'string'
},
'record_id_key': {
'default': '#IDX#',
'description': 'The dataset field/ column name that contains the unique identifier for each record, specified as a non-empty string. Defaults to `"#IDX#"`, which indicates that record IDs should be generated based on the record's (0-indexed) position in the dataset.',
'minLength': 1,
'title': 'Record Id Key',
'type': 'string'
},
'text_key': {
'description': 'The dataset field/ column name that contains the text to evaluate, specified as a non-empty string.',
'minLength': 1,
'title': 'Text Key',
'type': 'string'
}
},
'required': ['input_file', 'text_key'],
'title': 'JsonlDatasetSpec',
'type': 'object'
},
'MetricSpec': {
'additionalProperties': false,
'description': 'DTO specifying a metric and its configuration',
'properties': {
'name': {
'description': 'Non-empty name under which a metric is registered. !!! note "See also" - [`BaseMetric.name`](https://psandhaas.github.io/evaLLM/reference/evallm/metrics/base/#evallm.metrics.base.BaseMetric.name) - [`@register_metric`](https://psandhaas.github.io/evaLLM/reference/evallm/metrics/registry/#evallm.metrics.registry.register_metric) - [`MetricsCatalog.available`](https://psandhaas.github.io/evaLLM/reference/evallm/metrics/registry/#evallm.metrics.registry.MetricsCatalog.available)',
'minLength': 1,
'title': 'Name',
'type': 'string'
},
'config': {
'anyOf': [
{'additionalProperties': {'$ref': '#/$defs/JsonValue'}, 'type': 'object'},
{'type': 'null'}
],
'default': null,
'description': 'Runtime configuration for the metric or `null` (default), if not needed. !!! note "See also" - [`BaseMetric.config_schema`](https://psandhaas.github.io/evaLLM/reference/evallm/metrics/base/#evallm.metrics.base.BaseMetric.config_schema) - [`BaseMetric.from_config`](https://psandhaas.github.io/evaLLM/reference/evallm/metrics/base/#evallm.metrics.base.BaseMetric.from_config)',
'title': 'Config'
}
},
'required': ['name'],
'title': 'MetricSpec',
'type': 'object'}
},
'additionalProperties': false,
'description': 'DTO specifying which configuration of metrics to evaluate a given dataset on',
'properties': {
'dataset': {
'$ref': '#/$defs/JsonlDatasetSpec',
'description': 'The dataset to evaluate, specified as a [`JsonlDatasetSpec`](https://psandhaas.github.io/evaLLM/reference/evallm/application/models/#evallm.application.models.JsonlDatasetSpec).'
},
'metrics': {
'description': 'List of one or more metrics to use for evaluation, each specified as a [`MetricSpec`](https://psandhaas.github.io/evaLLM/reference/evallm/application/models/#evallm.application.models.MetricSpec).',
'items': {'$ref': '#/$defs/MetricSpec'},
'minItems': 1,
'title': 'Metrics',
'type': 'array'
}
},
'required': ['dataset', 'metrics'],
'title': 'EvaluationRequest',
'type': 'object'}
-
API Reference
evallmapplicationapplication ClassesEvaluator
| METHOD | DESCRIPTION |
|---|---|
run |
Evaluate the records in the request using the specified metrics. |
Source code in src/evallm/application/services.py
Functions
run
run() -> Iterator[EvaluationResult]
Evaluate the records in the request using the specified metrics.
This method iterates over the resolved dataset records and applies the
composite metric to each record, yielding an
EvaluationResult for each one.
| YIELDS | DESCRIPTION |
|---|---|
EvaluationResult
|
An evaluation result for each record, containing the record's unique identifier and a dictionary mapping metric result keys to their computed values.
TYPE::
|
-
API Reference
evallmapplicationapplication ClassesEvaluator
Source code in src/evallm/application/services.py
Functions
count_characters
count_characters(*, result_key: str | None = None) -> MetricSpec
Create a metric spec for counting the number of characters in the evaluated text.
| PARAMETER | DESCRIPTION |
|---|---|
result_key
|
Optional explicit result key for the metric.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MetricSpec
|
Character-count metric specification.
TYPE:
|
Source code in src/evallm/application/api.py
count_encodings
count_encodings(
model: str, *, hf_token: str | None = None, result_key: str | None = None
) -> MetricSpec
Create a metric spec for counting the number of model-specific encodings in a text.
This metric allows for specifying any
HuggingFace model to use for segmenting the text into encodings.Counting encodings
The 'hf-tokenizers' extra of evaLLM must be installed to use this metric, as
it relies on the HuggingFace tokenizers library for encoding text.
Install it with:
| PARAMETER | DESCRIPTION |
|---|---|
model
|
The name of a HuggingFace model that provides a pretrained tokenizer, which will be used to segment the text into model-specific encodings.
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
hf_token |
User access token for HuggingFace.
This is only required when specifying a
gated model to use for
encoding. Note that you can also set the
TYPE:
|
result_key |
Optional explicit result key for the metric.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MetricSpec
|
Encoding-count metric specification.
TYPE:
|
Source code in src/evallm/application/api.py
count_tokens
count_tokens(
*,
segmentation: Literal["whitespace", "wordpunct"] = "whitespace",
result_key: str | None = None,
) -> MetricSpec
Create a metric spec for counting the number of tokens in the evaluated text.
| PARAMETER | DESCRIPTION |
|---|---|
segmentation
|
Tokenization
method to use. Defaults to "whitespace". (see also:
TYPE:
|
result_key
|
Optional explicit result key for the metric.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MetricSpec
|
Token-count metric specification.
TYPE:
|
Source code in src/evallm/application/api.py
json_format
json_format(
expected_schema: Mapping[str, Any] | str,
*,
check_formats: bool = False,
result_key: str | None = None,
) -> MetricSpec
Create a metric spec for validating JSON output format.
| RETURNS | DESCRIPTION |
|---|---|
MetricSpec
|
JSON-format validation metric specification.
TYPE:
|
Source code in src/evallm/application/api.py
metric
metric(
name: str,
*,
config: Mapping[str, JsonValue] | None = None,
result_key: str | None = None,
) -> MetricSpec
Create a generic metric spec using a metric's name.
Warning
This function only performs syntactic validation so as to create canonical
MetricSpec objects. It does not guarantee the existence of the metric's
name in the catalog, nor does it validate the provided config against the
metric's config schema.
See also
MetricSpec.resolve_metric(catalog)for runtime resolution and validation of metric specs against a catalog.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name of the metric as registered in the catalog.
TYPE:
|
config
|
Optional config dict for the
metric. (see also:
|
result_key
|
Optional explicit result key for the metric.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MetricSpec
|
Canonical metric specification.
TYPE:
|