pub async fn generate_object<T>(
provider: &dyn DynProvider,
params: ChatParams,
config: GenerateObjectConfig,
) -> Result<GenerateObjectResult<T>, LlmError>where
T: DeserializeOwned + JsonSchema,Expand description
Generates a typed object from the LLM with schema validation.
- Derives a JSON Schema from
T(viaschemars) - Sets
structured_outputonChatParams - Calls the provider
- Parses the response text as JSON
- Validates against the schema
- Deserializes to
T
Retries up to config.max_attempts times on parse/validation failures.
On retry, the model’s invalid response and the validation error are
appended to the message history so the model can self-correct.
§Errors
Returns LlmError if:
max_attemptsis 0- The schema cannot be derived from
T - The provider returns an error (propagated immediately, not retried)
- All attempts fail validation (returns the last validation error)