Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FoundationModels

A small SwiftUI demo app that moderates user-entered team names entirely on-device using Apple's Foundation Models framework.

You add friendly five-a-side football teams to a list. Before a name is accepted, an on-device language model checks it for profanity, slurs, sexual content, or hateful language — no network calls, nothing leaves the device.

How it works

  • ContentView — the team list UI. Adding a name runs it through the moderator and either appends the team or shows a rejection reason.
  • TeamNameModerator — wraps a LanguageModelSession and performs moderation. It uses two layers of protection:
    1. Apple's built-in safety guardrails (guardrailViolation) catch blatant content.
    2. A guided-generation classifier judges subtler cases.
  • TeamNameVerdict — a @Generable struct used for guided generation. Fields are ordered so the model writes its assessment before committing to the isInappropriate boolean, which improves accuracy.
  • Team — a simple Identifiable model.

Design notes

  • Fails open. If the model isn't available on the device, or a check can't complete, names are allowed rather than blocking the user.
  • Prewarming. The session is warmed up when the text field gains focus to reduce first-check latency.
  • Prompt safety. Moderation instructions deliberately avoid quoting example profanity, since the guardrail scans the entire prompt.

Requirements

  • Xcode 16 or later
  • A device/OS version that supports the Foundation Models framework with Apple Intelligence enabled
  • Swift 5.0+ language mode

Note: The Swift module is named TeamNamesApp (set via PRODUCT_MODULE_NAME) so it doesn't collide with Apple's FoundationModels framework, while the app product is still named FoundationModels.

Running

  1. Open FoundationModels.xcodeproj in Xcode.
  2. Select a supported device (or simulator with Apple Intelligence available).
  3. Build and run.

On unsupported devices the app still runs — moderation simply allows all names.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages