Prompts kept in Langfuse
A prompt stored in Langfuse can change without a new deploy of your code. create_prompt saves a version, get_prompt fetches it, and compile fills in its variables.
The desk's instruction to the model, SYSTEM in desk.py, is a constant in the code. Changing a word means a code change and a release. Langfuse's prompt management keeps prompts on the server, with every version, so the text can change while the code stays the same.
langfuse.create_prompt(
name="desk-system",
type="text",
prompt="You answer customers of {{shop}} in one short sentence.",
labels=["production"],
)type="text" makes the prompt one string; lesson 19 covers chat prompts. {{shop}} is a variable, filled in at run time. The production label marks this version as the one applications should use. Usually a person writes prompts in Langfuse's interface; the SDK call does the same.
prompt = langfuse.get_prompt("desk-system")
print(prompt.version, prompt.labels, prompt.variables)
print(prompt.compile(shop="a small online shop"))
print(prompt.compile())
print(local_langfuse.REQUESTS)python prompt.pyVersion 1 carries production, and latest, which Langfuse moves to the newest version by itself. get_prompt with no label asks for production. REQUESTS shows one request to store the prompt and one to fetch it.
The second compile is a bug that raises nothing. Without a value for shop, the variable stays in the text as {{shop}}, and the model would read the braces as they are. prompt.variables lists the names to fill; a test that compiles every prompt with your real values and checks that no {{ is left catches this before a customer does.
The desk with its prompt from Langfuse
system = langfuse.get_prompt("desk-system").compile(shop="a small online shop")
print(answer("Where is my order A17?", system=system))python prompt.pyThe compiled text goes in as the desk's system argument from lesson 9. The desk works as before; the difference is that the instruction can now be edited in Langfuse, and every version is kept.
- Pass
shop="Ada's Books"and print the compiled text. - Fetch a prompt name that does not exist and read the error.
- Add a second variable,
{{tone}}, and printprompt.variables.
Slow is fine. Stopping is the only problem.