Prompt Chain

Integrate Langfuse for Prompt Management

Promptfoo example for Langfuse prompt management with labels: deploy, A/B test, and roll back prompts without code changes.

Works with langfusepromptfoo

78
Spark score
out of 100
Updated 14 days ago
Version 0.121.19

Add to Favorites

Why it matters

Streamline your prompt engineering process by integrating Langfuse for advanced prompt management and labeling within promptfoo.

Outcomes

What it gets done

01

Connect promptfoo with Langfuse for prompt tracking.

02

Utilize Langfuse labels for organizing prompts.

03

Enhance prompt evaluation and management capabilities.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/pfoo-integration-langfuse | bash

Steps

Steps in the chain

01
Install dependencies
02
Set environment variables
03
Create prompts in Langfuse
04
Initialize the example
05
Run the evaluation

Overview

Integration Langfuse

A promptfoo example for Langfuse prompt management with labels, covering the label and version syntax for referencing prompts, setup, and best practices. Use when managing prompts in Langfuse and evaluating labeled versions (production, staging, A/B variants) through promptfoo without code redeploys.

What it does

This promptfoo example demonstrates Langfuse prompt management with labels. Labels let you deploy new prompt versions without changing code, use different prompts per environment (production, staging, development), A/B test different prompt versions, and roll back to previous versions quickly. Setup runs in three steps: install @langfuse/client via npm install @langfuse/client, set the three environment variables (LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, and LANGFUSE_HOST="https://cloud.langfuse.com"), then log into the Langfuse dashboard to create prompts - named customer-support and email-writer in this example - with templated variables like {{customer_name}} and {{issue}}, and assign labels such as production, staging, or latest to specific versions of each.

When to use - and when NOT to

Initialize and run it with:

npx promptfoo@latest init --example integration-langfuse
cd integration-langfuse

followed by npx promptfoo@latest eval. Expected output includes a comparison of responses from different labeled prompts (production vs staging), performance metrics per prompt version, test results showing how different providers handle the same prompts, and a detailed evaluation report demonstrating label-based prompt management.

Inputs and outputs

Promptfoo supports two syntaxes for referencing Langfuse prompts. The explicit @ syntax (recommended for clarity) is langfuse://prompt-name@label:type; auto-detection with : syntax is langfuse://prompt-name:version-or-label:type, where numeric values like 1, 2, 3 are treated as versions and string values like production, staging are treated as labels. Format components are prompt-name (the Langfuse prompt name), version (a specific version number), label (the label assigned to a version), and type (text or chat, defaulting to text). Example references include langfuse://customer-support@production:chat, langfuse://customer-support@staging:chat, and langfuse://email-writer@latest using the explicit syntax; the auto-detection form covers the same ground with langfuse://customer-support:production:chat, langfuse://customer-support:staging, and langfuse://email-writer:latest:text; and version-pinned references use numeric values directly, as in langfuse://customer-support:1:chat and langfuse://email-writer:3:text.

Integrations

Best practices called out: use labels rather than hardcoded version numbers for production, test changes against a staging label first, use descriptive label names (production, staging, experiment-a, tenant-xyz), and monitor performance metrics across different prompt versions over time.

Who it's for

Teams managing prompts in Langfuse who want promptfoo evaluations wired directly to labeled prompt versions - comparing production against staging, A/B testing variants, or rolling back - without redeploying code to change which prompt version is live.

Source README

integration-langfuse (Langfuse Prompt Management)

This example demonstrates how to use Langfuse prompt management with labels in promptfoo.

Why use labels?

Labels allow you to:

  • Deploy new prompt versions without changing your code
  • Use different prompts for different environments (production, staging, development)
  • A/B test different prompt versions
  • Roll back to previous versions quickly

Setup

  1. Install dependencies:

    npm install @langfuse/client
    
  2. Set environment variables:

    export LANGFUSE_PUBLIC_KEY="your-public-key"
    export LANGFUSE_SECRET_KEY="your-secret-key"
    export LANGFUSE_HOST="https://cloud.langfuse.com"
    
  3. Create prompts in Langfuse:

    • Log into your Langfuse dashboard
    • Create prompts named customer-support and email-writer
    • Add prompt templates with variables like {{customer_name}}, {{issue}}, etc.
    • Assign labels to your prompt versions (e.g., production, staging, latest)

Initialize this example

To get started with this example:

npx promptfoo@latest init --example integration-langfuse
cd integration-langfuse

Running the example

npx promptfoo@latest eval

Expected outputs

After running the eval, you should see:

  • Comparison of responses from different labeled prompts (production vs staging)
  • Performance metrics for each prompt version
  • Test results showing how different providers handle the same prompts
  • A detailed evaluation report demonstrating label-based prompt management

Prompt format reference

Two syntax options

Promptfoo supports two ways to reference Langfuse prompts with labels:

  1. Explicit @ syntax (recommended for clarity)

    langfuse://prompt-name@label:type
    
  2. Auto-detection with : syntax

    langfuse://prompt-name:version-or-label:type
    
    • Numeric values (e.g., 1, 2, 3) are treated as versions
    • String values (e.g., production, staging) are treated as labels

Format components

  • prompt-name: The name of your prompt in Langfuse
  • version: Specific version number (1, 2, 3, etc.)
  • label: Label assigned to a prompt version
  • type: Either text or chat (defaults to text)

Example prompt references

### Explicit @ syntax for labels (recommended)
langfuse://customer-support@production:chat
langfuse://customer-support@staging:chat
langfuse://email-writer@latest

### Auto-detection with : syntax
langfuse://customer-support:production:chat  # String → label
langfuse://customer-support:staging          # String → label
langfuse://email-writer:latest:text          # "latest" → label

### Version references (numeric values)
langfuse://customer-support:1:chat           # Numeric → version
langfuse://email-writer:3:text               # Numeric → version

Best practices

  1. Use labels for production - Avoid hardcoding version numbers
  2. Test in staging first - Use a staging label to test changes
  3. Use descriptive labels - production, staging, experiment-a, tenant-xyz
  4. Monitor performance - Track metrics for different prompt versions

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.