DocsPrompt ManagementGet Started

Get Started with Prompt Management

This guide walks you through creating and using a prompt with Langfuse. If you’re looking to understand what prompt management is and why it matters, check out the Prompt Management Overview first. For details on how prompts are structured in Langfuse and how it works in the background, see Core Concepts.

Get API keys

  1. Create Langfuse account or self-host Langfuse.
  2. Create new API credentials in the project settings.

Create a prompt

Use the Langfuse UI to create a new prompt or update an existing one. You’ll need to select the prompt type, you can’t change this afterwards.

Use prompt

At runtime, you can fetch the prompt from Langfuse. We recommend using the production label to fetch the version intentionally chosen for production. Learn more about control (versions/labels) here.

from langfuse import get_client   # Initialize Langfuse client langfuse = get_client()

Below are code examples for both a text type prompt and a chat type prompt. Learn more about prompt types here.

Text prompt

# By default, the production version is fetched. prompt = langfuse.get_prompt("movie-critic")   # Insert variables into prompt template compiled_prompt = prompt.compile(criticlevel="expert", movie="Dune 2") # -> "As an expert movie critic, do you like Dune 2?"

Chat prompt

# By default, the production version of a chat prompt is fetched. chat_prompt = langfuse.get_prompt("movie-critic-chat", type="chat") # type arg infers the prompt type (default is 'text')   # Insert variables into chat prompt template compiled_chat_prompt = chat_prompt.compile(criticlevel="expert", movie="Dune 2") # -> [{"role": "system", "content": "You are an expert movie critic"}, {"role": "user", "content": "Do you like Dune 2?"}]

Not seeing your latest version? This might be because of the caching behavior. See prompt caching for more details.

Not seeing what you expected?

Next steps

Now that you’ve used your first prompt, there are a couple of things we recommend you do next to make the most of Langfuse Prompt Management:

Looking for something specific? Take a look under Features for guides on specific topics.

Was this page helpful?