Skip to main content
coreydaley.dev

Apple's on-device model is better from Swift than from Shortcuts

When I tested Apple Intelligence in Shortcuts, the On-Device option had one failure that mattered most to me: asked to return a dictionary, it returned a bulleted list of text, three times out of three. Shortcuts couldn’t read the fields back out.

Apps don’t go through Shortcuts. They call Apple’s on-device model with the Foundation Models framework, so I wrote a small Swift program and asked the same questions on macOS 27.2, on a Mac with an M2 Pro. The answer quality looked the same; what I could get out of it didn’t.

Typed output works

The framework lets you describe the answer you want as a Swift type, marked @Generable, and the model fills it in:

import FoundationModels

@Generable
struct Receipt {
    @Guide(description: "The store's name")
    var store: String
    @Guide(description: "Purchase date as YYYY-MM-DD")
    var date: String
    var total: Double
    @Guide(description: "Item names only, no prices")
    var items: [String]
}

let session = LanguageModelSession()
let receipt = try await session.respond(
    to: "Extract the receipt details.\n\n" + receiptText,
    generating: Receipt.self
).content

Given the same grocery receipt I’d used in Shortcuts, it returned the store, date, total and all three items correctly, three times out of three, in about 1.2 seconds each. No parsing, no JSON in a code block: a Receipt with a Double total. Whatever happens with Shortcuts’ Dictionary option on-device, the framework can get structured data out when you ask this way. Simple questions took about 0.4 seconds once the model was loaded; the first request took about 2.

The arithmetic is still wrong

The other half of my Shortcuts test was a time sum: a train leaves at 9:40, the trip takes 2 hours 35 minutes, and it’s 15 minutes late. From Swift, the on-device model answered “11:15” three times out of three, exactly as Shortcuts’ On-Device option did. (It’s 12:30.) The framework changes how you get answers out, not how good they are. Anything that depends on dates or numbers still needs checking in code.

8,192 tokens, and it tells you

The model reports its own context size, and the framework can count tokens before you send anything:

let model = SystemLanguageModel.default
print(model.contextSize)                              // 8192 on macOS 27
let tokens = try await model.tokenCount(for: prompt)

On macOS 26 the same property reports 4,096. A 40,000-character prompt of plain sentences was 7,555 tokens and worked, in about 11 seconds. At 48,000 characters my count said 9,064 tokens, and the request failed with a specific error: “Content contains 9118 tokens, which exceeds the maximum allowed context size of 8192.” The request adds tokens of its own, so leave headroom. That’s close to where Shortcuts’ On-Device option stopped, at about 41,600 characters.

The cloud model didn’t answer

macOS 27 also lets apps use Apple’s server model on Private Cloud Compute, through PrivateCloudComputeLanguageModel. In my test program it reported itself available, with a 32,768-token context, and then the request failed with “LanguageModelError error -1”, wrapping a ModelManagerError 1046. Apple’s developer session says developers apply for access, and its June announcement limits it to Small Business Program members with fewer than two million first-time downloads. My program was an ad-hoc-signed command-line tool with no developer team, so that’s the likely reason; I didn’t confirm it.

What I’d take from it

If your app needs structured data from text, the on-device model can do it on the Mac itself, as long as you define the shape in Swift. Apple’s developer session says the on-device model works offline and has no request limits. Just don’t trust it with arithmetic, and count tokens before you send anything long. Shortcuts users get this model through a narrower door; the Apple Intelligence in Shortcuts guide has the comparison.

What would you have an on-device model fill in for you, if you could hand it your own Swift types?

Related posts