models
DTOs are implemented as immutable
BaseModels that
perform structural validation only. While this allows them to stay decoupled from
other layers, it also means that no semantic/ stateful validation is performed.
| CLASS | DESCRIPTION |
|---|---|
BaseDTO |
Abstract base class for all DTOs in the application layer. |
MetricSpec |
DTO specifying a metric and its configuration |
BaseDatasetSpec |
Abstract base class for dataset specifications. |
JsonlDatasetSpec |
DTO specifying a structured JSONL dataset to evaluate |
EvaluationRequest |
DTO specifying which configuration of metrics to evaluate a given dataset on |
DatasetRecord |
DTO representing a single record to evaluate in a dataset |
EvaluationResult |
DTO representing the evaluated metrics' results for a single record |
Classes
BaseDTO
pydantic-model
Abstract base class for all DTOs in the application layer.
Config:
extra:forbidfrozen:Truejson_schema_extra:make_crossref_resolver(docs_base_url='https://psandhaas.github.io/evaLLM/reference')json_schema_serialization_defaults_required:Truerevalidate_instances:subclass-instancesser_json_inf_nan:constantsuse_attribute_docstrings:True
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
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
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
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
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
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
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
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
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
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. |