Generable

Asked on 06/12/2025

1 search

The term "Generable" refers to a macro in the Foundation Models framework introduced by Apple. It allows developers to generate structured data using Swift types. By applying the generable macro to structs and enums, developers can create a schema at compile time, which the model uses to produce the expected structure. This macro also generates an initializer that is automatically called when making a request to a session, allowing for the generation of instances of the structure.

Generable is particularly useful for ensuring structural correctness and avoiding the need for manual parsing of the model's output. It uses a technique called constrained decoding to prevent the model from making structural mistakes, such as generating invalid field names. This makes it a powerful tool for generating structured output from on-device large language models (LLMs).

For more details, you can refer to the session Deep dive into the Foundation Models framework (07:57).