<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FoundationModels",
  "identifier" : "/documentation/FoundationModels/Generable",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Foundation Models"
    ],
    "preciseIdentifier" : "s:16FoundationModels9GenerableP"
  },
  "title" : "Generable"
}
-->

# Generable

A type that the model uses when responding to prompts.

```
protocol Generable : ConvertibleFromGeneratedContent, ConvertibleToGeneratedContent
```

## Overview

Annotate your Swift structure or enumeration with the `@Generable` macro to
allow the model to respond to prompts by generating an instance of your type.
Use the `@Guide` macro to provide natural language descriptions of your
properties, and programmatically control the values that the model can generate.

```swift
@Generable
struct SearchSuggestions {
    @Guide(description: "A list of suggested search terms.", .count(4))
    var searchTerms: [SearchTerm]
    @Generable
    struct SearchTerm {
        // Use a generation identifier for data structures the framework generates.
        var id: GenerationID
        @Guide(description: "A two- or three- word search term, like 'Beautiful sunsets'.")
        var searchTerm: String
    }
}
```

For every [`Generable`](/documentation/FoundationModels/Generable) type in a request, the framework converts its type and
format information to a JSON schema and provides it to the model. This contributes
to the available context window size. If the [`LanguageModelSession`](/documentation/FoundationModels/LanguageModelSession) exceeds
the available context size, it throws [`LanguageModelError.contextSizeExceeded(_:)`](/documentation/FoundationModels/LanguageModelError/contextSizeExceeded(_:)).
To reduce the size of your generable type:

- Reduce the complexity of your [`Generable`](/documentation/FoundationModels/Generable) type by evaluating whether properties
  are necessary to complete the task.
- Give your properties short and clear names.
- Use [`Guide(description:)`](/documentation/FoundationModels/Guide(description:)) on properties only when it improves response quality.
- Add a [`Guide(description:_:)`](/documentation/FoundationModels/Guide(description:_:)) with [`maximumCount(_:)`](/documentation/FoundationModels/GenerationGuide/maximumCount(_:)) to
  reduce token usage.

If the [`Generable`](/documentation/FoundationModels/Generable) type includes properties with clear names the model may have
all it needs to generate your type, eliminating the need of [`Guide(description:)`](/documentation/FoundationModels/Guide(description:)).
For more information on managing the context window size, see
[Managing the context window](/documentation/FoundationModels/managing-the-context-window).

## Topics

### Creating a Generable type

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

[`Generable(description:representNilExplicitlyInGeneratedContent:)`](/documentation/FoundationModels/Generable(description:representNilExplicitlyInGeneratedContent:))

[`Generable(name:description:representNilExplicitlyInGeneratedContent:)`](/documentation/FoundationModels/Generable(name:description:representNilExplicitlyInGeneratedContent:))

### Creating a guide

[`Guide(description:)`](/documentation/FoundationModels/Guide(description:))

[`Guide(description:_:)`](/documentation/FoundationModels/Guide(description:_:))

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

Guides that control how values are generated.

### Getting the schema

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

An instance of the generation schema.

### Converting to partially generated

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

Returns the partially generated representation of the current instance.

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

A representation of partially generated content



---

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)