Skip to main content
This page consolidates the lower-level reference symbols used by Constrained Generation and Function Calling. Most apps don’t touch these directly β€” the high-level pages cover the usual flows. Reach here when you need to inspect schemas, build options programmatically, or wire a custom parser.

GenerationOptions

Per-request controls. Leave any field as null / nil to fall back to the manifest defaults.
GenerationOptions is a Kotlin data class bridged into Swift. Kotlin parameter defaults don’t survive the ObjC bridge, so the canonical Swift idiom is the parameterless init plus chained .with(...) builders:
Builder-style chaining (v0.10.0+):
For the legacy compat-class path (Leap.load(...) flows), GenerationOptionsCompat additionally exposes setResponseFormat(jsonSchema: String).
  • Sampling fields β€” temperature, topP, minP, topK, and repetitionPenalty. Use the model bundle’s recommended values; arbitrary defaults from generic tutorials usually underperform.
  • rngSeed β€” deterministic sampling seed for tests and reproducible runs.
  • maxTokens β€” maximum completion tokens to generate. Prompt tokens do not count toward this cap.
  • jsonSchemaConstraint β€” JSON Schema string for constrained generation. Use the higher-level helpers β€” Swift options.with(jsonSchema: T.jsonSchema()) / Kotlin setResponseFormatType<T>() β€” instead of writing the schema by hand.
  • injectSchemaIntoPrompt β€” when true (default), the schema is also appended to the system message for semantic guidance. Set false to use only the structural constraint.
  • functionCallParser β€” LFMFunctionCallParser (default), HermesFunctionCallParser(), or null/nil to disable parsing and surface raw tool-call text in Chunks.
  • enableThinking / inlineThinkingTags β€” reasoning-mode controls for models that emit <think> content.
  • extras β€” backend-specific JSON payload.

Constrained generation utilities

JSONSchemaGenerator.getJSONSchema(for:) is non-throwing β€” it forwards to the jsonSchema() method that the @Generatable macro adds to the type, so the schema is produced at compile time. Useful when embedding the schema in the prompt itself, or when you want to debug the schema the model is being constrained against.See Constrained Generation for the full @Generatable / @Guide macro reference.

Function-calling type reference

The full surface is documented in Function Calling; the type signatures here are the at-a-glance reference.
Type wrappers (StringType, NumberType, etc.) carry per-type metadata like enumValues for restricting valid inputs and description for prompt-time hints (used when the type is nested inside an array or object).

Parsers

Two parser implementations ship with the SDK on every platform:
  • LFMFunctionCallParser β€” default. Handles Liquid Foundation Model (LFM2) Pythonic-style control tokens (<|tool_call_start|> / <|tool_call_end|>).
  • HermesFunctionCallParser β€” Qwen3 and other models using the Hermes function-calling format.
Subclass LeapFunctionCallParser (Kotlin abstract class, bridged to Swift as a class with the same name) to add support for a new format.

Prompt token budgeting

getPromptTokensSize(messages:, addBosToken:) is declared directly on ModelRunner β€” no cast required. Useful when you need to estimate context usage before sending a long request.