JsonSchemaGenerator

abstract class JsonSchemaGenerator(source)

JSON schema generator from Kotlin serializable classes, to be used with LLM structured output functionality. This generator creates JSON schemas that can be included in LLM prompts to encourage structured outputs that match your Kotlin data models. The generated schemas help LLMs understand the expected response format.

Inheritors

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
data class GenerationContext(val json: Json, val descriptor: SerialDescriptor, val processedTypeDefs: MutableMap<SerialDescriptor, JsonObject>, val currentDefPath: List<SerialDescriptor>, val descriptionOverrides: Map<String, String>, val currentDescription: String?)

Holds intermediate and stateful information about the current schema generation process.

Functions

Link copied to clipboard
abstract fun generate(json: Json, name: String, serializer: KSerializer<*>, descriptionOverrides: Map<String, String>): LLMParams.Schema.JSON

Generates a JSON schema representation based on the provided input parameters. Should call process to process the schema tree.