Linking Langfuse prompts to traces to measure prompt performance

Connect each generation in Langfuse to the prompt version that produced it, so cost, latency and scores can be compared per version and regressions caught after a change.

On this page

Linking Langfuse prompts to traces to measure prompt performance

Linking prompt versions to traces lets you compare cost, latency and evaluation scores per prompt version, so a team changing prompts in production can see whether quality, latency or spend moved after a change instead of guessing. Without that link, traces show what the application did but not which prompt text produced it, so a regression often surfaces as a support ticket rather than a number on a dashboard. Langfuse's documentation describes the feature as enabling tracking of metrics and evaluations per prompt version, which is the comparison this topic is about.

You need this when several prompt versions run at once, for example a production label alongside a staging or per-tenant variant, when prompts change often enough that a single bad edit could go unnoticed for days, or when someone must answer for spend or quality by feature. A simpler setup is enough when one prompt changes rarely, traffic is low and a manual spot check of outputs catches problems in time. Before you rely on the comparison, confirm in the current Langfuse release that generations sent from your application carry the prompt reference, and that your evaluators write scores that can be filtered by version. This is a core feature of the MIT-licensed open source version, so no Enterprise license key should be implied, but confirm this against the current release notes and the Langfuse documentation on linking prompts to traces before you plan around it.

Which linking approach fits which team

Teams that fetch prompts from Langfuse at runtime through the SDK get version linking as part of normal prompt use. The application requests a prompt by name and label, receives the version it resolved to, and passes that prompt object into its tracing calls so the generation is recorded against the same version. Comparisons then come from the prompt version already attached to each trace, with no second system to reconcile.

  • Instrumentation change: Fetch the prompt through the SDK and pass the returned prompt object into the generation or tracing call, instead of hard-coding the text.
  • What is needed to compare versions: Every call path that generates output must use the managed prompt, or those generations will show no version.
  • Main trade-off: The application depends on Langfuse for prompt retrieval, so caching and fallback behavior become part of the release design.
  • Operational detail: Confirm in the linking docs which SDK versions and methods support passing a prompt into tracing for your language.

Before relying on this path, check that every production code path that calls a model uses the managed prompt and that the version field appears on sampled traces.

Configuration choices and when each fits

This table compares the main configuration choices for linking prompts to traces: how the application fetches prompts, when links are made, how results are read, and how traces are tagged. Read each row by asking what the choice gives you and what it costs in traceability or release control. The main takeaway is that label-based fetching and generation-time linking usually matter more than the reporting method you pick.

OptionWhat it gives youTrade-offWhen it fits
Label-based fetchingThe application requests a label such as production, so a label move changes the version in use without a code deployTraces show the resolved version, so you must confirm the label moved as intended before reading per-version resultsTeams that release prompts often and want rollback by moving a label
Pinned version numbersThe application always runs one fixed prompt version, so every trace maps to a known, unchanging versionEach prompt change needs a code or config change to update the pinned numberRegulated or change-controlled releases where every prompt change must pass a code review
Linking at generation timeEach generation records the prompt version when it runs, so cost, latency and scores attach to the exact versionOnly generations created after instrumentation carry the link, so history before the change cannot be comparedNew integrations or any setup where you need clean per-version comparisons from the first run
Linking after the factExisting traces can be reviewed against a version by matching their inputs or timing, without changing the applicationMatching is approximate and depends on your own data, so results need careful checkingShort-term analysis of legacy traces that were not instrumented with prompt links
Per-version dashboardsBuilt-in views to compare cost, latency and scores by prompt version inside LangfuseLimited to the views the platform offers, so custom cuts may need the APIDay-to-day review by product and prompt owners
Metrics API exportsVersioned metrics pulled into your own warehouse or reporting, for custom cuts and joins with business dataYou build and maintain the pipeline and its queries, and check that definitions match the UITeams that report to finance, risk or leadership with their own data models
Environment tagsSeparates development, staging and production traces so a regression is not hidden by test trafficTags are only as reliable as the code that sets them, so confirm every service sends themAny setup where prompts run in more than one environment
Tenant tagsLets you compare prompt versions across customers or tenants in multi-tenant productsHigh-cardinality tags add query and storage load, and tenant data may need masking or retention rulesProducts serving many customers where a change may affect only some tenants

How to set up version-level comparison in self-hosted Langfuse

This sequence takes a self-hosted Langfuse instance from a running deployment to a repeatable baseline, so cost, latency and scores can be compared per prompt version after each change. Each step ends with a check that tells the team whether it can move on.

  1. Confirm the instance is running and receiving traces

    The platform team confirms that the self-hosted Langfuse web and worker containers, PostgreSQL, ClickHouse, Redis or Valkey and blob storage are healthy, and that the application can reach the instance over the network. The application team sends a simple trace from a development environment with the project's public and secret keys. Done when the trace appears in the project's Tracing view within the normal ingestion window, with its input, output and model fields populated. If it does not appear, check worker health and ingestion logs before changing application code.

  2. Create or migrate prompts into Langfuse management

    The prompt owner creates each production prompt in the Langfuse Prompt Management section, or imports the existing text from the codebase, and assigns a name that the application will reference. Each saved change creates a new version with an automatic version number, which is the identifier later used to group traces. Done when every prompt the application uses appears in the project with at least one version, and the team can open each version and see its exact text and configuration.

  3. Fetch managed prompts and link generations in the application

    The developers change the application so it fetches each prompt from Langfuse at runtime and passes the returned prompt object to the LLM call, so that the generation is linked to the prompt version that produced it. Confirm the exact link method for the SDK version in use against the linking documentation before writing code. Done when a generation sent from the application shows a linked prompt name and version in its trace detail view, not just the plain text of the prompt.

  4. Send a test generation for each prompt version

    The team runs the application against at least two prompt versions in a non-production environment, using the same inputs for both, so that the traces differ only in the prompt. This can be done by moving a non-production label between versions or by a controlled test script. Done when each version has at least one linked generation with cost, latency and any test scores recorded, and the traces can be told apart by version.

  5. Verify grouping by version in the UI

    A reviewer opens the Langfuse dashboards and the trace list, filters by prompt name, and groups or compares results by prompt version. The reviewer checks that token usage and cost, latency and attached scores each separate the versions and that the numbers match a manual spot check of two or three traces. Done when the per-version figures agree with the individual traces. If a version shows no data, the generation is probably not linked to the prompt and step three should be repeated.

  6. Record a baseline before the next prompt change

    Before anyone changes the production prompt, the prompt owner records the current version's cost, latency and score distributions over a representative set of traces, and notes the version identifier and the production label it holds. Scores should come from the evaluation process the team already uses. Done when the baseline is written down with its version, date range and sample size, so that a later version can be compared against a fixed reference rather than memory.

  7. Compare the next version against the baseline

    When a new prompt version is ready, the team runs it in staging with the same inputs, then compares its cost, latency and scores with the recorded baseline in the Langfuse UI. Any regression that exceeds the team's agreed threshold blocks promotion of the label, and the decision and the figures are logged with the version. Done when the team can state, for each version, whether it was promoted or rejected and which measurements supported that decision.

Spotting regressions after a prompt change

A regression check works only if you fix a baseline version before the change goes live and compare the new version against it on the same measures. In self-hosted Langfuse, the baseline is usually the version currently carrying your production label, and the measures are the cost, latency and score figures that Langfuse aggregates per prompt version through linked traces. Decide the baseline and the metrics in writing before the rollout, because a comparison chosen after the numbers arrive tends to favor the change. Record the baseline version ID, the time window you will compare, and which evaluators or user feedback scores count toward the verdict.

Next, decide what counts as a regression. The Langfuse documentation does not give thresholds for cost, latency or scores, so set them with your product and quality owners rather than copying a number from a blog post. Separate hard failures, such as errors, empty outputs or schema violations, from soft movements in judged quality. Treat cost and latency changes as regressions only when they break a budget or service target you already run. Evaluator scores are only as trustworthy as their own calibration, so confirm with your evaluation owners how those scores were validated before you act on a small difference. Evaluations and datasets are covered in the sibling content on Langfuse evaluations and datasets.

Comparison also needs enough traffic. A new version that has served a few dozen generations will show averages that swing with every outlier, so wait until each version has a sample large enough for your team to trust, and check that the two versions saw comparable inputs, user segments and time of day. If traffic is uneven, compare on matched slices or run the check against a dataset first. Confirm your sample requirement with your data and analytics owners, and plan a rollback path by moving the production label back to the baseline version, which is the fastest response once a regression is confirmed.

Security and operational considerations

Linking prompts to traces creates a dataset that is more sensitive and more durable than either half alone. Each card below names a risk that comes from joining prompt versions to generation data, and what to confirm before you rely on per-version reporting in production.

Personal data inside prompts and traces

Prompt text, user messages and model outputs travel into the same trace records that carry the prompt version ID. A linked trace can therefore hold personal data even when the prompt template itself does not. Confirm which fields your application sends, whether you need masking before ingestion, and how long traces are kept. Retention and masking controls are the features to review first, and their availability depends on your license.

Self-hosting docs

Who can view per-version data

Per-version dashboards show cost, latency and scores for each prompt release, which can reveal how a product feature performs and who uses it. Project-level RBAC roles are an Enterprise license feature in self-hosted Langfuse, so the open source edition may not let you separate viewers from editors within a project. Confirm the role model you need before you grant access to traces that contain customer data.

License key docs

Audit trail for prompt changes

A linked trace shows which version produced a result, but it does not record who moved a label or published a version. Audit logs are an Enterprise license feature in self-hosted Langfuse. Without them, reconstruct the change history from your own source control or webhook records, and decide who is accountable for each production label move before a regression investigation needs that history.

ClickHouse growth from added metadata

Each generation linked to a prompt version carries extra attributes, and per-version analysis adds queries that scan them. Storage in ClickHouse grows with trace volume and with every attribute you attach. Before you enable linking at full traffic, measure how much a sample of traces adds per day, size the ClickHouse disk for that growth, and check the disk headroom your planned upgrade path requires.

v4 upgrade guide

Label changes that alter linked data

Traces link to the version that was fetched, so moving a label changes which version future generations report under, but not the history of past traces. Comparisons across a label move can mix two prompts that share a name but differ in behavior. Agree a rule for when a label move starts a new comparison window, and record label moves alongside the deployment that caused them.

Backups covering traces and prompts together

Per-version reporting depends on two stores at once: PostgreSQL holds prompt versions and labels, while ClickHouse holds the traces that reference them. Restoring one without the other leaves links pointing at versions that no longer exist or metrics with no version to attach to. Plan backups of both and of blob storage on the same recovery point, and test a restore that checks a linked trace still resolves to its prompt version.

Questions teams ask before linking prompts to traces

How much effort does linking prompts to traces take?

The effort depends mostly on how many places in your code call a model and how those calls are instrumented today. Linking a prompt to a trace means the generation carries the prompt name and version that produced it, so the work has three parts: the application side, where each call site must fetch a managed prompt and pass it into its trace; the prompt side, where existing hard-coded prompts are moved into Langfuse and given a stable name; and the verification side, where you confirm that cost, latency and scores appear grouped by version. A service with one model call and a single prompt is a small change. A codebase with dozens of call sites, several frameworks and prompts copied between services is a larger one. Ask any partner to inventory call sites before quoting, because that inventory sets most of the scope.

Can an internal team link prompts to traces without a partner?

Yes, if the team has engineers who already work with the application's model calls and can read the Langfuse documentation for prompt linking. The steps are not exotic: create or import prompts, fetch them in code, and attach the prompt reference to the generation so the trace records the version. What an internal team often lacks is time and a second pair of eyes on the cross-cutting parts, such as consistent naming across services, a rollback path if a prompt change breaks production, and a test that proves each version is attributed correctly. A partner is most useful when the call sites are spread across several teams or when the result must be reviewed by security or compliance staff who expect documented evidence.

What does the work need from our team?

Three inputs make the work predictable. First, access to the repositories and runtime configuration of every service that calls a model, including any framework that already emits OpenTelemetry traces to Langfuse's OTLP endpoint. Second, a staging Langfuse instance where prompt changes and trace links can be tested before anything reaches production, because a broken prompt fetch affects live users. Third, named prompt owners who decide which prompt versions are approved, what each version is for, and who may move a production label. Without owners, the version data will be accurate but nobody will know what a regression means. Confirm these three inputs with your engineering and product leads before the quote is written.

How long does it take to link prompts to traces?

No general duration can be given, because the answer follows the scope: the number of services, the number of prompts, whether a staging instance already exists, and how many review cycles the prompt owners need. The reliable way to plan is to split the work into phases: an inventory of call sites and prompts, a pilot on one service with one prompt, a rollout to remaining services, and a period of observation where version-level cost, latency and score dashboards are checked against known prompt changes. Ask for the phases and the acceptance test for each phase in writing. A fixed-scope agreement sets these milestones before work starts, which makes the timeline easier to compare between bidders.

Do we need an Enterprise license to link prompts to traces?

Linking prompts to traces is part of the core feature set. Langfuse states that all core features and APIs are available in the MIT-licensed open source version without limits, and self-hosted deployments run the same codebase as Langfuse Cloud. The Enterprise license key is needed only for specific self-hosted features such as project-level RBAC roles, protected prompt labels, audit logs and data retention policies. If your plan depends on protected labels so that only certain people can move production prompt versions, that is a licensing decision to make separately. Confirm the current license terms in the repository's LICENSE file and the license key documentation before you commit to a design.

What should we ask a partner for in a fixed-scope quote?

Ask for a written scope that lists the services and call sites in scope, the prompts to be migrated, the framework and SDK versions involved, and the environments where work will be tested. Ask which deliverables you receive: instrumented code changes, a naming convention for prompts and versions, the verification evidence showing version-level metrics, and a handover note for your engineers. Ask what is excluded, such as changes to Langfuse infrastructure, model provider configuration or evaluation design. Finally, ask how costs recur: one-time implementation is separate from any retainer for ongoing prompt governance or upgrades. A quote that cannot be traced back to these items is hard to compare.

Official Langfuse documentation for this feature

The linking prompts to traces guide is the next read for this topic, because it defines how a generation is tied to the prompt version that produced it, which is the foundation for every per-version comparison of cost, latency and scores. Read it before you write instrumentation code, and confirm against the current Langfuse documentation which SDK methods and trace fields it describes for the SDK version your teams use, since the Python and JS/TS SDKs have their own major versions and minimum server requirements.

Once the linking model is clear, read the self-hosting documentation to confirm the deployment side of the work: the Langfuse Web and Worker containers, PostgreSQL, ClickHouse, Redis or Valkey and S3-compatible blob storage that hold the traces and prompt versions your comparisons depend on. The Langfuse self-hosting documentation covers the deployment options and is the right place to check which versions your instance runs, because the linking data lives in ClickHouse and an upgrade can change how observations are stored. Confirm your target version against the upgrade guides before you plan the rollout.

How DeployOpen scopes and delivers prompt-to-trace linking

This sequence turns an agreed scope into an application that tags every generation with the prompt version that produced it, verified on your own self-hosted Langfuse and documented for your team to run.

  1. Agree the scope in writing

    Before any work starts, DeployOpen and your team agree in writing which applications, prompts and environments are in scope, which Langfuse instance receives the traces, and what the deliverables are. Most engagements are fixed-scope, so the scope document is the reference for quotes and acceptance. The step is done when both sides have signed off the scope and the named deliverables, including whether ongoing support is included.

  2. Review the prompt and tracing code

    DeployOpen reads how your application fetches prompts, where it calls the model, how traces are created today, and whether it uses the Langfuse SDK, OpenTelemetry or another tracing library. The review maps every place a generation is produced so no call path is missed, and it flags prompts that are hardcoded or fetched without a version. The output is a short findings list that names each call site and the change it needs.

  3. Confirm the target Langfuse setup

    DeployOpen checks the self-hosted Langfuse version, the SDK versions in use and the connection path from the application to the Langfuse Web container, including network rules and credentials. Where SDK versions must match a minimum Langfuse release, the team confirms that requirement against the upgrade notes before changing any code. The step is done when the agreed test environment accepts a trace from the application.

  4. Instrument generations with prompt versions

    DeployOpen changes the application so each generation is linked to the prompt version that produced it, using the Langfuse prompt link feature as documented, and records the model, token usage and latency on the same trace. Changes are kept small and limited to the agreed call sites, and fallback behavior is preserved so a fetch failure does not silently drop the link. The step closes when the code changes are reviewed and merged in your repository.

  5. Verify per-version metrics and scores

    DeployOpen runs test traffic through each prompt version and checks in the Langfuse UI that cost, latency and attached scores group under the correct version. It also tests a deliberate prompt change to confirm that a regression shows up as a difference between versions. Results are recorded against the scope, and any gaps, such as missing scores or unlinked generations, are fixed before sign-off.

  6. Hand over documentation and runbooks

    DeployOpen delivers documentation covering how the linking works, which code paths carry it, how to add a new prompt call site, how to read the per-version views, and what to check when a generation appears without a version. Your engineers and prompt owners receive a walkthrough of the documentation. The step is done when your team has run the checks in the runbook without DeployOpen present.

  7. Optional retainer support after handover

    If you want continued help, DeployOpen can provide retainer support for changes to prompts and tracing code, Langfuse upgrades, and periodic checks that new prompt versions still link correctly. Retainers are agreed separately from the fixed-scope work and are priced from their own written scope. The step is complete when the support terms and scope are agreed in writing, or when you decide to run the setup with your own team.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.