mlflow.entities

The mlflow.entities module defines entities returned by the MLflow REST API.

class mlflow.entities.Assessment(trace_id: str, name: str, source: AssessmentSource, create_time_ms: int, last_update_time_ms: int, expectation: Optional[mlflow.entities.assessment.Expectation] = None, feedback: Optional[mlflow.entities.assessment.Feedback] = None, rationale: Optional[str] = None, metadata: Optional[dict] = None, error: Optional[AssessmentError] = None, span_id: Optional[str] = None, _assessment_id: Optional[str] = None)[source]

Note

Experimental: This class may change or be removed in a future release without warning.

Assessment object associated with a trace.

Assessment are an abstraction for annotating two different types of labels on traces:

  • Expectations: A label that represents the expected value for a particular operation.

    For example, an expected answer for a user question from a chatbot.

  • Feedback: A label that represents the feedback on the quality of the operation.

    Feedback can come from different sources, such as human judges, heuristic scorers, or LLM-as-a-Judge.

To create an assessment with these labels, use the mlflow.log_expectation() or mlflow.log_feedback() functions. Do not create an assessment object directly using the constructor.

Parameters
  • trace_id – The ID of the trace associated with the assessment.

  • name – The name of the assessment.

  • source – The source of the assessment.

  • create_time_ms – The creation time of the assessment in milliseconds.

  • last_update_time_ms – The last update time of the assessment in milliseconds.

  • expectation – The expectation value of the assessment.

  • feedback – The feedback value of the assessment. Only one of expectation, feedback or error should be specified.

  • rationale – The rationale / justification for the assessment.

  • metadata – The metadata associated with the assessment.

  • error – An error object representing any issues during generating the assessment. If this is set, the assessment should not contain expectation or feedback.

  • span_id – The ID of the span associated with the assessment, if the assessment should be associated with a particular span in the trace.

  • _assessment_id – The ID of the assessment. This must be generated in the backend.

property assessment_id
create_time_ms: int
error: Optional[AssessmentError] = None
expectation: Optional[mlflow.entities.assessment.Expectation] = None
feedback: Optional[mlflow.entities.assessment.Feedback] = None
classmethod from_proto(proto)[source]
last_update_time_ms: int
metadata: Optional[dict] = None
name: str
rationale: Optional[str] = None
source: AssessmentSource
span_id: Optional[str] = None
to_dictionary()[source]
to_proto()[source]
trace_id: str
class mlflow.entities.AssessmentError(error_code: str, error_message: Optional[str] = None)[source]

Note

Experimental: This class may change or be removed in a future release without warning.

Error object representing any issues during generating the assessment.

For example, if the LLM-as-a-Judge fails to generate an feedback, you can log an error with the error code and message as shown below:

from mlflow.entities import AssessmentError

error = AssessmentError(
    error_code="RATE_LIMIT_EXCEEDED",
    error_message="Rate limit for the judge exceeded.",
)

mlflow.log_feedback(
    trace_id="1234",
    name="faithfulness",
    source=AssessmentSourceType.LLM_JUDGE,
    error=error,
    # Skip setting value when an error is present
)
Parameters
  • error_code – The error code.

  • error_message – The detailed error message. Optional.

error_code: str
error_message: Optional[str] = None
classmethod from_proto(proto)[source]
to_proto()[source]
class mlflow.entities.AssessmentSource(source_type: str, source_id: Optional[str] = None)[source]

Note

Experimental: This class may change or be removed in a future release without warning.

Source of an assessment (human, LLM as a judge with GPT-4, etc).

Parameters
  • source_type – The type of the assessment source. Must be one of the values in the AssessmentSourceType enum.

  • source_id – An identifier for the source, e.g. user ID or LLM judge ID.

classmethod from_dictionary(source_dict: dict)AssessmentSource[source]
classmethod from_proto(proto)[source]
source_id: Optional[str] = None
source_type: str
to_dictionary()dict[source]
to_proto()[source]
class mlflow.entities.AssessmentSourceType(source_type: str)[source]

Note

Experimental: This class may change or be removed in a future release without warning.

CODE = 'CODE'
HUMAN = 'HUMAN'
LLM_JUDGE = 'LLM_JUDGE'
SOURCE_TYPE_UNSPECIFIED = 'SOURCE_TYPE_UNSPECIFIED'
classmethod from_proto(proto_source_type)str[source]
class mlflow.entities.Dataset(name: str, digest: str, source_type: str, source: str, schema: Optional[str] = None, profile: Optional[str] = None)[source]

Dataset object associated with an experiment.

property digest

String digest of the dataset.

classmethod from_proto(proto)[source]
property name

String name of the dataset.

property profile

String profile of the dataset.

property schema

String schema of the dataset.

property source

String source of the dataset.

property source_type

String source_type of the dataset.

to_dictionary()[source]
to_proto()[source]
class mlflow.entities.DatasetInput(dataset: Dataset, tags: Optional[list] = None)[source]

DatasetInput object associated with an experiment.

property dataset

Dataset.

classmethod from_proto(proto)[source]
property tags

Array of input tags.

to_dictionary()[source]
to_proto()[source]
class mlflow.entities.Document(page_content: str, metadata: dict = <factory>, id: Optional[str] = None)[source]

An entity used in MLflow Tracing to represent retrieved documents in a RETRIEVER span.

Parameters
  • page_content – The content of the document.

  • metadata – A dictionary of metadata associated with the document.

  • id – The ID of the document.

classmethod from_langchain_document(document)[source]
classmethod from_llama_index_node_with_score(node_with_score)[source]
id: Optional[str] = None
metadata: dict
page_content: str
to_dict()[source]
class mlflow.entities.Experiment(experiment_id, name, artifact_location, lifecycle_stage, tags=None, creation_time=None, last_update_time=None)[source]

Experiment object.

DEFAULT_EXPERIMENT_NAME = 'Default'
property artifact_location

String corresponding to the root artifact URI for the experiment.

property creation_time
property experiment_id

String ID of the experiment.

classmethod from_proto(proto)[source]
property last_update_time
property lifecycle_stage

Lifecycle stage of the experiment. Can either be ‘active’ or ‘deleted’.

property name

String name of the experiment.

property tags

Tags that have been set on the experiment.

to_proto()[source]
class mlflow.entities.ExperimentTag(key, value)[source]

Tag object associated with an experiment.

classmethod from_proto(proto)[source]
property key

String name of the tag.

to_proto()[source]
property value

String value of the tag.

class mlflow.entities.FileInfo(path, is_dir, file_size)[source]

Metadata about a file or directory.

property file_size

Size of the file or directory. If the FileInfo is a directory, returns None.

classmethod from_proto(proto)[source]
property is_dir

Whether the FileInfo corresponds to a directory.

property path

String path of the file or directory.

to_proto()[source]
class mlflow.entities.InputTag(key: str, value: str)[source]

Input tag object associated with a dataset.

classmethod from_proto(proto)[source]
property key

String name of the input tag.

to_proto()[source]
property value

String value of the input tag.

class mlflow.entities.LifecycleStage[source]
ACTIVE = 'active'
DELETED = 'deleted'
classmethod is_valid(lifecycle_stage)[source]
classmethod matches_view_type(view_type, lifecycle_stage)[source]
classmethod view_type_to_stages(view_type=3)[source]
class mlflow.entities.LiveSpan(otel_span: opentelemetry.trace.span.Span, request_id: str, span_type: str = 'UNKNOWN')[source]

A “live” version of the Span class.

The live spans are those being created and updated during the application runtime. When users start a new span using the tracing APIs within their code, this live span object is returned to get and set the span attributes, status, events, and etc.

add_event(event: SpanEvent)[source]

Add an event to the span.

Parameters

event – The event to add to the span. This should be a SpanEvent object.

from_dict(data: dict)Span[source]

Create a Span object from the given dictionary.

set_attribute(key: str, value: Any)[source]

Set a single attribute to the span.

set_attributes(attributes: dict)[source]

Set the attributes to the span. The attributes must be a dictionary of key-value pairs. This method is additive, i.e. it will add new attributes to the existing ones. If an attribute with the same key already exists, it will be overwritten.

set_inputs(inputs: Any)[source]

Set the input values to the span.

set_outputs(outputs: Any)[source]

Set the output values to the span.

set_span_type(span_type: str)[source]

Set the type of the span.

set_status(status: Union[SpanStatusCode, str])[source]

Set the status of the span.

Parameters

status – The status of the span. This can be a SpanStatus object or a string representing of the status code defined in SpanStatusCode e.g. "OK", "ERROR".

class mlflow.entities.Metric(key, value, timestamp, step)[source]

Metric object.

classmethod from_dictionary(metric_dict)[source]

Create a Metric object from a dictionary.

Parameters

metric_dict (dict) – Dictionary containing metric information.

Returns

The Metric object created from the dictionary.

Return type

Metric

classmethod from_proto(proto)[source]
property key

String key corresponding to the metric name.

property step

Integer metric step (x-coordinate).

property timestamp

Metric timestamp as an integer (milliseconds since the Unix epoch).

to_dictionary()[source]

Convert the Metric object to a dictionary.

Returns

The Metric object represented as a dictionary.

Return type

dict

to_proto()[source]
property value

Float value of the metric.

class mlflow.entities.NoOpSpan[source]

No-op implementation of the Span interface.

This instance should be returned from the mlflow.start_span context manager when span creation fails. This class should have exactly the same interface as the Span so that user’s setter calls do not raise runtime errors.

E.g.

with mlflow.start_span("span_name") as span:
    # Even if the span creation fails, the following calls should pass.
    span.set_inputs({"x": 1})
    # Do something
add_event(event: SpanEvent)[source]
property context
end()[source]
property end_time_ns

The end time of the span in nanosecond.

property name

The name of the span.

property parent_id

The span ID of the parent span.

property request_id

No-op span returns a special request ID to distinguish it from the real spans.

set_attribute(key: str, value: Any)[source]
set_attributes(attributes: dict)[source]
set_inputs(inputs: dict)[source]
set_outputs(outputs: dict)[source]
set_status(status: SpanStatus)[source]
property span_id

The ID of the span. This is only unique within a trace.

property start_time_ns

The start time of the span in nanosecond.

property status

The status of the span.

class mlflow.entities.Param(key, value)[source]

Parameter object.

classmethod from_proto(proto)[source]
property key

String key corresponding to the parameter name.

to_proto()[source]
property value

String value of the parameter.

class mlflow.entities.Prompt(name: str, version: int, template: str, commit_message: Optional[str] = None, creation_timestamp: Optional[int] = None, version_metadata: Optional[dict] = None, prompt_tags: Optional[dict] = None, aliases: Optional[list] = None)[source]

An entity representing a prompt (template) for GenAI applications.

Parameters
  • name – The name of the prompt.

  • version – The version number of the prompt.

  • template – The template text of the prompt. It can contain variables enclosed in double curly braces, e.g. {{variable}}, which will be replaced with actual values by the format method. MLflow use the same variable naming rules same as Jinja2 https://jinja.palletsprojects.com/en/stable/api/#notes-on-identifiers

  • commit_message – The commit message for the prompt version. Optional.

  • creation_timestamp – Timestamp of the prompt creation. Optional.

  • version_metadata – A dictionary of metadata associated with the prompt version. This is useful for storing version-specific information, such as the author of the changes. Optional.

  • prompt_tags – A dictionary of tags associated with the entire prompt. This is different from the version_metadata as it is not tied to a specific version of the prompt.

property commit_message

Return the commit message of the prompt version.

format(allow_partial: bool = False, **kwargs)Union[Prompt, str][source]

Format the template text with the given keyword arguments. By default, it raises an error if there are missing variables. To format the prompt text partially, set allow_partial=True.

Example:

prompt = Prompt("my-prompt", 1, "Hello, {{title}} {{name}}!")
formatted = prompt.format(title="Ms", name="Alice")
print(formatted)
# Output: "Hello, Ms Alice!"

# Partial formatting
formatted = prompt.format(title="Ms", allow_partial=True)
print(formatted)
# Output: Prompt(name=my-prompt, version=1, template="Hello, Ms {{name}}!")
Parameters
  • allow_partial – If True, allow partial formatting of the prompt text. If False, raise an error if there are missing variables.

  • kwargs – Keyword arguments to replace the variables in the template.

classmethod from_model_version(model_version: ModelVersion, prompt_tags: Optional[dict] = None)Prompt[source]

Create a Prompt object from a ModelVersion object.

Parameters
  • model_version – The ModelVersion object to convert to a Prompt.

  • prompt_tags – The prompt-level tags (from RegisteredModel). Optional.

property run_ids

Get the run IDs associated with the prompt.

property tags

Return the prompt-level tags (from RegisteredModel).

property template

Return the template text of the prompt.

to_single_brace_format()str[source]

Convert the template text to single brace format. This is useful for integrating with other systems that use single curly braces for variable replacement, such as LangChain’s prompt template. Default is False.

property uri

Return the URI of the prompt.

property variables

Return a list of variables in the template text. The value must be enclosed in double curly braces, e.g. {{variable}}.

property version_metadata

Return the tags of the prompt as a dictionary.

class mlflow.entities.Run(run_info: RunInfo, run_data: RunData, run_inputs: Optional[RunInputs] = None)[source]

Run object.

property data

The run data, including metrics, parameters, and tags.

Return type

mlflow.entities.RunData

classmethod from_proto(proto)[source]
property info

The run metadata, such as the run id, start time, and status.

Return type

mlflow.entities.RunInfo

property inputs

The run inputs, including dataset inputs

Return type

mlflow.entities.RunInputs

to_dictionary()dict[source]
to_proto()[source]
class mlflow.entities.RunData(metrics=None, params=None, tags=None)[source]

Run data (metrics and parameters).

classmethod from_proto(proto)[source]
property metrics

Dictionary of string key -> metric value for the current run. For each metric key, the metric value with the latest timestamp is returned. In case there are multiple values with the same latest timestamp, the maximum of these values is returned.

property params

Dictionary of param key (string) -> param value for the current run.

property tags

Dictionary of tag key (string) -> tag value for the current run.

to_dictionary()[source]
to_proto()[source]
class mlflow.entities.RunInfo(run_uuid, experiment_id, user_id, status, start_time, end_time, lifecycle_stage, artifact_uri=None, run_id=None, run_name=None)[source]

Metadata about a run.

property artifact_uri[source]

String root artifact URI of the run.

property end_time[source]

End time of the run, in number of milliseconds since the UNIX epoch.

property experiment_id

String ID of the experiment for the current run.

classmethod from_proto(proto)[source]
classmethod get_orderable_attributes()[source]
classmethod get_searchable_attributes()[source]
property lifecycle_stage

One of the values in LifecycleStage describing the lifecycle stage of the run.

property run_id[source]

String containing run id.

property run_name[source]

String containing run name.

property run_uuid

[Deprecated, use run_id instead] String containing run UUID.

property start_time[source]

Start time of the run, in number of milliseconds since the UNIX epoch.

property status[source]

One of the values in mlflow.entities.RunStatus describing the status of the run.

to_proto()[source]
property user_id[source]

String ID of the user who initiated this run.

class mlflow.entities.RunInputs(dataset_inputs: list)[source]

RunInputs object.

property dataset_inputs

Array of dataset inputs.

classmethod from_proto(proto)[source]
to_dictionary()dict[source]
to_proto()[source]
class mlflow.entities.RunStatus[source]

Enum for status of an mlflow.entities.Run.

FAILED = 4
FINISHED = 3
KILLED = 5
RUNNING = 1
SCHEDULED = 2
static all_status()[source]
static from_string(status_str)[source]
static is_terminated(status)[source]
static to_string(status)[source]
class mlflow.entities.RunTag(key, value)[source]

Tag object associated with a run.

classmethod from_proto(proto)[source]
property key

String name of the tag.

to_proto()[source]
property value

String value of the tag.

class mlflow.entities.SourceType[source]

Enum for originating source of a mlflow.entities.Run.

JOB = 2
LOCAL = 4
NOTEBOOK = 1
PROJECT = 3
RECIPE = 6
SOURCETYPE_TO_STRING = {1: 'NOTEBOOK', 2: 'JOB', 3: 'PROJECT', 4: 'LOCAL', 5: 'UNKNOWN', 6: 'RECIPE'}
UNKNOWN = 5
static from_string(status_str)[source]
static to_string(status)[source]
class mlflow.entities.Span(otel_span: opentelemetry.sdk.trace.ReadableSpan)[source]

A span object. A span represents a unit of work or operation and is the building block of Traces.

This Span class represents immutable span data that is already finished and persisted. The “live” span that is being created and updated during the application runtime is represented by the LiveSpan subclass.

property attributes

Get all attributes of the span.

Returns

A dictionary of all attributes of the span.

property end_time_ns

The end time of the span in nanosecond.

property events

Get all events of the span.

Returns

A list of all events of the span.

classmethod from_dict(data: dict)Span[source]

Create a Span object from the given dictionary.

get_attribute(key: str)Optional[Any][source]

Get a single attribute value from the span.

Parameters

key – The key of the attribute to get.

Returns

The value of the attribute if it exists, otherwise None.

property inputs

The input values of the span.

property name

The name of the span.

property outputs

The output values of the span.

property parent_id

The span ID of the parent span.

property request_id

The request ID of the span, a unique identifier for the trace it belongs to. Request ID is equivalent to the trace ID in OpenTelemetry, but generated differently by the tracing backend.

property span_id

The ID of the span. This is only unique within a trace.

property span_type

The type of the span.

property start_time_ns

The start time of the span in nanosecond.

property status

The status of the span.

to_dict()[source]
to_proto()[source]

Convert into OTLP compatible proto object to sent to the Databricks Trace Server.

class mlflow.entities.SpanEvent(name: str, timestamp: int = <factory>, attributes: dict = <factory>)[source]

An event that records a specific occurrences or moments in time during a span, such as an exception being thrown. Compatible with OpenTelemetry.

Parameters
  • name – Name of the event.

  • timestamp – The exact time the event occurred, measured in microseconds. If not provided, the current time will be used.

  • attributes – A collection of key-value pairs representing detailed attributes of the event, such as the exception stack trace. Attributes value must be one of [str, int, float, bool, bytes] or a sequence of these types.

attributes: dict
classmethod from_exception(exception: Exception)[source]

Create a span event from an exception.

json()[source]
name: str
timestamp: int
to_proto()[source]

Convert into OTLP compatible proto object to sent to the Databricks Trace Server.

class mlflow.entities.SpanStatus(status_code: SpanStatusCode, description: str = '')[source]

Status of the span or the trace.

Parameters
  • status_code – The status code of the span or the trace. This must be one of the values of the mlflow.entities.SpanStatusCode enum or a string representation of it like “OK”, “ERROR”.

  • description – Description of the status. This should be only set when the status is ERROR, otherwise it will be ignored.

description: str = ''
status_code: SpanStatusCode
class mlflow.entities.SpanStatusCode(value)[source]

Enum for status code of a span

ERROR = 'ERROR'
OK = 'OK'
UNSET = 'UNSET'
class mlflow.entities.SpanType[source]

Predefined set of span types.

AGENT = 'AGENT'
CHAIN = 'CHAIN'
CHAT_MODEL = 'CHAT_MODEL'
EMBEDDING = 'EMBEDDING'
LLM = 'LLM'
PARSER = 'PARSER'
RERANKER = 'RERANKER'
RETRIEVER = 'RETRIEVER'
TOOL = 'TOOL'
UNKNOWN = 'UNKNOWN'
class mlflow.entities.Trace(info: TraceInfo, data: TraceData)[source]

A trace object.

Parameters
  • info – A lightweight object that contains the metadata of a trace.

  • data – A container object that holds the spans data of a trace.

data: TraceData
classmethod from_dict(trace_dict: dict)Trace[source]
classmethod from_json(trace_json: str)Trace[source]
info: TraceInfo
static pandas_dataframe_columns()list[source]
search_spans(span_type: Optional[SpanType] = None, name: Optional[Union[str, re.Pattern]] = None)list[source]

Search for spans that match the given criteria within the trace.

Parameters
  • span_type – The type of the span to search for.

  • name – The name of the span to search for. This can be a string or a regular expression.

Returns

A list of spans that match the given criteria. If there is no match, an empty list is returned.

import mlflow
import re
from mlflow.entities import SpanType


@mlflow.trace(span_type=SpanType.CHAIN)
def run(x: int) -> int:
    x = add_one(x)
    x = add_two(x)
    x = multiply_by_two(x)
    return x


@mlflow.trace(span_type=SpanType.TOOL)
def add_one(x: int) -> int:
    return x + 1


@mlflow.trace(span_type=SpanType.TOOL)
def add_two(x: int) -> int:
    return x + 2


@mlflow.trace(span_type=SpanType.TOOL)
def multiply_by_two(x: int) -> int:
    return x * 2


# Run the function and get the trace
y = run(2)
trace = mlflow.get_last_active_trace()

# 1. Search spans by name (exact match)
spans = trace.search_spans(name="add_one")
print(spans)
# Output: [Span(name='add_one', ...)]

# 2. Search spans by name (regular expression)
pattern = re.compile(r"add.*")
spans = trace.search_spans(name=pattern)
print(spans)
# Output: [Span(name='add_one', ...), Span(name='add_two', ...)]

# 3. Search spans by type
spans = trace.search_spans(span_type=SpanType.LLM)
print(spans)
# Output: [Span(name='run', ...)]

# 4. Search spans by name and type
spans = trace.search_spans(name="add_one", span_type=SpanType.TOOL)
print(spans)
# Output: [Span(name='add_one', ...)]
to_dict()dict[source]
to_json(pretty=False)str[source]
to_pandas_dataframe_row()dict[source]
to_proto()[source]

Convert into a proto object to sent to the Databricks Trace Server.

class mlflow.entities.TraceData(spans: list = <factory>, request: Optional[str] = None, response: Optional[str] = None)[source]

A container object that holds the spans data of a trace.

Parameters
  • spans – List of spans that are part of the trace.

  • request – Input data for the entire trace. Equivalent to the input of the root span but added for ease of access. Stored as a JSON string.

  • response – Output data for the entire trace. Equivalent to the output of the root span. Stored as a JSON string.

classmethod from_dict(d)[source]
property intermediate_outputs

Returns intermediate outputs produced by the model or agent while handling the request. There are mainly two flows to return intermediate outputs: 1. When a trace is generate by the mlflow.log_trace API, return intermediate_outputs attribute of the span. 2. When a trace is created normally with a tree of spans, aggregate the outputs of non-root spans.

request: Optional[str] = None
response: Optional[str] = None
spans: list
to_dict()dict[source]
class mlflow.entities.TraceInfo(request_id: str, experiment_id: str, timestamp_ms: int, execution_time_ms: Optional[int], status: mlflow.entities.trace_status.TraceStatus, request_metadata: dict = <factory>, tags: dict = <factory>, assessments: list = <factory>)[source]

Metadata about a trace.

Parameters
  • request_id – id of the trace.

  • experiment_id – id of the experiment.

  • timestamp_ms – start time of the trace, in milliseconds.

  • execution_time_ms – duration of the trace, in milliseconds.

  • status – status of the trace.

  • request_metadata – Key-value pairs associated with the trace. Request metadata are designed for immutable values like run ID associated with the trace.

  • tags – Tags associated with the trace. Tags are designed for mutable values like trace name, that can be updated by the users after the trace is created, unlike request_metadata.

assessments: list
execution_time_ms: Optional[int]
experiment_id: str
classmethod from_dict(trace_info_dict)[source]

Convert trace info dictionary to TraceInfo object.

classmethod from_proto(proto, assessments=None)[source]
request_id: str
request_metadata: dict
status: mlflow.entities.trace_status.TraceStatus
tags: dict
timestamp_ms: int
to_dict()[source]

Convert trace info to a dictionary for persistence. Update status field to the string value for serialization.

to_proto()[source]
to_v3_proto(request: Optional[str], response: Optional[str])[source]

Convert into the V3 TraceInfo proto object.

class mlflow.entities.ViewType[source]

Enum to filter requested experiment types.

ACTIVE_ONLY = 1
ALL = 3
DELETED_ONLY = 2
classmethod from_proto(proto_view_type)[source]
classmethod from_string(view_str)[source]
classmethod to_proto(view_type)[source]
classmethod to_string(view_type)[source]
class mlflow.entities.model_registry.ModelVersion(name, version, creation_timestamp, last_updated_timestamp=None, description=None, user_id=None, current_stage=None, source=None, run_id=None, status='READY', status_message=None, tags=None, run_link=None, aliases=None)[source]

MLflow entity for Model Version.

property aliases

List of aliases (string) for the current model version.

property creation_timestamp

Integer. Model version creation timestamp (milliseconds since the Unix epoch).

property current_stage

String. Current stage of this model version.

property description

String. Description

classmethod from_proto(proto)[source]
property last_updated_timestamp

Integer. Timestamp of last update for this model version (milliseconds since the Unix epoch).

property name

String. Unique name within Model Registry.

property run_id

String. MLflow run ID that generated this model.

String. MLflow run link referring to the exact run that generated this model version.

property source

String. Source path for the model.

property status

String. Current Model Registry status for this model.

property status_message

String. Descriptive message for error status conditions.

property tags

Dictionary of tag key (string) -> tag value for the current model version.

to_proto()[source]
property user_id

String. User ID that created this model version.

property version
class mlflow.entities.model_registry.ModelVersionSearch(*args, **kwargs)[source]
aliases()[source]

List of aliases (string) for the current model version.

tags()[source]

Dictionary of tag key (string) -> tag value for the current model version.

class mlflow.entities.model_registry.ModelVersionTag(key, value)[source]

Tag object associated with a model version.

classmethod from_proto(proto)[source]
property key

String name of the tag.

to_proto()[source]
property value

String value of the tag.

class mlflow.entities.model_registry.Prompt(name: str, version: int, template: str, commit_message: Optional[str] = None, creation_timestamp: Optional[int] = None, version_metadata: Optional[dict] = None, prompt_tags: Optional[dict] = None, aliases: Optional[list] = None)[source]

An entity representing a prompt (template) for GenAI applications.

Parameters
  • name – The name of the prompt.

  • version – The version number of the prompt.

  • template – The template text of the prompt. It can contain variables enclosed in double curly braces, e.g. {{variable}}, which will be replaced with actual values by the format method. MLflow use the same variable naming rules same as Jinja2 https://jinja.palletsprojects.com/en/stable/api/#notes-on-identifiers

  • commit_message – The commit message for the prompt version. Optional.

  • creation_timestamp – Timestamp of the prompt creation. Optional.

  • version_metadata – A dictionary of metadata associated with the prompt version. This is useful for storing version-specific information, such as the author of the changes. Optional.

  • prompt_tags – A dictionary of tags associated with the entire prompt. This is different from the version_metadata as it is not tied to a specific version of the prompt.

property commit_message

Return the commit message of the prompt version.

format(allow_partial: bool = False, **kwargs)Union[Prompt, str][source]

Format the template text with the given keyword arguments. By default, it raises an error if there are missing variables. To format the prompt text partially, set allow_partial=True.

Example:

prompt = Prompt("my-prompt", 1, "Hello, {{title}} {{name}}!")
formatted = prompt.format(title="Ms", name="Alice")
print(formatted)
# Output: "Hello, Ms Alice!"

# Partial formatting
formatted = prompt.format(title="Ms", allow_partial=True)
print(formatted)
# Output: Prompt(name=my-prompt, version=1, template="Hello, Ms {{name}}!")
Parameters
  • allow_partial – If True, allow partial formatting of the prompt text. If False, raise an error if there are missing variables.

  • kwargs – Keyword arguments to replace the variables in the template.

classmethod from_model_version(model_version: ModelVersion, prompt_tags: Optional[dict] = None)Prompt[source]

Create a Prompt object from a ModelVersion object.

Parameters
  • model_version – The ModelVersion object to convert to a Prompt.

  • prompt_tags – The prompt-level tags (from RegisteredModel). Optional.

property run_ids

Get the run IDs associated with the prompt.

property tags

Return the prompt-level tags (from RegisteredModel).

property template

Return the template text of the prompt.

to_single_brace_format()str[source]

Convert the template text to single brace format. This is useful for integrating with other systems that use single curly braces for variable replacement, such as LangChain’s prompt template. Default is False.

property uri

Return the URI of the prompt.

property variables

Return a list of variables in the template text. The value must be enclosed in double curly braces, e.g. {{variable}}.

property version_metadata

Return the tags of the prompt as a dictionary.

class mlflow.entities.model_registry.RegisteredModel(name, creation_timestamp=None, last_updated_timestamp=None, description=None, latest_versions=None, tags=None, aliases=None)[source]

MLflow entity for Registered Model.

property aliases

Dictionary of aliases (string) -> version for the current registered model.

property creation_timestamp

Integer. Model version creation timestamp (milliseconds since the Unix epoch).

property description

String. Description

classmethod from_proto(proto)[source]
property last_updated_timestamp

Integer. Timestamp of last update for this model version (milliseconds since the Unix epoch).

property latest_versions

List of the latest mlflow.entities.model_registry.ModelVersion instances for each stage.

property name

String. Registered model name.

property tags

Dictionary of tag key (string) -> tag value for the current registered model.

to_proto()[source]
class mlflow.entities.model_registry.RegisteredModelAlias(alias, version)[source]

Alias object associated with a registered model.

property alias

String name of the alias.

classmethod from_proto(proto)[source]
to_proto()[source]
property version

String model version number that the alias points to.

class mlflow.entities.model_registry.RegisteredModelSearch(*args, **kwargs)[source]
aliases()[source]

Dictionary of aliases (string) -> version for the current registered model.

tags()[source]

Dictionary of tag key (string) -> tag value for the current registered model.

class mlflow.entities.model_registry.RegisteredModelTag(key, value)[source]

Tag object associated with a registered model.

classmethod from_proto(proto)[source]
property key

String name of the tag.

to_proto()[source]
property value

String value of the tag.

class mlflow.store.entities.PagedList(items: list, token)[source]

Wrapper class around the base Python List type. Contains an additional token string attribute that can be passed to the pagination API that returned this list to fetch additional elements, if any are available

to_list()[source]