The Evaluations framework in Xcode 27 lets developers generate and validate synthetic test data at scale using the SampleGenerator API, then run robust evaluations against agentic workflows that involve tool calling ā all from Swift code.
⢠Eliminates hand-writing hundreds of test cases: the makeSamples / SampleGenerator API generates diverse synthetic data programmatically, exposing gaps a small handcrafted dataset would miss.
⢠Built-in validation closures let you enforce structural rules (tag count, string length, casing) per sample at generation time, keeping bad data out of your evaluation set automatically.
⢠Supports agentic / tool-calling workflows specifically, so you can evaluate multi-step AI features ā not just single prompt-response pairs ā and track quality over time with the Xcode 27 Evaluations Report.
Demonstrates using SampleGenerator with a custom session provider and validation closure to expand a small seed dataset of book reviews into 100 synthetic samples, rejecting any that violate structural rules.
import Evaluations
import FoundationModels
// MARK: - Domain model
struct BookSample: Codable, Sendable {
let review: String
let tags: [String]
}
// MARK: - Seed data
let seedSamples: [ModelSample<String, [String]>] = [
ModelSample(
prompt: "A sweeping romance set in Regency England with wit and social commentary.",
expectedOutput: ["romance", "classic", "regency", "social-commentary"]
),
ModelSample(
prompt: "A gothic horror tale of ambition gone terribly wrong and its monstrous consequences.",
expectedOutput: ["horror", "gothic", "classic", "science-fiction"]
),
ModelSample(
prompt: "An adventure on the high seas chasing an obsessive white whale to the ends of the earth.",
expectedOutput: ["adventure", "classic", "sea", "obsession"]
)
]
// MARK: - Synthetic generation
func generateExpandedDataset() async throws -> [ModelSample<String, [String]>] {
let generationPrompt = """
Generate diverse book review samples covering a wide range of genres,
moods, tones, and lengths. Each review should feel like it was written
by a real reader. Vary sentence complexity and emotional register.
"""
let generator = SampleGenerator(
prompt: generationPrompt,
dataset: seedSamples,
targetCount: 20,
sessionProvider: {
// Use on-device model; swap to PrivateCloudComputeLanguageModel for larger context
let session = LanguageModelSession(
instructions: Instructions("""
You generate synthetic book review samples for an evaluation dataset.
Rules:
- Reviews must be at least 100 characters.
- Generate between 3 and 8 lowercase tags per review.
- Cover a mix of genres: literary, sci-fi, mystery, romance, horror, non-fiction.
""")
)
return session
},
samplingStrategy: .random,
validator: { sample in
// Rule 1: review must be at least 100 characters
guard sample.prompt.count >= 100 else {
return .invalid(reason: "Review too short (\(sample.prompt.count) chars)")
}
// Rule 2: between 3 and 8 tags
let tagCount = sample.expectedOutput.count
guard (3...8).contains(tagCount) else {
return .invalid(reason: "Tag count out of range: \(tagCount)")
}
// Rule 3: all tags must be lowercase
let allLower = sample.expectedOutput.allSatisfy { $0 == $0.lowercased() }
guard allLower else {
return .invalid(reason: "Tags contain uppercase characters")
}
return .valid
}
)
var expandedDataset = seedSamples
for try await newSample in generator.run() {
expandedDataset.append(newSample)
}
print("Valid samples: \(generator.samples.count)")
print("Invalid samples: \(generator.invalidSamples.count)")
return expandedDataset
}Foundation Models is a new Apple framework introduced in iOS 27 that gives developers on-device access to the same Apple Intelligence language model powering system features, enabling text generation, structured output, and tool-calling entirely on-device without a network connection.
iOS 27 opens the Foundation Models framework to third-party LLM providers via a new public LanguageModel protocol, enabling anyone to integrate custom, server-based, or open-source models using the same Swift API as Apple's on-device system model.
App Schemas let developers describe their app's content and actions using pre-defined domain schemas (like the Calendar domain) so Siri can understand, search, and act on app data without custom NLP. Entities conforming to IndexedEntity are donated to Spotlight's semantic index, enabling natural-language queries over app content.
In-depth guide
iOS 27 On-Device AI & Apple Intelligence ā⢠targetCount includes your seed samples ā if you pass 13 seeds and set targetCount: 100, only 87 new samples are generated. ⢠The sessionProvider may be called more than once if the context window is exhausted mid-run; keep instructions self-contained and stateless. ⢠The validator closure runs per-sample in isolation with no cross-sample context, so diversity checks must be done after the run by inspecting the full samples array. ⢠Evaluations framework is new in Xcode 27 ā no back-deployment to earlier SDKs.
Default generation uses the on-device Apple Intelligence model; switching to PrivateCloudComputeLanguageModel requires network and entitlement. Apple Intelligence must be enabled on the device.
Visual Intelligence brings iOS 17's Visual Look Up capabilities to a new developer-facing API surface in iOS 27, letting apps pipe live camera frames or static images through on-device scene understanding to extract subjects, text, barcodes, and rich semantic labels without any cloud round-trip.