executeStructured
Executes a prompt with structured output, enhancing it with schema instructions or native structured output parameter, and parses the response into the defined structure.
Note: While many language models advertise support for structured output via JSON schema, the actual level of support varies between models and even between versions of the same model. Some models may produce malformed outputs or deviate from the schema in subtle ways, especially with complex structures like polymorphic types.
Return
kotlin.Result with parsed StructuredResponse or error.
Parameters
The prompt to be executed.
LLM to execute requests.
A configuration defining structures and behavior.
Executes a prompt with structured output, enhancing it with schema instructions or native structured output parameter, and parses the response into the defined structure.
This is a simple version of the full executeStructured
. Unlike the full version, it does not require specifying struct definitions and structured output modes manually. It attempts to find the best approach to provide a structured output based on the defined model capabilities.
For example, it chooses which JSON schema to use (simple or full) and with which mode (native or manual).
Return
kotlin.Result with parsed StructuredResponse or error.
Parameters
The prompt to be executed.
LLM to execute requests.
Serializer for the requested structure type.
Optional list of examples in case manual mode will be used. These examples might help the model to understand the format better.
Optional parser that handles malformed responses by using an auxiliary LLM to intelligently fix parsing errors. When specified, parsing errors trigger additional LLM calls with error context to attempt correction of the structure format.
Executes a prompt with structured output, enhancing it with schema instructions or native structured output parameter, and parses the response into the defined structure.
This is a simple version of the full executeStructured
. Unlike the full version, it does not require specifying struct definitions and structured output modes manually. It attempts to find the best approach to provide a structured output based on the defined model capabilities.
For example, it chooses which JSON schema to use (simple or full) and with which mode (native or manual).
Return
kotlin.Result with parsed StructuredResponse or error.
Parameters
The structure to request.
The prompt to be executed.
LLM to execute requests.
Optional list of examples in case manual mode will be used. These examples might help the model to understand the format better.
Optional parser that handles malformed responses by using an auxiliary LLM to intelligently fix parsing errors. When specified, parsing errors trigger additional LLM calls with error context to attempt correction of the structure format.