Launch Week 02 wrapped — explore all five launches

Pull Datasets

Pull datasets locally to use them for evaluation.

Overview

In the previous section, we learnt how to push and queue goldens via Confident's Evals API. In this section, we will learn how to:

  • Pull single and multi-turn datasets for evaluation
  • Access custom column values from goldens
  • Parse multi-modal goldens (images) into an evaluatable format
  • Use the evals_iterator to run evals on single-turn datasets (Python only)

How it works

Code-driven evals follow a similar process to no-code evals, but you control the evaluation loop:

  1. Pull dataset — fetch goldens from Confident AI using the Evals API
  2. Invoke AI app — call your AI app with each golden's input
  3. Create test cases — map golden fields and AI outputs into test cases
  4. Run evaluation — execute metrics on your test cases and push results

Here's a visual representation of the data flow:

sequenceDiagram
    participant You as Your Code
    participant Platform as Confident AI
    participant AI as Your AI App
    participant Metrics as Local/Remote Metrics

    You->>Platform: Pull dataset (goldens)
    Platform-->>You: Return goldens

    loop For each golden in dataset
        You->>AI: Invoke with golden.input
        AI-->>You: Generate output
        You->>You: Create test case from golden + output
    end

    You->>Metrics: Run evaluation on test cases
    Metrics-->>You: Metric scores
    You->>Platform: Push test run results
    Platform-->>You: Test run created

The key difference from no-code evals is that you control the evaluation loop — pulling goldens, invoking your AI app, and constructing test cases all happen in your code.

Pull Goldens via Evals API

Datasets are either single or multi-turn, and you should know that pulling a single-turn dataset will give you single-turn goldens, and vice versa.

Pulling goldens via the Evals API will only pull finalized goldens by default. Below is a single-turn dataset example (click here for multi-turn usage of datasets):

  1. Pull goldens

    First use the .pull() method:

    main.py
    from deepeval.dataset import EvaluationDataset
    
    dataset = EvaluationDataset()
    dataset.pull(alias="YOUR-DATASET-ALIAS")
    
    print(dataset.goldens) # Check it's pulled correctly
  2. Construct test cases

    Then loop through your dataset of goldens to create a list of test cases:

    main.py
    from deepeval.dataset import EvaluationDataset
    from deepeval.test_case import LLMTestCase
    
    dataset = EvaluationDataset()
    dataset.pull(alias="YOUR-DATASET-ALIAS")
    
    for golden in dataset.goldens:
        test_case = LLMTestCase(
            input=golden.input,
            actual_output=llm_app(golden.input),
            # map any additional fields here
        )
        dataset.add_test_case(test_case)
  3. Run an evaluation

    By calling .add_test_case() in the previous step, each time you run evaluate Confident AI will automatically associate any created test run with your dataset:

    from deepeval import evaluate
    
    evaluate(test_cases=dataset.test_cases, metrics=[...])

Using Custom Columns

If your dataset has custom columns, you can access them via the custom_column_key_values field on each golden:

main.py
from deepeval.dataset import EvaluationDataset
from deepeval.test_case import LLMTestCase

dataset = EvaluationDataset()
dataset.pull(alias="YOUR-DATASET-ALIAS")

for golden in dataset.goldens:
    # Access custom column values
    difficulty = golden.custom_column_key_values.get("difficulty")
    category = golden.custom_column_key_values.get("category")

    # Use them in your test case or LLM app invocation
    test_case = LLMTestCase(
        input=golden.input,
        actual_output=llm_app(golden.input, difficulty=difficulty),
    )
    dataset.add_test_case(test_case)

Using Images

Any (list of) golden text fields (such as input, scenario, etc.) that contains an image will be in the format of [DEEPEVAL:IMAGE:url]. The url inside the [DEEPEVAL:IMAGE:url] format is a public url that can be accessed by anyone.

For goldens containing images, here you can parse and use it accordingly as follows:

The deepeval python SDK offers a utility method called convert_to_multi_modal_array. This method is useful for converting a string containing images in the [DEEPEVAL:IMAGE:url] format into a list of strings and MLLMImage items.

from deepeval.dataset import EvaluationDataset
from deepeval.utils import convert_to_multi_modal_array

dataset = EvaluationDataset()
dataset.pull(alias="My Evals Dataset")

for golden in dataset.goldens:
    multimodal_array = convert_to_multi_modal_array(golden.input)

The multimodal_array here is a list containing strings and MLLMImages, you can loop over this array to construct a messages array with images to pass to your MLLM. Here's an example showing how to construct messages array for openai:

messages = []
for element in multimodal_array:
    if isinstance(element, str):
        messages.append({"type": "text", "text": element})
    elif isinstance(element, MLLMImage):
      if element.url:
          messages.append(
              {
                  "type": "image_url",
                  "image_url": {"url": element.url},
              }
          )

Using Evals Iterator

Typically, you would just provide your dataset as a list of test cases for evaluation. However, if you're running single-turn, end-to-end OR component-level evaluations and using deepeval in Python, you can use the evals_iterator() instead:

main.py
from deepeval.dataset import EvaluationDataset

dataset = EvaluationDataset()
dataset.pull(alias="YOUR-DATASET-ALIAS")

for golden in dataset.evals_iterator():
    llm_app(golden.input) # Replace with your LLM app

# Async version
# import asyncio
#
# for golden in dataset.evals_iterator():
#    task = asyncio.create_task(a_llm_app(golden.input))
#    dataset.evaluate(task)

You'll need to trace your LLM app to make this work. Read this section on running single-turn end-to-end evals with tracing to learn more.

Datasets in CI/CD

Using datasets in CI/CD follows the same pattern as local evaluation — pull your dataset, create test cases, and run evaluation. The only difference is that you use assert_test() instead of evaluate() to integrate with pytest:

test_llm_app.py
import pytest
from deepeval.test_case import LLMTestCase
from deepeval.dataset import EvaluationDataset
from deepeval.metrics import AnswerRelevancyMetric
from deepeval import assert_test

dataset = EvaluationDataset()
dataset.pull(alias="YOUR-DATASET-ALIAS")

for golden in dataset.goldens:
    test_case = LLMTestCase(input=golden.input, actual_output=llm_app(golden.input))
    dataset.add_test_case(test_case)

@pytest.mark.parametrize("test_case", dataset.test_cases)
def test_llm_app(test_case: LLMTestCase):
    assert_test(test_case, metrics=[AnswerRelevancyMetric()])

Then run with deepeval test run test_llm_app.py to execute your tests. Learn more about setting up automated testing in the Unit-Testing in CI/CD section.

Next Steps

Now that you're familiar with the full dataset lifecycle, time to dive into running evaluations end to end.

Curating datasets across your team?Keep collaboration, annotation, and dataset quality organized at scaleBook a demo
Built byConfident AI