JsonSchemaGenerator

Walks a kotlinx.serialization SerialDescriptor and produces a JSON Schema (draft 2020-12-ish subset) suitable for handing to LLM provider APIs.

Supported descriptors:

  • Primitives → type: "string|number|integer|boolean"

  • Classes / objects → type: "object" with properties and required

  • Lists → type: "array" with items

  • Maps → type: "object" with additionalProperties

  • Enums → type: "string" with enum

Sealed and open polymorphic descriptors fall back to {} (any). Phase 1 does not need them; revisit when adding richer structured-output use cases.

Functions

Link copied to clipboard
inline fun <T> schemaFor(): JsonObject
fun schemaFor(descriptor: SerialDescriptor): JsonObject