eyadkelleh/apple_foundation_models_claude_skill
Overview
This skill explains how to build on-device AI features using Apple Foundation Models for iOS, macOS, iPadOS, and visionOS apps. It focuses on SystemLanguageModel, LanguageModelSession, guided generation, tool calling, prompting strategies, and safety guardrails. Use it to design private, offline-capable language experiences and structured output generation.
How this skill works
The skill inspects and explains core APIs: SystemLanguageModel and LanguageModelSession for running on-device LLMs, guided generation types (Generable, GenerationGuide) for producing typed Swift outputs, and Tool for extending models with app logic. It covers availability checks, prewarming, streaming responses, and guardrails to manage sensitive content. Examples show session.respond(), generating typed models, and registering custom tools for dynamic behavior.
When to use it
- Building on-device LLM features that must run offline and preserve user privacy
- Generating structured Swift types (e.g., models, JSON) directly from prompts
- Extending model behavior with custom, app-specific tool calls
- Crafting robust prompts and instruction sets for predictable outputs
- Adding language localization and feedback for multilingual apps
Best practices
- Check SystemLanguageModel.Availability before attempting generation
- Define clear Instructions up front to constrain model behavior
- Use guided generation (Generable/GenerationSchema) for reliable, typed outputs
- Enable SystemLanguageModel.Guardrails and handle LanguageModelSession errors defensively
- Prewarm models and use streamResponse() for lower latency and real-time UI feedback
Example use cases
- In-app assistant that runs fully on-device for private user queries
- Generating validated JSON or Swift structs (e.g., Recipe, Contact) from natural-language prompts
- Tool-backed sessions that call app services like weather or calendar via Tool implementations
- Multilingual chat or translation features using LanguageModelFeedback and localization utilities
- Real-time captioning or interactive voice agents using streaming responses
FAQ
Apple Foundation Models require iOS/iPadOS/macOS/Mac Catalyst/visionOS 26.0 or later.
How do I ensure structured output from a model?
Use guided generation types such as Generable and GenerationGuide with a defined GenerationSchema so the session returns validated typed objects.
When should I use tool calling?
Use Tool when the model must access dynamic app functionality or external data that the on-device model cannot generate reliably, like current weather or calendar events.