Package-level declarations

Types

Link copied to clipboard

Exception indicating an error during the parsing of structured output from a language model.

Link copied to clipboard
abstract class StructuredData<TStruct, TSchema : LLMParams.Schema>(val id: String, val schema: TSchema, val examples: List<TStruct>) : StructuredDataDefinition

Represents a generic structure for handling data with a specific schema.

Link copied to clipboard

Represents the definition of structured data, enabling content construction and customization.

Link copied to clipboard
sealed interface StructuredOutput<T>

Defines how structured outputs should be generated.

Link copied to clipboard
data class StructuredOutputConfig<T>(val default: StructuredOutput<T>? = null, val byProvider: Map<LLMProvider, StructuredOutput<T>> = emptyMap(), val fixingParser: StructureFixingParser? = null)

Configures structured output behavior. Defines which structures in which modes should be used for each provider when requesting a structured output.

Link copied to clipboard

An object that provides utilities for formatting structured output prompts.

Link copied to clipboard
data class StructuredResponse<T>(val structure: T, val message: Message.Assistant)

Represents a container for structured data parsed from response message.

Link copied to clipboard
class StructureFixingParser(val fixingModel: LLModel, val retries: Int, fixingPrompt: (builder: PromptBuilder, content: String, structure: StructuredData<*, *>, exception: SerializationException) -> PromptBuilder = ::defaultFixingPrompt)

Helper fixing parser for handling malformed structured data that uses LLMs to attempt to correct any errors in the provided content to produce valid structured outputs.

Properties

Link copied to clipboard

Registered mapping of providers to their respective known simple JSON schema format generators. The registration is supposed to be done by the LLM clients when they are loaded, to communicate their custom formats.

Link copied to clipboard

Registered mapping of providers to their respective known full JSON schema format generators. The registration is supposed to be done by the LLM clients on their initialization, to communicate their custom formats.

Functions

Link copied to clipboard
inline suspend fun <T> PromptExecutor.executeStructured(prompt: Prompt, model: LLModel, examples: List<T> = emptyList(), fixingParser: StructureFixingParser? = null): Result<StructuredResponse<T>>
suspend fun <T> PromptExecutor.executeStructured(prompt: Prompt, model: LLModel, serializer: KSerializer<T>, examples: List<T> = emptyList(), fixingParser: StructureFixingParser? = null): Result<StructuredResponse<T>>

Executes a prompt with structured output, enhancing it with schema instructions or native structured output parameter, and parses the response into the defined structure.

Link copied to clipboard
fun <T> TextContentBuilderBase<*>.structure(structure: StructuredData<T, *>, value: T)

Adds a structured representation of the given value to the TextContentBuilderBase.