Skip to main content

GenerationOptions

Tune generation behavior with GenerationOptions. Leave a field as nil / null to fall back to the defaults packaged with the model bundle.
data class GenerationOptions(
    val temperature: Float? = null,
    val topP: Float? = null,
    val minP: Float? = null,
    val repetitionPenalty: Float? = null,
    val jsonSchemaConstraint: String? = null,
    val functionCallParser: LeapFunctionCallParser? = LFMFunctionCallParser(),
    val injectSchemaIntoPrompt: Boolean = true,
    val topK: Int? = null,
    val rngSeed: Long? = null,
    val enableThinking: Boolean = false,
)
FieldTypeDescription
temperatureFloat?Sampling temperature.
topPFloat?Nucleus sampling probability mass.
minPFloat?Minimum probability threshold.
repetitionPenaltyFloat?Penalizes repeated tokens.
jsonSchemaConstraintString?JSON schema string for Constrained Generation.
functionCallParserLeapFunctionCallParser?Parser for tool-call tokens. Default is LFMFunctionCallParser. Use HermesFunctionCallParser for Hermes/Qwen3 formats, or null for raw text.
injectSchemaIntoPromptBooleanWhether to inject the JSON schema into the system prompt.
topKInt?Top-K sampling: only the K most likely tokens are considered.
rngSeedLong?Random number generator seed for reproducible outputs.
enableThinkingBooleanEnable the model’s thinking/reasoning mode.
Use setResponseFormat to populate jsonSchemaConstraint from a @Generatable-annotated data class:
val options = GenerationOptions(temperature = 0.6f, topP = 0.9f)
    .apply { setResponseFormat(CityFact::class) }

conversation.generateResponse(
    message = user,
    generationOptions = options,
).collect { response ->
    // Handle structured output
}

Constrained Generation Utilities

For full usage details, see the Constrained Generation guide.

JSONSchemaGenerator

Generates a JSON schema string from a @Generatable-annotated type. This schema is passed to GenerationOptions.jsonSchemaConstraint to activate constrained generation.
package ai.liquid.leap.structuredoutput

object JSONSchemaGenerator {
    @Throws(LeapGeneratableSchematizationException::class)
    fun <T : Any> getJSONSchema(
        klass: KClass<T>,
        indentSpaces: Int? = null,
    ): String
}
  • klass — the Kotlin class object created from T::class. It must be a data class annotated with @Generatable.
  • indentSpaces — a non-null value will format the JSON output into a pretty style with the given indent spaces.
If the data class cannot be supported or any other issue blocks JSON schema generation, a LeapGeneratableSchematizationException is thrown.

GeneratableFactory

Deserializes a JSON object into an instance of a @Generatable-annotated type. Available on all platforms (commonMain).
package ai.liquid.leap.structuredoutput

object GeneratableFactory {
    @Throws(LeapGeneratableDeserializationException::class)
    fun <T : Any> createFromJSONObject(
        jsonObject: JSONObject,
        klass: KClass<T>,
    ): T

    @Throws(LeapGeneratableDeserializationException::class)
    inline fun <reified T : Any> createFromJSONObject(jsonObject: JSONObject): T {
        return createFromJSONObject(jsonObject, T::class)
    }
}
The single-parameter version can be called when the return type can be inferred from context. It is a convenience wrapper around the full version.
  • jsonObject — the JSON object used as the data source for creating the generatable data class instance.
  • klass — the Kotlin class object created from T::class. It must be a data class annotated with @Generatable.

Annotations

package ai.liquid.leap.structuredoutput

@Target(AnnotationTarget.CLASS)
annotation class Generatable(val description: String)

@Target(AnnotationTarget.PROPERTY)
annotation class Guide(val description: String)
  • @Generatable marks a data class for use as a generation constraint.
  • @Guide adds a human-readable description to a field, helping the model produce accurate values.

Function Calling Types

For full usage details, see the Function Calling guide.

LeapFunction

Describes the signature of a function that can be called by the model.
data class LeapFunction(
    val name: String,
    val description: String,
    val parameters: List<LeapFunctionParameter>,
)
  • name — name of the function.
  • description — a human- and LLM-readable description of the function.
  • parameters — the list of parameters accepted by the function.

LeapFunctionParameter

Describes the signature of a parameter in a function.
data class LeapFunctionParameter(
    val name: String,
    val type: LeapFunctionParameterType,
    val description: String,
    val optional: Boolean = false,
)
  • name — name of the parameter.
  • type — data type of the parameter.
  • description — a human- and LLM-readable description of the parameter.
  • optional — whether this parameter is optional.

LeapFunctionParameterType

Represents a data type for function parameters. All types must be valid JSON Schema types.
sealed class LeapFunctionParameterType(description: kotlin.String? = null) {
    val description: kotlin.String? = description

    class String(val enumValues: List<kotlin.String>? = null, description: kotlin.String? = null)
    class Number(val enumValues: List<kotlin.Number>? = null, description: kotlin.String? = null)
    class Integer(val enumValues: List<Int>? = null, description: kotlin.String? = null)
    class Boolean(description: kotlin.String? = null)
    class Null
    class Array(val itemType: LeapFunctionParameterType, description: kotlin.String? = null)
    class Object(
        val properties: Map<kotlin.String, LeapFunctionParameterType>,
        val required: List<kotlin.String> = listOf(),
        description: kotlin.String? = null,
    )
}
VariantDescription
StringA string literal. enumValues restricts accepted values.
NumberA number (integer or floating point). enumValues restricts accepted values.
IntegerAn integer literal. enumValues restricts accepted values.
BooleanA boolean literal.
NullAccepts only null.
ArrayAn array. itemType describes the element type.
ObjectAn object. properties maps property names to types; required lists mandatory properties.

LeapFunctionCall

Describes a function call request generated by the model.
data class LeapFunctionCall(
    val name: String,
    val arguments: Map<String, Any?>,
)
  • name — name of the function to be called.
  • arguments — the arguments for the call. Values can be strings, numbers, booleans, null, lists (arrays), or maps/dictionaries (objects).

Function Call Parsers

Function call parsers convert raw tool-call tokens from the model into LeapFunctionCall instances.
Two built-in implementations of LeapFunctionCallParser:
  • LFMFunctionCallParser — parses Liquid Foundation Model (LFM2) Pythonic function calls. This is the default.
  • HermesFunctionCallParser — parses Hermes/Qwen3 function calling format.
Set the parser to nil / null in GenerationOptions to receive raw tool-call text instead.