executeStructured
Executes a prompt and ensures the response is properly structured by applying automatic output coercion.
This method enhances structured output parsing reliability by:
Injecting structured output instructions into the original prompt
Executing the enriched prompt to receive a raw response
Using a separate LLM call to parse/coerce the response if direct parsing fails
Unlike execute(prompt, structure) which simply attempts to parse the raw response and fails if the format doesn't match exactly, this method actively works to transform unstructured or malformed outputs into the expected structure through additional LLM processing.
Return
A StructuredResponse containing both parsed structure and raw text
Parameters
The structured data definition with schema and parsing logic
The prompt to execute
The main model to execute prompt
Number of parsing attempts before giving up
LLM used for output coercion (transforming malformed outputs)
Throws
if parsing fails after all retries