Versions and labels: release and roll back
Every change to a prompt is a new version; labels point at versions. Moving production to another version releases it, and moving it back is a rollback.
Lesson 18 created version 1 with the production label. The desk asks for production, so what matters is which version that label points at.
langfuse.create_prompt(name="desk-system", prompt="Answer in one short sentence.", labels=["production"])
langfuse.create_prompt(name="desk-system", prompt="Answer in one short sentence. Thank the customer.")
for label in ["production", "latest"]:
prompt = langfuse.get_prompt("desk-system", label=label)
print(f"{label:10} -> version {prompt.version}: {prompt.prompt}")python labels.pySaving under the same name made version 2. Without labels of its own it took only latest, so production code keeps getting version 1 until someone decides otherwise. That is the safe default: a new version is a draft.
Releasing version 2, and rolling back
langfuse.update_prompt(name="desk-system", version=2, new_labels=["production"])
print("promoted ->", langfuse.get_prompt("desk-system").version)
langfuse.update_prompt(name="desk-system", version=1, new_labels=["production"])
print("rolled back ->", langfuse.get_prompt("desk-system").version)
print("version 2 by number ->", langfuse.get_prompt("desk-system", version=2).prompt)python labels.pyupdate_prompt moves labels to a version, and a label lives on only one version at a time. Rolling back is the same call with the old number. update_prompt also clears this program's cached copy of the prompt, so it saw each change at once; another program that fetched the prompt earlier keeps its cached copy for up to a minute, which lesson 21 explains. Fetching by version ignores labels altogether, which suits a test that must always use one exact prompt. Other labels work the same way: staging, one per customer, or prod-a and prod-b for the A/B test in lesson 22.
- Give version 2 the label
stagingand fetch it withlabel="staging". - Create version 3 with
labels=["production"]and print which versions carry which labels. - Fetch
version=7and read the error.
Every expert started right here.