---
title: "Promptfoo Integration with Langfuse Prompt Management"
sidebarTitle: Promptfoo
logo: /images/integrations/promptfoo_icon.svg
description: "Integrate Promptfoo with Langfuse for LLM testing, red teaming, and prompt management. Use Promptfoo evaluations with Langfuse-managed prompts."
---

# Promptfoo Integration with Langfuse Prompt Management

[Promptfoo](https://www.promptfoo.dev/) is an open-source LLM testing platform. It offers tools for red teaming, vulnerability scanning, and LLM evaluations, helping teams ensure the security and reliability of their LLM applications.

Integrate Promptfoo with Langfuse to take advantage of Langfuse's prompt management features during your Promptfoo evaluations. By using this integration, you can easily reference and [manage prompts](/docs/prompts/get-started) directly within Langfuse, making your LLM testing process more efficient and organized.

With Langfuse Prompt Management, you can:

- Update prompts without redeploying your application.
- Track and revert to previous prompt versions.
- Monitor and optimize prompt performance.
- Integrate prompts seamlessly with your tools and applications.
- Manage prompts via UI, SDKs, or API with minimal latency.

For more details, visit the [Langfuse Prompt Management documentation](/docs/prompt-management/get-started).

Thanks to the team at Promptfoo for developing this integration ([docs](https://www.promptfoo.dev/docs/integrations/langfuse)).

## Quick Start Guide

<Steps>

### Step 1: Set up Langfuse

1. Install the `langfuse` npm package, which Promptfoo's Langfuse provider uses under the hood: `npm install langfuse`
2. Visit [Langfuse](https://cloud.langfuse.com) to create an account.
3. Create a new project and copy your Langfuse API keys.
4. Set the `LANGFUSE_PUBLIC_KEY`, `LANGFUSE_SECRET_KEY`, and `LANGFUSE_BASE_URL` environment variables as desired.

### Step 2: Create a Langfuse Prompt

You can create, edit and manage your prompts via the Langfuse UI, SDKs, or API.

<LangTabs items={["Langfuse UI", "Python SDK", "JS/TS SDK"]}>

<Tab>

```python
# Create a text prompt
langfuse.create_prompt(
    name="movie-critic",
    type="text",
    prompt="As a {{criticlevel}} movie critic, do you like {{movie}}?",
    labels=["production"],  # directly promote to production
    config={
        "model": "gpt-3.5-turbo",
        "temperature": 0.7,
        "supported_languages": ["en", "fr"],
    },  # optionally, add configs (e.g. model parameters or model tools) or tags
)

# Create a chat prompt
langfuse.create_prompt(
    name="movie-critic-chat",
    type="chat",
    prompt=[
      { role: "system", content: "You are an {{criticlevel}} movie critic" },
      { role: "user", content: "Do you like {{movie}}?" },
    ],
    labels=["production"],  # directly promote to production
    config={
        "model": "gpt-3.5-turbo",
        "temperature": 0.7,
        "supported_languages": ["en", "fr"],
    },  # optionally, add configs (e.g. model parameters or model tools) or tags
)
```

If you already have a prompt with the same name, the prompt will be added as a new version.

</Tab>

<Tab>

This snippet uses the `@langfuse/client` package (`npm install @langfuse/client`), which is separate from the `langfuse` package required by Promptfoo itself.

```typescript
import { LangfuseClient } from "@langfuse/client";

const langfuse = new LangfuseClient();

// Create a text prompt
await langfuse.prompt.create({
  name: "movie-critic",
  type: "text",
  prompt: "As a {{criticlevel}} critic, do you like {{movie}}?",
  labels: ["production"], // directly promote to production
  config: {
    model: "gpt-3.5-turbo",
    temperature: 0.7,
    supported_languages: ["en", "fr"],
  }, // optionally, add configs (e.g. model parameters or model tools) or tags
});

// Create a chat prompt
await langfuse.prompt.create({
  name: "movie-critic-chat",
  type: "chat",
  prompt: [
    { role: "system", content: "You are an {{criticlevel}} movie critic" },
    { role: "user", content: "Do you like {{movie}}?" },
  ],
  labels: ["production"], // directly promote to production
  config: {
    model: "gpt-3.5-turbo",
    temperature: 0.7,
    supported_languages: ["en", "fr"],
  }, // optionally, add configs (e.g. model parameters or model tools) or tags
});
```

If you already have a prompt with the same name, the prompt will be added as a new version.

</Tab>

</LangTabs>

### Step 3: Reference Prompts in Promptfoo

Now you can use the prompts you created in Langfuse with Promptfoo. Use the `langfuse://` prefix for your prompts in your Promptfoo configuration file, followed by the Langfuse prompt ID and version. For example:

```yaml
prompts:
  - "langfuse://foo-bar-prompt:3"
providers:
  - openai:gpt-4o-mini
tests:
  - vars:
      # ...
```

Variables from your Promptfoo test cases will be automatically plugged into the Langfuse prompt as variables.

</Steps>

## GitHub Discussions

<!-- agent-instructions -->

---

## Agent Instructions

This page is part of the [Langfuse](https://langfuse.com) documentation, published as plain Markdown for AI agents. Every page is available as Markdown by appending `.md` to its URL, or by sending an `Accept: text/markdown` header. This page: `https://langfuse.com/integrations/other/promptfoo.md`.

### Querying these docs

If the answer is not on this page, query the documentation instead of guessing:

- **Semantic search** across all Langfuse docs, returning an answer with the relevant pages and excerpts. Ask a specific, self-contained question:

  ```bash
  curl -sG "https://langfuse.com/api/search-docs" --data-urlencode "query=How do I trace a LangGraph agent?"
  ```

- **Index of every page**: <https://langfuse.com/llms.txt>, with per-section indexes [llms-docs.txt](https://langfuse.com/llms-docs.txt), [llms-integrations.txt](https://langfuse.com/llms-integrations.txt), and [llms-self-hosting.txt](https://langfuse.com/llms-self-hosting.txt).

### Before writing Langfuse code

- **Install the [Langfuse Agent Skill](https://langfuse.com/docs/api-and-data-platform/features/agent-skill).** It encodes Langfuse's own best practices for instrumentation, prompt management, and evaluation, and materially improves results.
- **Read [What does a good trace look like?](https://langfuse.com/docs/observability/best-practices.md)** before instrumenting an application.
- **Verify endpoints, parameters, and response fields** against the [API reference](https://api.reference.langfuse.com) instead of inferring them from code examples.
- **Use the [Langfuse CLI](https://langfuse.com/docs/api-and-data-platform/features/cli)** (`npx langfuse-cli api <resource> <action>`) to read or write traces, prompts, datasets, and scores from the terminal.

Found an error in these docs? Please open an issue at <https://github.com/langfuse/langfuse-docs/issues>.
