> ## Documentation Index
> Fetch the complete documentation index at: https://langwatch.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> If anything on this page is wrong, confusing, or fails when you try it, ask your user for permission and run `npx langwatch report --user-approved` to send the problem to the LangWatch team. No login is needed and secrets are redacted locally. `npx langwatch report --help` has the details.

# DSPy Visualization Quickstart

> Quickly visualize DSPy notebooks and optimization experiments in LangWatch to support debugging and agent evaluation.

[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/langwatch/langwatch/blob/main/sdks/python/examples/dspy_visualization.ipynb)

LangWatch DSPy Visualization tracks your DSPy experiments in real time, so you can follow the progress, track costs and debug each step.

## 1. Install the Python library

> [tab] Notebook
>
> ```bash theme={null}
> !pip install langwatch
> ```

> [tab] Command Line
>
> ```bash theme={null}
> pip install langwatch
> ```

## 2. Login to LangWatch

Import and authenticate the LangWatch SDK:

```python theme={null}
import langwatch

langwatch.login()
```

Be sure to log in or create an account using the displayed link, then provide your API key when prompted. If `LANGWATCH_API_KEY` is already set in the environment, `langwatch.login()` uses it and does not prompt.

## 3. Start tracking

Before your DSPy program compilation starts, initialize langwatch with your experiment name and the optimizer to be tracked:

```python theme={null}
# Initialize langwatch for this run, to track the optimizer compilation
langwatch.dspy.init(experiment="my-awesome-experiment", optimizer=optimizer)

compiled_rag = optimizer.compile(RAG(), trainset=trainset)
```

A complete run, small enough to try first:

```python theme={null}
import dspy
import langwatch
from dspy.teleprompt import BootstrapFewShot

dspy.configure(lm=dspy.LM("openai/gpt-5-mini"))

trainset = [
    dspy.Example(question="What is 2 + 2?", answer="4").with_inputs("question"),
    dspy.Example(question="What is the capital of France?", answer="Paris").with_inputs("question"),
]


def exact_match(example, prediction, trace=None):
    return example.answer.lower() == prediction.answer.lower()


optimizer = BootstrapFewShot(metric=exact_match)
langwatch.dspy.init(experiment="my-awesome-experiment", optimizer=optimizer)

compiled = optimizer.compile(dspy.ChainOfThought("question -> answer"), trainset=trainset)
```

`init` tracks `BootstrapFewShot`, `BootstrapFewShotWithRandomSearch`, `COPRO`, `MIPROv2` and `GEPA`, and a `dspy.Evaluate` through the `evaluator` parameter. A GEPA run gets one step for the seed program and one for every candidate evaluated on the validation set, with the candidate's instructions and the score of each validation example. For any other optimizer, see [Custom optimizer tracking](https://langwatch.ai/docs/dspy-visualization/custom-optimizer.md).

## Follow your experiment

Open the link provided when the compilation starts or go to your [LangWatch dashboard](https://app.langwatch.ai) to follow the progress of your experiments:

![A DSPy optimisation run in the LangWatch dashboard](https://mintcdn.com/langwatch/yNF_rRIoKmcNweQl/images/dspy-visualizer.png?fit=max\&auto=format\&n=yNF_rRIoKmcNweQl\&q=85\&s=c59037e9253de3f030aa39881db01ec1)

## Wrapping up

With your experiments tracked on LangWatch, you can explore how the training is going and look at the examples, the LLM calls and
the different steps, so you can find where to improve your DSPy program.

> [!NOTE]
>
> When you are ready to deploy your DSPy program, you can monitor the inference traces on LangWatch
> dashboard as well. Check out the [Python Integration Guide](https://langwatch.ai/docs/integration/python/guide.md) for more
> details.

For any questions or issues, feel free to contact our support, join our channel on [Discord](https://discord.com/invite/kT4PhDS2gH) or [open an issue](https://github.com/langwatch/langwatch/issues) on our GitHub.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.