LangfuseLangfuse Python SDK 4.15.4 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
38 small wins to finish your pathNext lesson

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.

Examplelabels.py, after the setup lines
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}")
Example
python labels.py

Saving 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

Examplelabels.py, continued
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)
Example
python labels.py

update_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.

Try it yourself
  • Give version 2 the label staging and fetch it with label="staging".
  • Create version 3 with labels=["production"] and print which versions carry which labels.
  • Fetch version=7 and read the error.

Every expert started right here.