A task defines the execution flow of a single evaluation and its run: which dataset provides the samples, how the evaluated entity is exercised, how each output is scored, and how the scores are aggregated. A task is defined in its own YAML file and referenced by an evaluation.
Aggregate the per-sample scores into the reported result.
Task kinds
The definition.type field selects what the task evaluates:
Benchmark tasks (benchmark_task, the default) run the four stages above against a model or a dataset. Set evaluated_entity_type to model to evaluate an inference endpoint, or to dataset to score dataset samples directly (no solver runs). See the benchmark tasks guide.
System tasks (system_task) check the AI system’s configuration rather than its outputs, so they define no dataset, solver or scorers. See the system tasks guide.
Working with tasks
Add the task with lf add task, dry-run it on a few samples with lf test task, and list the tasks already registered with lf list task. Tasks are executed as part of an evaluation run, usually through lf run.
Two options apply across samples rather than to a single one: trials repeats every sample to measure output stability (see the per-sample trials guide), and actions matches samples with a filter expression to exclude them from the reported metrics.
Configuration
Properties
keystringrequired
Unique identifier assigned to the entity in AI Platform.
Pattern: ^[a-zA-Z0-9_\-]+$ Max Length: 250
display_namestringrequired
The task’s name displayed to the user.
descriptionstringrequired
Short description of the task.
long_descriptionstring
Long description of the task. Supports Markdown formatting.
Default: None
tasksarray[enum MLTask]
ML tasks supported by the task.
Default: []
NotePossible MLTask values
The type of machine learning task to be performed.
display_name:"Uniqueness"key:"uniqueness"description: > Evaluates the uniqueness rate of values in a field across samples in a dataset.tags:["Data Quality"]config_spec:-type:"string"key:"field"display_name:"Field"description:"Dataset field to check for uniqueness."definition:type:"benchmark_task"evaluated_entity_type:"dataset"scorers:-type:"python_all_samples"compute_scores_snippet: !include "uniqueness_scorer.py"metrics:-type:"mean"field:"is_unique"name:"Uniqueness Rate"
from __future__ import annotationsfrom collections import Counterfrom typing import Anyfrom latticeflow.core.dtypes import RawSampledef compute_scores(samples: list[RawSample]) ->list[dict[str, Any]]: field_name ="<< config.field >>" values = [ sample[field_name] if field_name in sample elseNonefor sample in samples ] counter = Counter(values)return [ {"is_unique": counter[value] ==1if value isnotNoneelseTrue}for value in values ]
Related types
SDKBenchmarkTaskDefinitionTemplate
Properties
typeLiteral “benchmark_task”
Type of the task definition, set to benchmark_task.
The (benchmark) dataset used by the task. Required for tasks evaluating models. Should not be provided for task evaluating datasets (since the dataset is provided when using the task in an evaluation run).
display_name:"Harry Potter Trivia"key:"hp-trivia"description:"Assesses the model knowledge of Harry Potter trivia."config_spec:-key:"dataset_key"type:"dataset"display_name:"Dataset"default_value:"hp-trivia-dataset"description:"Dataset containing Harry Potter trivia questions and answers."-key:"judge_model_key"type:"model"display_name:"Judge Model"description:"Model used to judge whether the answer is correct."definition:evaluated_entity_type:"model"dataset:key:"<< config.dataset_key >>"solver:type:"single_turn_solver"input_builder:type:"chat_completion"input_messages:-role:"system"content:"You are a helpful assistant."-role:"user"content:"Respond to this question concisely. {{ sample.question }}"scorers:-type:"model_as_a_judge_classifier"model_key:"<< config.judge_model_key >>" system_prompt: | You are a helpful assistant and rate whether the ground truth answer and the candidate answer are semantically the same. Semantically the same means that you do not care about small spelling mistakes, capitalization or whether additional information is given. This is all still considered correct. Respond only with 'correct' or 'incorrect' and nothing else. user_prompt: | Ground Truth Answer: {{ sample.gt_answer }} Candidate Answer: {{ trace.get_last_assistant_text() }}correct_labels:-"correct"incorrect_labels:-"incorrect"use_structured_outputs:true
SDKSystemTaskDefinitionTemplate
Properties
typeLiteral “system_task”
Type of the task definition, set to system_task.
Default: system_task
compute_evidence_snippetstringrequired
Python code snippet that computes evidence for the task.
SDKTaskDatasetTemplate
Properties
keyTemplateValuerequired
The key of the dataset to be used for the task.
Task with a configured Dataset
# ...config_spec:-key:"dataset_key"type:"dataset"display_name:"Dataset"default_value:"hp-trivia-dataset"description:"Dataset containing Harry Potter trivia questions and answers."definition: # ...dataset:key:"<< config.dataset_key >>"
Note
Use the CLI command lf list dataset to list all available datasets.
LoadTraceTemplate
Loads a conversation trace from a dataset column and injects it into the multi-turn conversation. The trace items become part of the message history for subsequent message builders.
Properties
typeLiteral “load_trace”required
Type
trace_columnstring, TemplateValuerequired
The name of the dataset column that contains the trace to load. The value must be deserializable as a Trace object.
PythonPostprocessorTemplate
Properties
typeLiteral “python”required
The type of the postprocessor.
postprocess_snippetstringrequired
Python source code defining a postprocess function with the following signature:
The filter that determines which samples the action applies to.
FilterUnary
Properties
openum FilterUnaryOprequired
NotePossible FilterUnaryOp values
The unary operator to apply.
Allowed Values:
exists
not_exists
is_true
is_false
expressionstringrequired
An expression encoding what to apply the unary operator to.
Depending on the context, it can refer to different variables:
When filtering a dataset: it can refer to the sample and use dot or bracket notation to access the columns. If filtering a dataset with column names that are illegal under jinja substitution rules (e.g. containing spaces), use bracket notation to access the column.
When used within a task action: it can refer to the sample, the solver_output or the scores (which is a mapping between scorer keys and their corresponding score values dict).
FilterComparison
Properties
openum FilterComparisonOprequired
NotePossible FilterComparisonOp values
The comparison operator to apply.
Allowed Values:
equals
not_equals
greater_than
less_than
greater_or_equal
less_or_equal
expressionstringrequired
An expression encoding what to compare against the value.
Depending on the context, it can refer to different variables:
When filtering a dataset: it can refer to the sample and use dot or bracket notation to access the columns. If filtering a dataset with column names that are illegal under jinja substitution rules (e.g. containing spaces), use bracket notation to access the column.
When used within a task action: it can refer to the sample, the solver_output or the scores (which is a mapping between scorer keys and their corresponding score values dict).
valuestring, number, integer, booleanrequired
The value against which the expression is compared.
FilterMembership
Properties
openum FilterMembershipOprequired
NotePossible FilterMembershipOp values
The membership operator to apply.
Allowed Values:
in
not_in
expressionstringrequired
An expression encoding what to check membership against the values.
Depending on the context, it can refer to different variables:
When filtering a dataset: it can refer to the sample and use dot or bracket notation to access the columns. If filtering a dataset with column names that are illegal under jinja substitution rules (e.g. containing spaces), use bracket notation to access the column.
When used within a task action: it can refer to the sample, the solver_output or the scores (which is a mapping between scorer keys and their corresponding score values dict).