<!--
{
  "availability" : [
    "Xcode: 27.0.0 -",
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Evaluations",
  "identifier" : "/documentation/Evaluations/Loader",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Evaluations"
    ],
    "preciseIdentifier" : "s:11Evaluations6LoaderP"
  },
  "title" : "Loader"
}
-->

# Loader

A protocol for types that supply a dataset for evaluation.

```
protocol Loader<Sample> : Sendable
```

## Overview

Use one of the built-in concrete types such as [`ArrayLoader`](/documentation/Evaluations/ArrayLoader), [`JSONLoader`](/documentation/Evaluations/JSONLoader), or [`StreamLoader`](/documentation/Evaluations/StreamLoader),
or implement this protocol directly for custom data sources.

```swift
var dataset: any Loader<ModelSample<String>> {
    ArrayLoader(samples: [
        ModelSample(prompt: "One plus one is...", expected: "Two."),
        ModelSample(prompt: "Swift is...", expected: "A powerful language."),
    ])
}
```

```swift
var dataset: any Loader<ModelSample<String>> {
    JSONLoader(url: Bundle.main.url(forResource: "prompts", withExtension: "jsonl")!)
}
```

```swift
var dataset: any Loader<ModelSample<String>> {
    StreamLoader(stream: AsyncThrowingStream<ModelSample<String>, Error> { continuation in
        Task {
            let prompts = ["One plus one is...", "Swift is..."]
            for prompt in prompts {
                continuation.yield(ModelSample(prompt: prompt, expected: ""))
            }
            continuation.finish()
        }
    })
}
```

## Topics

### Loaders

[`ArrayLoader`](/documentation/Evaluations/ArrayLoader)

A loader backed by an in-memory array.

[`JSONLoader`](/documentation/Evaluations/JSONLoader)

A loader backed by a JSON or JSONL file.

[`StreamLoader`](/documentation/Evaluations/StreamLoader)

A loader backed by a custom async sequence.

## Relationships

### Inherits From

[`Sendable`](/documentation/Swift/Sendable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

### Conforming Types

[`ArrayLoader`](/documentation/Evaluations/ArrayLoader)

[`JSONLoader`](/documentation/Evaluations/JSONLoader)

[`StreamLoader`](/documentation/Evaluations/StreamLoader)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)