rshankras/claude-code-apple-skills/foundation-models
Claude Code and agent skill by rshankras/claude-code-apple-skills
- community
Checking that the SKILL.md file is still in the repository.
On-device LLM integration using Apple's Foundation Models framework. Use when implementing AI text generation, structured output, or tool calling.
Install
npx vskill@latest install rshankras/claude-code-apple-skills/foundation-modelsSKILL.md
Foundation Models
Integrate Apple's on-device LLM into your apps for privacy-preserving AI features. Companion references: safety-and-guardrails.md (model limits, prompt design, the four-layer safety stack), models-and-agents.md (Private Cloud Compute, LanguageModel protocol, vision input, DynamicProfile agentic sessions — the iOS 27 wave), and utilities-package.md (Apple's open-source utilities package: OpenAI-compatible endpoints, just-in-time Skills, history compression).
When This Skill Activates
- User wants AI text generation features
- User needs structured data from natural language
- User asks about prompting or LLM integration
- User wants to implement AI assistants or agentic features (tool loops, multi-profile sessions)
- User needs content summarization or extraction
- User asks about Private Cloud Compute, guardrails, or model safety
Model Fit — Check Before Building
The on-device model is ~3B parameters (2-bit quantized): built for summarization, extraction, classification, tagging, revision, short chat — not math, code generation, facts, or world knowledge (WWDC25 248). For capability boundaries, prompt-design rules, and the safety stack, read safety-and-guardrails.md first. For anything bigger, PrivateCloudComputeLanguageModel (32k context, reasoning) and third-party backends are in models-and-agents.md.
Quick Start
1. Check Availability
2. Create a Session
3. Generate Response
Prompt Engineering Best Practices
The Instruction Formula
Instructions set the model's persona and constraints. They're prioritized over prompts.
Example:
Instruction Components
| Component | Purpose | Example | |
|---|---|---|---|
| Role | Define persona | "You are a travel expert" | |
| Task | What to do | "Help plan itineraries" | |
| Style | Output format | "Use bullet points, be concise" | |
| Safety | Boundaries | "Don't provide medical advice" |
Effective Prompts
Prompts are user inputs. Make them:
| Principle | Bad | Good | |
|---|---|---|---|
| Specific | "Help with cooking" | "Suggest a 30-minute vegetarian dinner" | |
| Constrained | "Tell me about dogs" | "Describe Golden Retrievers in 3 sentences" | |
| Focused | "I need help with many things" | "What ingredients substitute for eggs in baking?" |
Prompt Patterns
Question Pattern:
Command Pattern:
Extraction Pattern:
Transformation Pattern:
Structured Output with @Generable
Get typed Swift data instead of raw strings.
Define Generable Types
@Guide Constraints
| Constraint | Use Case | Example | |
|---|---|---|---|
.range(min...max) | Numeric bounds | .range(1...100) | |
.options([...]) | Enum-like choices | .options(["Low", "Medium", "High"]) | |
.count(n) | Exact array length | .count(5) | |
.count(min...max) | Array length range | .count(3...10) |
Two Rules the Macro Hides (WWDC25 301)
- Don't re-describe your schema in the prompt. The framework injects your
@Generabletype's details "in a specific format that the model has been trained on" — hand-written "respond in JSON with fields…" text duplicates it and wastes tokens. Constrained decoding masks invalid tokens per-step, so structural correctness is guaranteed, not prompted for. - Property order is generation order. "Properties are generated in the order they are declared on your Swift struct… you may find that the model produces the best summaries when they're the last property" (WWDC25 286). Put conditioning fields (context, inputs, reasoning) before the properties that should depend on them; put summaries last. This affects output quality and streaming animations.
For schemas only known at runtime, build a DynamicGenerationSchema (supports arrayOf: and referenceTo: cross-references), validate with GenerationSchema(root:dependencies:) (throws on unresolved references), respond via session.respond(to:schema:), and read untyped values with response.content.value(String.self, forProperty: "question").
Generate Structured Data
Complex Nested Structures
Tool Calling
Let the model call your code to access data or perform actions.
Define a Tool
Rules from the deep dive (WWDC25 301):
- Name = verb, description = one sentence. "These strings are put verbatim in your prompt. So longer strings means more tokens, which can increase the latency." No abbreviations, no implementation details.
- Arguments are `@Generable` — guided generation guarantees valid arguments; nest
@Generableenums to give the model a closed set of options. - The session holds one instance for its whole lifetime — tools may be stateful (e.g. track already-returned results to avoid repeats).
- Tools can be called in parallel within a single request — tool state must be concurrency-safe.
- Tool output lands in the transcript like model output — it consumes context window.
Use Tools in Session
Tool Error Handling
Snapshot Streaming
Show responses as they generate for better UX.
Stream to SwiftUI
Multi-Turn Conversations
Reuse sessions to maintain context.
Error Handling
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassedPattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/apple-intelligence/foundation-models/SKILL.md
Popularity
- Repository stars
- 770
- Repository forks
- 74
- 7-day trend score
- 33
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 18 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/rshankras/claude-code-apple-skills/foundation-models)