One Logo Pool Ball
FoundationModels · IOS API REFERENCE

Generable

protocol · iOS 26.0+ · SDK 27.1

protocol Generable : ConvertibleFromGeneratedContent, ConvertibleToGeneratedContent

A type that the model uses when responding to prompts. 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`` 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`` exceeds the available context size, it throws ``LanguageModelError/contextSizeExceeded(_:)``. To reduce the size of your generable type: - Reduce the complexity of your ``Generable`` type by evaluating whether properties are necessary to complete the task. - Give your properties short and clear names. - Use ``Guide(description:)`` on properties only when it improves response quality. - Add a ``Guide(description:_:)`` with ``GenerationGuide/maximumCount(_:)`` to reduce token usage. If the ``Generable`` type includes properties with clear names the model may have all it needs to generate your type, eliminating the need of ``Guide(description:)``. For more information on managing the context window size, see <doc:managing-the-context-window>.

Members (3)

method · iOS 26.0+

asPartiallyGenerated

Swift declaration
func asPartiallyGenerated() -> Self.PartiallyGenerated

Returns the partially generated representation of the current instance.

get · iOS 27.0+

promptRepresentation

Swift declaration
var promptRepresentation: Prompt { get }

An instance that represents a prompt.

get · iOS 27.0+

instructionsRepresentation

Swift declaration
var instructionsRepresentation: Instructions { get }

An instance that represents the instructions.

Skipped declarations

No declarations were skipped in this snapshot.

All FoundationModels types →