how to use a foundation model
Asked on 06/18/2025
1 search
To use a foundation model with Apple's Foundation Models framework, you can follow these steps:
-
Import the Framework: Start by importing the Foundation Models framework into your project. This gives you access to the on-device large language model.
-
Create a Session: Use the framework to create a session. This session will allow you to interact with the model.
-
Send a Prompt: You can send a prompt to the model using the session. The model is capable of tasks such as text extraction, summarization, and more. You can choose to display the answer as one response or incrementally using streaming output.
-
Use Generable for Structured Output: If you need structured data, you can use the
Generable
macro to define types that the model can generate. This allows the model to produce structured responses that can be directly used in your app. -
Tool Calling: The framework supports tool calling, which allows the model to autonomously call functions you define in Swift. This can be used to fetch up-to-date content or perform actions within your app.
-
Safety and Prompt Design: The framework includes guardrails for safety, and you can add your own safety rules. It's important to carefully design your prompts and instructions to ensure the model generates appropriate content.
For a deeper understanding, you might want to explore the session Deep dive into the Foundation Models framework (00:00:00) which covers sessions, generable, dynamic schemas, and tool calling in detail.

Platforms State of the Union
Discover the newest advancements on Apple platforms.

Deep dive into the Foundation Models framework
Level up with the Foundation Models framework. Learn how guided generation works under the hood, and use guides, regexes, and generation schemas to get custom structured responses. We’ll show you how to use tool calling to let the model autonomously access external information and perform actions, for a personalized experience. To get the most out of this video, we recommend first watching “Meet the Foundation Models framework”.

Code-along: Bring on-device AI to your app using the Foundation Models framework
Develop generative AI features for your SwiftUI apps using the Foundation Models framework. Get started by applying the basics of the framework to create an awesome feature. Watch step-by-step examples of how to complement the models with tools you build, stream results, and apply further optimizations for great performance.