Best practices while using foundation model framework
Asked on 2025-07-05
1 search
To effectively use the Foundation Models framework, here are some best practices highlighted during the WWDC sessions:
-
Prompt Engineering:
- Control the content length by specifying phrases like "in three sentences" for shorter outputs or "in detail" for longer ones.
- Define the style and voice by specifying a role in your prompt. For example, you can instruct the model to generate content in a specific tone or style.
-
Safety and Trust:
- Ensure your app does not generate inappropriate content by leveraging the guardrails provided by the Foundation Models framework. These guardrails help block harmful inputs and outputs.
- Handle user input with care and consider the potential impact of the model's responses on users.
-
Guided Generation:
- Use the
Generable
andGuide
macros to generate structured outputs that can be directly used in your app. This helps in creating data structures without worrying about parsing the model's output.
- Use the
-
Stateful Sessions:
- Utilize stateful sessions to maintain context across multiple interactions with the model. This can be particularly useful for applications that require multi-turn conversations.
-
Tool Calling:
- Implement tool calling to allow the model to autonomously execute code defined in your app, enhancing the model's capabilities.
For more detailed information on these practices, you can refer to the session Explore prompt design & safety for on-device foundation models (06:14) and Code-along: Bring on-device AI to your app using the Foundation Models framework (02:30).

Explore prompt design & safety for on-device foundation models
Design generative AI experiences that leverage the strengths of the Foundation Models framework. We’ll start by showing how to design prompts for the on-device large language model at the core of Apple Intelligence. Then, we’ll introduce key ideas around AI safety, and offer concrete strategies to make your generative AI features safe, reliable, and delightful.

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.

Discover machine learning & AI frameworks on Apple platforms
Tour the latest updates to machine learning and AI frameworks available on Apple platforms. Whether you are an app developer ready to tap into Apple Intelligence, an ML engineer optimizing models for on-device deployment, or an AI enthusiast exploring the frontier of what is possible, we’ll offer guidance to help select the right tools for your needs.