Introducing Confident Monitor

Pull Datasets

Pull datasets locally to use them for evaluation.

Overview

In the previous section, we learnt how to push and queue goldens via the Confident 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)
  • Run evals on Confident AI instead, with the Confident AI SDK

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 Confident 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 the Confident 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 Confident 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=[...])

Run Evals on Confident AI

The steps above run metrics locally with deepeval. To have Confident AI run them instead, start an evaluation of the dataset against a metric collection. Confident AI evaluates the dataset's finalized goldens, using the actual outputs stored on them or ones it generates for you. The SDK reads your project key from CONFIDENT_PROJ_API_KEY (more on project keys).

Pass the dataset's id, which you get back whenever you push to it, and the name of the metric collection to evaluate against. Create a metric collection if you haven't yet:

main.py
from confident_ai import ConfidentAI

client = ConfidentAI()

result = client.datasets.run_evaluation(
    dataset_id="<DATASET-ID>",
    metric_collection="Answer Quality",
)

This evaluates the actual outputs already stored on the goldens. To generate them first, also pass an AI connection's id or a prompt's alias, never both. The call returns as soon as the test run is created, and the evaluation carries on in the background.

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 confident_ai import ConfidentAI

client = ConfidentAI()

dataset = client.dataset(dataset_id="<DATASET-ID>")
dataset.pull()

for golden in dataset.goldens:
    columns = golden.custom_column_key_values or {}
    difficulty = columns.get("difficulty")
    category = columns.get("category")

    actual_output = llm_app(golden.input, difficulty=difficulty)

Using Images

Images in golden text fields (such as input or scenario) come back as [CONFIDENT:IMAGE:<url>] markers, each holding a signed link to the image. parse_multimodal splits a field into strings and Media in order, so you can build the content parts your MLLM of choice expects. Here's how you'd build them for openai:

main.py
from confident_ai import ConfidentAI, Media, parse_multimodal

client = ConfidentAI()

dataset = client.dataset(dataset_id="<DATASET-ID>")
dataset.pull()

for golden in dataset.goldens:
    content = []
    for part in parse_multimodal(golden.input):
        if isinstance(part, Media):
            content.append({"type": "image_url", "image_url": {"url": part.url}})
        else:
            content.append({"type": "text", "text": part})

This example is for single-turn goldens. For multi-turn goldens, parse scenario and each turn's content the same way.

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

Last updated on

Built byConfident AI