Interview's MateAI Engineering
Interview's Mate

AI Engineering

LLMs, RAG, agents & evals

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
AI Engineering topics
Lesson 76/ 160
04. Evals

Langfuse

Open-source LLM observability for traces, scores, datasets, and prompt management.

IntermediateTraces · Datasets3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Langfuse is a control room for an AI app: it records what the AI did, stores the versions of its instructions and lets you test new versions on saved examples.

Think of it like…

Sentry plus Git plus a test runner for prompts: one place to see what happened in production, version the instructions and replay them against saved cases.

Where you’ve seen it

A team adds Langfuse tracing to a support assistant that handles 50,000 requests a day at roughly $0.012 each. The cost dashboard, grouped by feature tag, shows $600 a day: chat $430 (72%), summarise $110 (18%) and classify $60 (10%), which directs optimisation toward chat. A product manager edits the chat prompt in the prompt manager as version 15 and tests it on a dataset of 220 items created from flagged production traces; the experiment compares it with version 14 per item with a judge score. After v15 looks better, the team moves the production label from v14 to v15 with no deployment, and a regression in tone seen on the next day's traces is fixed by moving the label back in seconds.

Words you’ll hear

Trace, span and generation
A request, its nested steps, and the specific model-call spans with tokens and cost.
Prompt label
A movable tag (production, staging) pointing to a prompt version.
Dataset and experiment run
Saved test items and the results of running a variant over them.
Score
A numeric or categorical evaluation value attached to a trace, span or dataset run.

Visual diagram

Loading interactive diagram

Theory & deep dive

Core concepts and instrumentation

A trace represents one request; it contains observations: spans for generic steps, generations for model calls (model, parameters, input, output, token usage, cost) and events. Sessions group the traces of one conversation, and users and tags make slicing possible. In Python the SDK provides an observe decorator that turns a function into a span with captured arguments and results, a drop-in wrapper for the OpenAI client that records generations automatically, and integrations for frameworks such as LangChain and LlamaIndex. Recent SDK versions build on OpenTelemetry, so spans from other instrumented libraries can appear in the same trace.

Scores attach evaluation results to traces or observations: user thumbs, LLM-judge verdicts, rule checks or human annotation. Annotation queues let reviewers label traces. Cost is computed from token usage and model prices, so dashboards can break spend down by model, feature, user segment and prompt version, provided you pass useful metadata (prompt version, feature name, release) when you create traces.

Minimal instrumentation

@observe() def answer(question): ... creates a trace and span for each call, and fetching a prompt with langfuse.get_prompt("support-chat", label="production") links the generation to the exact prompt version that produced it.

Key takeaway: Traces, generations, scores and metadata give one connected view of behaviour, cost and quality.

Prompts, datasets and operating it

Prompt management stores prompts outside the code with version history. The app fetches by name and label (cached client-side to avoid latency and survive outages), so changing which version carries the production label is a release or rollback without a redeploy. Because generations record the prompt version, you can compare quality and cost across versions on live traffic. Treat prompts like code anyway: require review for production label changes, keep tests in CI, and keep a fallback prompt in the repository.

Datasets hold input and expected-output items, often created from traces with one click. An experiment run executes a prompt or pipeline over every item and records outputs and scores so runs can be compared side by side, which supports regression testing on golden sets. For operating Langfuse: the managed cloud is the quickest start; self-hosting suits strict data-residency needs but means running its databases and storage (recent versions use Postgres, ClickHouse, Redis and blob storage) and upgrades. Mask sensitive data before it's sent, set retention policies, and remember it's one option among several (LangSmith, Arize Phoenix, Braintrust, OpenTelemetry backends), so keep instrumentation portable where you can.

Release by label

v15 beats v14 on 14 of 20 sampled dataset items by judge score and has the same cost, so the team moves the production label to v15. If tone complaints appear, moving the label back to v14 restores the old behaviour immediately.

Key takeaway: Decouple prompt releases with labels, test on datasets from real traces, and plan data governance.

How it works, step by step

Step 1 of 4
Engineering

1. Instrument the app

Add the SDK, decorate key functions, wrap the model client and attach metadata such as feature and version.

@observe + client wrapper
Key numbers at this step
Overhead
async export

When to use it & trade-offs

What it is

Langfuse is an open-source LLM engineering platform that puts several workflows in one place: tracing of requests (traces, nested spans and model "generations" with tokens and cost), prompt management (versioned prompts with labels such as production and staging, fetched at runtime), datasets and experiments (run a prompt or model over a golden dataset and compare runs), evaluation and scores (LLM judges, user feedback and custom scores attached to traces) and dashboards for latency, cost and quality. It can run as a managed cloud service or be self-hosted, and it integrates with common SDKs and frameworks.

Why it matters: Teams that build their own logging, prompt store and eval tracking end up with scattered tooling. A platform like Langfuse connects the loop that matters: a bad production trace becomes a dataset item, the dataset evaluates a new prompt version, and the winning version is promoted by changing a label rather than redeploying code. Knowing what such a tool does, and where it fits next to OpenTelemetry and your own pipelines, is a practical skill for LLM engineers.

When to reach for it

  • Debugging and cost attribution for LLM apps
  • Prompt versioning with safe rollout and rollback
  • Building datasets and experiments from real traces

When to avoid or be careful

  • Sending raw PII and secrets without masking
  • Fetching prompts synchronously with no cache or fallback
  • Relying on a tool without owning your eval criteria

Observability and eval tooling choices

Langfuse
Best for: Open-source tracing, prompt management and datasets in one tool

Strengths: Self-hostable; framework-agnostic; strong prompt and dataset workflow.

Watch out: Self-hosting adds operations work.

Other LLM platforms (LangSmith, Phoenix, Braintrust)
Best for: Teams tied to a given framework or wanting hosted evals

Strengths: Tight integrations; polished eval features.

Watch out: Differing openness, pricing and lock-in.

General OpenTelemetry backend
Best for: Unifying LLM traces with the rest of the stack

Strengths: Vendor-neutral; one pane of glass.

Watch out: Less LLM-specific tooling for prompts and datasets.

Interview signals & numbers to know

When this topic comes up

  • “We edit prompts in code and redeploy for every tweak”
  • “Which feature drives our LLM cost?”
  • “Turn failures into test cases”
  • Prompt labels and versions
  • Self-hosted LLM observability

Benchmarks & rules of thumb

$600/day -
spend from 50,000 requests at about $0.012
72% / 18% / 10% -
cost split by feature in the example
220 -
dataset items created from flagged traces

Common mistakes & follow-ups

Common interview mistakes

  • Leaving the app hard-wired to one prompt version with no rollback path.
  • Not tagging traces with feature and version, so dashboards can't slice.
  • Treating the tool's built-in score as truth without calibration.

Likely interviewer follow-ups

  • How would you roll out a prompt change safely with prompt management?
  • What would you trace for a RAG app in Langfuse?
  • When would you self-host versus use the cloud service?
Interview tip: Describe the loop: trace → dataset → experiment → label promotion. It shows you use the tool as a process, not just a log viewer.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Langfuse with generative AI interview Q&A and hands-on practice.

Open Generative AI Q&A →Tech Learn Q&A
Previous topic
Tracing
Next topic
OpenTelemetry for LLMs