<!--
{
  "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/ToolExpectation",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Evaluations"
    ],
    "preciseIdentifier" : "s:11Evaluations15ToolExpectationV"
  },
  "title" : "ToolExpectation"
}
-->

# ToolExpectation

A specification for an expected tool call, or a group of expectations
that can be satisfied in any order.

```
struct ToolExpectation
```

## Overview

Most commonly, a `ToolExpectation` identifies a single tool by name and
optionally validates its arguments:

```swift
ToolExpectation("getWeather", arguments: [
    .exact(argumentName: "location", value: "Paris, France")
])
```

For ordered sequences where multiple tools must all be called at the same
position but their relative order doesn’t matter, use [`anyOrder(_:)`](/documentation/Evaluations/ToolExpectation/anyOrder(_:)):

```swift
ToolExpectation.anyOrder([
    ToolExpectation("fetchData"),
    ToolExpectation("fetchMetadata"),
])
```

## Topics

### Creating an expectation

[`init(String, arguments: [ArgumentMatcher])`](/documentation/Evaluations/ToolExpectation/init(_:arguments:))

Creates a new tool expectation.

### Creating any-order groups

[`static func anyOrder([ToolExpectation]) -> ToolExpectation`](/documentation/Evaluations/ToolExpectation/anyOrder(_:))

Creates a group of expectations that must all be satisfied at the same
sequential position, but can occur in any relative order.

### Accessing expectation details

[`var name: String`](/documentation/Evaluations/ToolExpectation/name)

The name of the tool that the evaluation expects the model to call.

[`var arguments: [ArgumentMatcher]`](/documentation/Evaluations/ToolExpectation/arguments)

The argument matchers to validate against the tool call.

[`var isAnyOrderGroup: Bool`](/documentation/Evaluations/ToolExpectation/isAnyOrderGroup)

A Boolean value that indicates whether this expectation represents a group of expectations
that can be satisfied in any order.

### Matching arguments

[`enum ArgumentMatcher`](/documentation/Evaluations/ArgumentMatcher)

The values that define how to validate a tool-call argument.

### Initializers

[`init(from: any Decoder) throws`](/documentation/Evaluations/ToolExpectation/init(from:))

Creates a tool expectation by decoding from the given decoder.

### Instance Properties

[`var generatedContent: GeneratedContent`](/documentation/Evaluations/ToolExpectation/generatedContent)

The generated content representation of this tool expectation.

### Instance Methods

[`func encode(to: any Encoder) throws`](/documentation/Evaluations/ToolExpectation/encode(to:))

Encodes this tool expectation into the given encoder.

### Type Properties

[`static var generationSchema: GenerationSchema`](/documentation/Evaluations/ToolExpectation/generationSchema)

The generation schema for this tool expectation.

### Enumerations

[`enum PartiallyGenerated`](/documentation/Evaluations/ToolExpectation/PartiallyGenerated)

A partially generated form of a tool expectation.

### Default Implementations

[ConvertibleFromGeneratedContent Implementations](/documentation/Evaluations/ToolExpectation/ConvertibleFromGeneratedContent-Implementations)

## Relationships

### Conforms To

[`ConvertibleToGeneratedContent`](/documentation/FoundationModels/ConvertibleToGeneratedContent)

[`InstructionsRepresentable`](/documentation/FoundationModels/InstructionsRepresentable)

[`PromptRepresentable`](/documentation/FoundationModels/PromptRepresentable)

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

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

[`Generable`](/documentation/FoundationModels/Generable)

[`ConvertibleFromGeneratedContent`](/documentation/FoundationModels/ConvertibleFromGeneratedContent)

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

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

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

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

---

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)