MLX Structured
A Swift library for constraining large-language-model output to a schema, regular expression or custom grammar during generation on Apple's MLX framework, built on the XGrammar constrained-decoding library.
MLX Structured is a Swift library for structured output generation using constrained decoding, built on top of the XGrammar library. A grammar can be defined from a JSON Schema, a Swift Generable type on newer OS versions, a regular expression, an EBNF rule, or a composable grammar builder that combines fixed text, schemas and regular expressions into one format.
The defined grammar is passed as an extra argument to MLX's text-generation calls, so output is constrained token by token as it streams, for example to force a tool-calling format. The library installs as a Swift package dependency and targets projects that already use MLX for on-device language-model inference.