The add_tags() function allows you to attach tags to various ZenML resources including pipelines, runs, artifacts, and more.
Signature
def add_tags (
tags : Union[ str , Tag, List[Union[ str , Tag]]],
# Pipeline parameters
pipeline : Optional[Union[ UUID , str ]] = None ,
# Run parameters
run : Optional[Union[ UUID , str ]] = None ,
# Run template parameters
run_template : Optional[Union[ UUID , str ]] = None ,
# Snapshot parameters
snapshot : Optional[Union[ UUID , str ]] = None ,
# Deployment parameters
deployment : Optional[Union[ UUID , str ]] = None ,
# Artifact parameters
artifact : Optional[Union[ UUID , str ]] = None ,
# Artifact version parameters
artifact_version_id : Optional[ UUID ] = None ,
artifact_name : Optional[ str ] = None ,
artifact_version : Optional[ str ] = None ,
infer_artifact : Optional[ bool ] = None ,
) -> None
Parameters
tags
Union[str, Tag, List[Union[str, Tag]]]
required
The tag(s) to add. Can be a string, a Tag object, or a list of either.
The ID or name of the pipeline.
The ID, name, or prefix of the pipeline run.
The ID or name of the run template.
The ID or name of the deployment.
The ID or name of the artifact.
The ID of a specific artifact version.
The name of the artifact (used with artifact_version or infer_artifact).
The version of the artifact.
Whether to infer the artifact from the step context.
Examples
Tag Current Pipeline Run
from zenml import step, add_tags
@step
def training_step () -> None :
# Perform training
accuracy = 0.95
# Tag the current run based on performance
if accuracy > 0.9 :
add_tags([ "high-performance" , "production-ready" ])
else :
add_tags([ "needs-improvement" ])
Tag Output Artifact
from zenml import step, add_tags
import pandas as pd
@step
def process_data () -> pd.DataFrame:
df = pd.DataFrame({ "data" : range ( 100 )})
# Tag the output artifact
add_tags(
tags = [ "processed" , "v2" , "production" ],
infer_artifact = True
)
return df
Tag Specific Output
from typing import Tuple, Annotated
from zenml import step, add_tags
import pandas as pd
@step
def split_data () -> Tuple[
Annotated[pd.DataFrame, "train" ],
Annotated[pd.DataFrame, "test" ],
]:
train = pd.DataFrame({ "x" : range ( 800 )})
test = pd.DataFrame({ "x" : range ( 200 )})
# Tag specific outputs
add_tags(
tags = [ "training" , "large" ],
artifact_name = "train" ,
infer_artifact = True
)
add_tags(
tags = [ "testing" , "small" ],
artifact_name = "test" ,
infer_artifact = True
)
return train, test
Tag Pipeline
from zenml import add_tags
# Tag a pipeline by name
add_tags(
tags = [ "ml" , "classification" , "production" ],
pipeline = "training_pipeline"
)
Tag Existing Run
from zenml import add_tags
# Tag a completed run
add_tags(
tags = [ "baseline" , "experiment-1" ],
run = "training_pipeline-2024_01_15"
)
Tag Artifact by Name and Version
from zenml import add_tags
# Tag a specific artifact version
add_tags(
tags = [ "validated" , "reviewed" , "approved" ],
artifact_name = "training_data" ,
artifact_version = "v5"
)
Tag with Tag Objects
from zenml import add_tags, Tag
from zenml.enums import ColorVariants
# Create tags with colors
tags = [
Tag( name = "critical" , color = ColorVariants. RED ),
Tag( name = "verified" , color = ColorVariants. GREEN ),
]
add_tags( tags = tags)
Conditional Tagging
from zenml import step, add_tags
import pandas as pd
@step
def analyze_data () -> dict :
df = pd.read_csv( "data.csv" )
result = { "rows" : len (df), "quality" : 0.95 }
# Tag based on data characteristics
tags = []
if result[ "rows" ] > 10000 :
tags.append( "large-dataset" )
if result[ "quality" ] > 0.9 :
tags.extend([ "high-quality" , "production-ready" ])
add_tags(tags)
return result
Tag Deployment
from zenml import add_tags
# Tag a deployment
add_tags(
tags = [ "production" , "kubernetes" , "v2.0" ],
deployment = "ml-model-deployment"
)
Tag Multiple Resources
from zenml import add_tags
# Tag the pipeline
add_tags(
tags = [ "production" ],
pipeline = "training_pipeline"
)
# Tag the latest run
add_tags(
tags = [ "successful" , "baseline" ],
run = "training_pipeline-latest"
)
# Tag output artifacts
add_tags(
tags = [ "production-ready" ],
artifact_name = "model" ,
artifact_version = "12"
)
Tag in Different Steps
from zenml import pipeline, step, add_tags
import pandas as pd
@step
def load_data () -> pd.DataFrame:
df = pd.DataFrame({ "data" : range ( 100 )})
add_tags([ "data-loading" , "complete" ])
return df
@step
def train_model ( data : pd.DataFrame) -> dict :
# Training logic
add_tags([ "training" , "complete" ])
return { "accuracy" : 0.95 }
@step
def evaluate_model ( results : dict ) -> None :
if results[ "accuracy" ] > 0.9 :
add_tags([ "high-accuracy" , "production-candidate" ])
@pipeline
def ml_pipeline ():
data = load_data()
results = train_model(data)
evaluate_model(results)
Tag Object Properties
When using Tag objects, you can specify:
from zenml import Tag
from zenml.enums import ColorVariants
tag = Tag(
name = "production" ,
color = ColorVariants. GREEN , # Optional: tag color in UI
exclusive = True , # Optional: only one tag from this group
cascade = True , # Optional: cascade to child resources
)
Use Cases
Organize experiments - Tag runs with experiment names or configurations
Track data quality - Tag datasets as validated, cleaned, or raw
Mark production assets - Identify production-ready models and data
Categorize by team - Tag resources by team or project
Flag for review - Mark artifacts that need human review
Track lineage - Tag resources with source or derivation information
Conditional logic - Use tags to make decisions in pipelines
Important Notes
When called inside a step without parameters, tags are added to the pipeline run
Tags are case-sensitive
Duplicate tags are ignored
Tags can be searched and filtered in the ZenML dashboard and CLI
Tags persist across pipeline runs and can be used for analytics
remove_tags Remove tags from resources
Tag Learn about Tag objects
@pipeline Configure tags in pipelines