> For the complete documentation index, see [llms.txt](https://docs.valohai.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.valohai.com/genai/llm-evaluations-local-execution/showing-full-traces-of-llm-calls-with-langfuse.md). Agents can also search and read this documentation through its [MCP server](https://docs.valohai.com/~gitbook/mcp).

# Showing full traces of LLM calls with Langfuse

Valohai LLM tells you what an evaluation scored. Langfuse tells you what happened inside it, the prompt that went out, the response that came back, and every span along the way.

The integration links the two. Each result in the table carries a link to its own trace, so a score you do not believe is one click away from the call that produced it.

## Set it up

Install Langfuse alongside the library:

```shell
pip install langfuse valohai-llm
```

Put the Langfuse credentials from your project settings in the environment, next to the `VALOHAI_LLM_API_KEY` from [Offline LLM Evaluations with LLM Eval](https://docs.valohai.com/genai/llm-evaluations-local-execution.md):

```shell
export LANGFUSE_PUBLIC_KEY="pk-..."
export LANGFUSE_SECRET_KEY="sk-..."
export LANGFUSE_HOST="https://cloud.langfuse.com"  # or your self-hosted address
```

That is the whole setup. Importing `valohai_llm` installs a hook into Langfuse that records the URL of each trace as it starts, and `post_result()` sends that URL along as `langfuse_last_trace_url` metadata. Your evaluation code does not mention the integration anywhere. `VALOHAI_LLM_NO_LANGFUSE_HOOK` turns the hook off.

## Trace a result you post yourself

Instrument the LLM call with Langfuse and post the result as usual. This example scores a summary and posts one result for it, which in practice you would run in a loop over many articles.

```python
import valohai_llm  # importing this installs the Langfuse hook
from langfuse.openai import openai  # Langfuse's drop-in OpenAI wrapper

# Langfuse traces this call automatically
response = openai.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Summarize this article: ..."}],
)

accuracy = evaluate_summary(response.choices[0].message.content)

# The trace URL rides along with the result
valohai_llm.post_result(
    task="summarization-eval",
    metrics={"accuracy": accuracy},
    labels={"model": "gpt-4o", "dataset": "cnn-dailymail"},
)
```

## Trace a sweep

Nothing changes for a [task](https://docs.valohai.com/genai/llm-evaluations-local-execution/configuring-your-evaluations-with-tasks.md) sweep. `task.run()` calls `post_result()` for every evaluation it runs, so every result in the sweep picks up its trace the same way.

```python
import valohai_llm
from langfuse.openai import openai

task = valohai_llm.get_current_task()

def evaluate(*, params: dict, item: dict) -> dict:
    response = openai.chat.completions.create(
        model=params["model"],
        messages=[{"role": "user", "content": item["prompt"]}],
    )
    correct = 1 if response.choices[0].message.content == item["expected"] else 0
    return {"correct": correct}

task.run(evaluate, item_labels=["category"])
```

Each call to `evaluate` produces one Langfuse trace and one Valohai LLM result, linked to each other.

## One call per result keeps the link exact

The hook holds the most recently started trace and overwrites it rather than collecting a list. One LLM call per evaluation, which is the usual shape, gives you the right trace every time.

Make several calls inside one evaluation function and the result links only to the last trace that started. If you need all of them, either post a result per call or go to Langfuse directly for the full picture of that run.

The trace also has to start before `post_result()` runs, so the URL exists when the result is sent. A loop that calls the model and then posts does this naturally.

## Open the trace from a result

On the Results page, the rightmost column shows a Langfuse icon for every result that captured a trace. Click it to open the trace in Langfuse.

![Results table with a Langfuse trace link in the rightmost column](https://4109720758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff3mjTRQNkASbnMbJqzJ2%2Fuploads%2FaE7la569WN16k4qVG7pZ%2FScreenshot%202026-03-04%20at%2014.22.17.png?alt=media\&token=594e7b41-df83-4209-8f28-bf056d0d4bf3)

## Next steps

* [Analyzing and comparing results](https://docs.valohai.com/genai/llm-evaluations-local-execution/analyzing-and-comparing-results.md) for the rest of what that results table does
* [Comparing cost and quality](https://docs.valohai.com/genai/llm-evaluations-local-execution/comparing-cost-and-quality.md) for attaching what each call cost to the result it belongs to
* [Running your evaluations with valohai-llm](https://docs.valohai.com/genai/llm-evaluations-local-execution/running-your-evaluations-with-valohai-llm.md) for the library's other hooks and environment variables


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.valohai.com/genai/llm-evaluations-local-execution/showing-full-traces-of-llm-calls-with-langfuse.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
