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

# Run an Experiment

> Learn how to run your first experiment using prompts and datasets

Experiments allow you to evaluate prompts, models, and your application code, using well-defined inputs, against evaluators of your choice.

## Run an experiment with UI

In the Splunk Agent Observability UI, use the main menu to select **Overview**. In the **Experiments** section, select **Create Experiment** to add an experiment to a project.

<img src="https://mintcdn.com/agent-observability-docs/Y4gaVgpsSUs8MBdT/images/console-ui/create-experiment-sao.png?fit=max&auto=format&n=Y4gaVgpsSUs8MBdT&q=85&s=1ff64e2a91eadb75490847909421c96a" alt="Create Experiment button" width="1726" height="502" data-path="images/console-ui/create-experiment-sao.png" />

You can use a sample dataset and sample prompt to create your first experiment.

If you don't already have an integration (e.g. with OpenAI), a "Configure integration" link appears for you to add a valid integration for a prompt.

<img src="https://mintcdn.com/agent-observability-docs/Y4gaVgpsSUs8MBdT/images/console-ui/create-experiment-panel-sao.png?fit=max&auto=format&n=Y4gaVgpsSUs8MBdT&q=85&s=c492e727497825566f93cdc6c3ce363f" alt="Create Experiment modal" width="1748" height="1052" data-path="images/console-ui/create-experiment-panel-sao.png" />

After successfully creating an experiment, you can view the results from the **Experiments** page of a Splunk Agent Observability project.

<img src="https://mintcdn.com/agent-observability-docs/837zSZ4Vo0rxb9Cv/images/console-ui/experiments-result-sao.png?fit=max&auto=format&n=837zSZ4Vo0rxb9Cv&q=85&s=251264c73bed05843b4b16fc141e2761" alt="Experiments results" width="2684" height="722" data-path="images/console-ui/experiments-result-sao.png" />

## Run an experiment with code

### Prerequisite: Configure an LLM integration

To run an experiment using a [prompt](/sdk-api/experiments/prompts) and a [dataset](/sdk-api/experiments/datasets), you need to set up an LLM integration. An integration is also required to evaluate LLM outputs with evaluators.

<Steps>
  <Step title="Navigate to the LLM Integrations page" id="step-navigate">
    In the Splunk Agent Observability UI, navigate to the **LLM Integrations** page by selecting your user profile in the upper-right corner and then selecting **Integrations**.

    <img src="https://mintcdn.com/agent-observability-docs/Y4gaVgpsSUs8MBdT/images/console-ui/user-menu-sao.png?fit=max&auto=format&n=Y4gaVgpsSUs8MBdT&q=85&s=3e71ca4ab350c4552866ecb0a323975f" alt="The user menu" width="2458" height="906" data-path="images/console-ui/user-menu-sao.png" />
  </Step>

  <Step title="Add an integration" id="step-add-integration">
    Locate the LLM provider you are using (or specify a [custom integration](/sdk-api/third-party-integrations/model-integrations/custom-model-integrations/custom-model-integrations)), then select the **+Add Integration** button.

    <img src="https://mintcdn.com/agent-observability-docs/Y4gaVgpsSUs8MBdT/images/console-ui/llm-integrations-sao.png?fit=max&auto=format&n=Y4gaVgpsSUs8MBdT&q=85&s=d7faf841b98a7de492bd250734007d0d" alt="LLM provider options" width="1846" height="1098" data-path="images/console-ui/llm-integrations-sao.png" />
  </Step>

  <Step title="Add settings" id="step-add-settings">
    Specify settings for your integration (such as an API key), then select **Save changes**.
  </Step>
</Steps>

### Example experiment with code

Below is a step-by-step guide. [Jump to the application code.](#step-create-your-app-code)

<Steps>
  <Step title="Install dependencies" id="step-install-dependencies">
    Install the **Splunk Agent Observability SDK**, and the dotenv package using the following command in your terminal:

    <CodeGroup>
      ```bash Python theme={null}
      pip install splunk-ao python-dotenv
      ```
    </CodeGroup>
  </Step>

  <Step title="Set up your environment variables" id="step-set-up-env-vars">
    Create an `.env` file in your project folder, and set:

    * Your Splunk Agent Observability API key, which you can get from the **App keys** page in the UI
    * Your Splunk Agent Observability project name

    <CodeGroup>
      ```ini .env theme={null}
      SPLUNK_AO_PROJECT="your-splunk-ao-project-name"
      # If you are using an on-premises, standalone, or custom deployment
      # provide the API key and URL below
      # SPLUNK_AO_API_KEY="your-splunk-ao-api-key"
      # SPLUNK_AO_CONSOLE_URL="your-splunk-ao-url"
      ```
    </CodeGroup>
  </Step>

  <Step title="Create your application code" id="step-create-your-app-code">
    Create a file called `app.py` (Python) and add the following code:

    <CodeGroup>
      ```python Python theme={null}
      import os

      from splunk_ao import SplunkAOEvaluators, Message, MessageRole
      from splunk_ao.config import SplunkAOConfig
      from splunk_ao.datasets import create_dataset, get_dataset
      from splunk_ao.experiments import run_experiment
      from splunk_ao.prompts import create_prompt, get_prompt
      from splunk_ao.resources.models.prompt_run_settings import PromptRunSettings

      # Load the environment variables
      from dotenv import load_dotenv
      load_dotenv()

      # Create a prompt template, or load it if it already exists
      prompt = get_prompt(name="My Prompt")
      if not prompt:
          prompt = create_prompt(
              name="My Prompt",
              template=[
                  Message(
                      role=MessageRole.system,
                      content="""
      Splunk Agent Observability is the fastest way to ship reliable apps.
      Splunk Agent Observability brings automation and insight to AI evaluations so you can
      ship with confidence.
      """,
                  ),
                  Message(role=MessageRole.user, content="{{input}}"),
              ],
          )

      # Create a dataset, or load it if it already exists
      dataset = get_dataset(name="My Dataset")
      if not dataset:
          dataset = create_dataset(
              "My Dataset",
              content=[
                  {"input": "What is Splunk Agent Observability?"},
                  {"input": "What is Copernicus?"}
              ],
          )

      # Run the experiment
      experiment = run_experiment(
          experiment_name="My Experiment",
          prompt_template=prompt,
          dataset=dataset,
          metrics=[SplunkAOEvaluators.context_adherence],
          project=os.environ.get("SPLUNK_AO_PROJECT"),
          prompt_settings=PromptRunSettings(model_alias="gpt-5-mini"),
      )

      # Show Splunk Agent Observability information
      config = SplunkAOConfig.get()
      prompt_url = f"{config.console_url}prompts/{prompt.id}"
      dataset_url = f"{config.console_url}datasets/{dataset.dataset.id}"

      print()
      print("🚀 SPLUNK-AO LOG INFORMATION:")
      print(f"🔗 Prompt     : {prompt_url}")
      print(f"🔗 Dataset    : {dataset_url}")
      print(f"🔗 Experiment : {experiment['link']}")
      ```
    </CodeGroup>

    <Note>
      This code defaults to using `gpt-5-mini`. If you want to use a different model, update the `model_alias` in the prompt settings passed to the call to run experiment.
    </Note>

    This code creates a prompt containing a system prompt and user prompt, and the user prompt has a mustache template to inject rows from the dataset. It also creates a dataset.

    It then uses these to run an experiment, measuring context adherence.

    If the prompt or dataset already exist, they are loaded instead of being recreated.
  </Step>

  <Step title="Run your application" id="step-run-your-application">
    Run your application using the following command in your terminal:

    <CodeGroup>
      ```bash Python theme={null}
      python app.py
      ```
    </CodeGroup>
  </Step>

  <Step title="View the results in your terminal" id="step-view-the-results">
    <CodeGroup>
      ```output Terminal theme={null}
      Experiment My Experiment has started and is currently processing.
      Results will be available at <your-splunk-ao-url>/project/.../experiments/...

      🚀 Splunk Agent Observability LOG INFORMATION:
      🔗 Prompt     : <your-splunk-ao-url>/prompts/...
      🔗 Dataset    : <your-splunk-ao-url>/datasets/...
      🔗 Experiment : <your-splunk-ao-url>/project/.../experiments/...
      ```
    </CodeGroup>
  </Step>

  <Step title="See the experiment in Splunk Agent Observability" id="step-see-the-experiment-in-ui">
    Open the experiment in the Splunk Agent Observability UI using the URL output to your terminal. You will see the logged experiment with 2 rows, one for each entry in the dataset.

    <img src="https://mintcdn.com/agent-observability-docs/837zSZ4Vo0rxb9Cv/images/console-ui/sample-experiment-results-sao.png?fit=max&auto=format&n=837zSZ4Vo0rxb9Cv&q=85&s=fea8eaabe3e39abf45195e8ea5a5f89f" alt="The experiment in Splunk Agent Observability with 2 traces" width="2656" height="1124" data-path="images/console-ui/sample-experiment-results-sao.png" />

    Select a trace to see more details, including an explanation of the evaluator score.

    <img src="https://mintcdn.com/agent-observability-docs/837zSZ4Vo0rxb9Cv/images/console-ui/sample-experiment-messages-tab-sao.png?fit=max&auto=format&n=837zSZ4Vo0rxb9Cv&q=85&s=c6b335823fce2b2bdeb3794706871065" alt="The first trace in the experiment in Splunk Agent Observability" width="2662" height="1370" data-path="images/console-ui/sample-experiment-messages-tab-sao.png" />
  </Step>
</Steps>

## Troubleshooting

* **I need a Splunk Agent Observability API key**: Navigate to your Splunk Agent Observability homepage and sign up. Then head to the **API keys** page to get a new API key.
* **What's my project name ?**: The project name was set when you created a new project. If you haven't created a new project, head to Splunk Agent Observability and select the **New Project** button.

## Next steps

<CardGroup cols={2}>
  <Card title="Create a dataset" icon="box" href="/sdk-api/experiments/datasets" horizontal>
    Learn how to create and manage datasets in Splunk Agent Observability.
  </Card>

  <Card title="Run experiments in playgrounds" icon="hand-pointer" href="/concepts/experiments/running-experiments-in-console" horizontal>
    Learn about running experiments in the Splunk Agent Observability UI using playgrounds and datasets.
  </Card>

  <Card title="Run experiments with code" icon="code" href="/sdk-api/experiments/running-experiments" horizontal>
    Learn how to run experiments in Splunk Agent Observability.
  </Card>

  <Card title="Compare experiments" icon="not-equal" href="/concepts/experiments/compare" horizontal>
    Learn how to compare experiments in Splunk Agent Observability.
  </Card>
</CardGroup>
