StructureFixingParser

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

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.

Constructors

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

Types

Link copied to clipboard
object Companion

Companion object providing some utility functions.

Properties

Link copied to clipboard

LLM to use for processing and attempting to fix format.

Link copied to clipboard

Number of attempts to fix the structure before giving up.

Functions

Link copied to clipboard
suspend fun <T> parse(executor: PromptExecutor, structure: StructuredData<T, *>, content: String): T

Parses the given content string into an instance of the specified type using the provided structured data schema. If the initial parsing fails, attempts to fix the content based on the error and retries parsing.