Skip to content

// On-device LLM in Swift — LanguageModelSession, @Generable guided generation, tool calling, streaming, fallback.

Apple Foundation Models

skill --stat
  • last update

    Jun 24, 2026

  • license

    MITv1.0.0

  • format

    SKILL.md

quickstart.sh
3 steps
  1. Install

    // Downloads SKILL.md into ~/.claude/skills/apple-foundation-models-on-device-llm/

    $ curl -fsSL --create-dirs -o ~/.claude/skills/apple-foundation-models-on-device-llm/SKILL.md https://claudeskil.com/skills/apple-foundation-models-on-device-llm/SKILL.md
  2. Invoke

    // Inside Claude Code, type the skill name as a slash command

    > /apple-foundation-models-on-device-llm help me ship this
  3. Or copy this from the README

    // extracted swift block

    $ curl -fsSL --create-dirs -o ~/.claude/skills/apple-foundation-models-on-device-llm/SKILL.md https://claudeskil.com/skills/apple-foundation-models-on-device-llm/SKILL.md
    
    import FoundationModels
    
    @Generable struct Recipe {
        @Guide(description: "Dish name") var title: String
apple-foundation-models-on-device-llm/
references
SKILL.md
readonly
name:
Apple Foundation Models
slug:
apple-foundation-models-on-device-llm
version:
v1.0.0
license:
MIT
author:
@chiragthummar16
categories:
tags:
#swift#foundation-models#on-device-ai#apple-intelligence#guided-generation
description:

On-device LLM in Swift — LanguageModelSession, @Generable guided generation, tool calling, streaming, fallback.

README.md

apple-foundation-models-on-device-llm/README.md
5 sections

Apple Foundation Models

This skill helps Swift developers build features on top of Apple's Foundation Models framework — the on-device large language model that ships with Apple Intelligence on iOS, iPadOS, and macOS. It covers the practical surface area you actually call: creating a LanguageModelSession, getting typed output with @Generable, streaming partial results, exposing app functions through the Tool protocol, and gating everything behind availability checks. It's for people writing real Swift code, not prompt experiments.

When to use it

  • You want a chat, summarization, classification, or extraction feature that runs locally with no network call and no per-token cost.
  • You need the model to return a Swift struct you can use directly, not a string you have to parse.
  • You want to let the model call into your app (search a database, fetch the weather) via tool calling.
  • You're handling the cases where the model isn't ready — device unsupported, Apple Intelligence off, or assets still downloading.

How it works

The entry point is SystemLanguageModel.default. Always branch on model.availability, which returns .available or .unavailable(reason) (cases include .deviceNotEligible, .appleIntelligenceNotEnabled, .modelNotReady).

A LanguageModelSession holds the conversation and is created with instructions:. Call session.prewarm() early to load assets before the first request. Use session.respond(to:) for a full reply, or session.streamResponse(to:) to get an async sequence of snapshots.

For structured output, annotate a type with @Generable and constrain fields with @Guide(description:) (and constraints like ranges or .count). Pass generating: MyType.self to respond, and the framework uses guided generation to guarantee the output conforms. Streaming yields a MyType.PartiallyGenerated whose properties fill in incrementally. Tools conform to the Tool protocol with a @Generable Arguments type and a call(arguments:) method, then are handed to the session via tools:.

swift
curl -fsSL --create-dirs -o ~/.claude/skills/apple-foundation-models-on-device-llm/SKILL.md https://claudeskil.com/skills/apple-foundation-models-on-device-llm/SKILL.md

import FoundationModels

@Generable struct Recipe {
    @Guide(description: "Dish name") var title: String
    @Guide(.count(3...8)) var steps: [String]
}

let model = SystemLanguageModel.default
guard case .available = model.availability else { return }

let session = LanguageModelSession(instructions: "You are a concise chef.")
let recipe = try await session.respond(to: "Quick pasta", generating: Recipe.self).content

Tips & gotchas

  • A session is single-threaded for requests — check session.isResponding before sending another; concurrent calls throw.
  • The context window is limited; long histories raise exceededContextWindowSize. Start a fresh session and carry over a summary.
  • GenerationOptions lets you set temperature and sampling; pass it to respond.
  • Guided generation only guarantees shape, not facts. Validate values yourself.

FAQ

Which devices run it? Apple-Intelligence-capable hardware (e.g. A17 Pro / M-series) with the feature enabled. Everything else reports .unavailable.

Can I fine-tune it? No weight training, but you steer behavior with instructions, @Guide, and an optional adapter via SystemLanguageModel(adapter:).

Does it work offline? Yes — inference is fully on-device once assets are downloaded.

$ cat reviews/

Reviews

// No reviews yet. Be the first.
Loading review form…

$ ls related/

explore all →