> ## 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.

# Langflow Integration

> Integrate Langflow with LangWatch to capture node execution, prompt behavior, and evaluation metrics for AI agent testing.

[Langflow](https://www.langflow.org/) is a low-code tool for building LLM pipelines. If you are using Langflow, you can easily enable LangWatch from their UI for analytics, evaluations and much more.

## Setup

<Steps>
  <Step title="Obtain your API Key">
    [Create your LangWatch account](https://app.langwatch.ai/) and project to obtain your API Key from the dashboard
  </Step>

  <Step title="Environment Variables">
    Add the following key to Langflow .env file:

    ```bash theme={null}
    LANGWATCH_API_KEY="your-api-key"
    ```

    Or export in in your terminal:

    ```bash theme={null}
    export LANGWATCH_API_KEY="your-api-key"
    ```
  </Step>

  <Step title="Restart Langflow">
    Restart Langflow using `langflow run --env-file .env`
  </Step>

  <Step title="Test the integration">
    Run a message through your Langflow project and check the LangWatch dashboard for monitoring and observability.

    <img src="https://mintcdn.com/langwatch/iJjBH4X_YNQ578jk/images/integration/langflow/langflow-1.png?fit=max&auto=format&n=iJjBH4X_YNQ578jk&q=85&s=b9f33e7973284942af1615ffe49631f7" alt="Langflow project" width="2109" height="916" data-path="images/integration/langflow/langflow-1.png" />

    That's it! You should now see your Langflow component traces on the LangWatch dashboard.

    <img src="https://mintcdn.com/langwatch/iJjBH4X_YNQ578jk/images/integration/langflow/langflow-2.png?fit=max&auto=format&n=iJjBH4X_YNQ578jk&q=85&s=e035d72c0c541097b5e0b584f1489e41" alt="LangWatch results" width="3572" height="2038" data-path="images/integration/langflow/langflow-2.png" />
  </Step>
</Steps>

## Defining custom input and output

You can customize what LangWatch captures as the final input and output of your Langflow component for better observability.

To do this, you can add this two lines of code in the execution function of any Langflow component:

```python theme={null}
import langwatch
langwatch.get_current_trace().update(input="The user input", output="My bot output")
```

You can do this by first clicking on the `<> Code` button in any appropriate component:

<img src="https://mintcdn.com/langwatch/iJjBH4X_YNQ578jk/images/integration/langflow/langflow-code.png?fit=max&auto=format&n=iJjBH4X_YNQ578jk&q=85&s=1f407eb633797c46107d20df504b52f5" alt="Langflow code button" width="278" height="222" data-path="images/integration/langflow/langflow-code.png" />

Then scroll down to find the `def` responsible for execution of that component and paste the code above, mapping the variables as needed for your case:

<img src="https://mintcdn.com/langwatch/iJjBH4X_YNQ578jk/images/integration/langflow/langflow-langwatch-call.png?fit=max&auto=format&n=iJjBH4X_YNQ578jk&q=85&s=26cda591d1a56c1bcc983409e65684ee" alt="Langflow code editor" width="1826" height="570" data-path="images/integration/langflow/langflow-langwatch-call.png" />

The message on LangWatch will render as you defined:

<img src="https://mintcdn.com/langwatch/iJjBH4X_YNQ578jk/images/integration/langflow/langwatch-message.png?fit=max&auto=format&n=iJjBH4X_YNQ578jk&q=85&s=a0236939d642835ed6c376b13ba82bc5" alt="LangWatch message" width="1968" height="822" data-path="images/integration/langflow/langwatch-message.png" />

## Capturing additional metadata

You can also capture additional metadata from your Langflow component. This can be useful for capturing information about the user, the conversation, or any specific information from your system.

Just like for the input and output, you can capture metadata by updating the trace, two very useful cases to capture for example are the user\_id and trace\_id that groups messages from the same conversation,
but you can also capture any other information that you want to track.

```python theme={null}
import langwatch
langwatch.get_current_trace().update(
  metadata={
    "user_id": self.sender_name,
    "thread_id": self.session_id,
    # any other metadata you want
  }
)
```

***

For more information, check out [Langflow docs](https://docs.langflow.org/).
