extract<T> method
Future<T>
extract<T>({
- required List<
Message> messages, - required ObjectSchema schema,
- required T fromJson(),
- String toolName = 'extract',
- String? toolDescription,
- int maxRetries = 2,
- void onRetry(
- ExtractionAttempt attempt
Extracts a T from the model.
fromJson runs only after the response has passed schema validation,
so it can assume every required field is present and correctly typed.
Implementation
Future<T> extract<T>({
required List<Message> messages,
required ObjectSchema schema,
required T Function(Map<String, Object?> json) fromJson,
String toolName = 'extract',
String? toolDescription,
int maxRetries = 2,
void Function(ExtractionAttempt attempt)? onRetry,
}) async {
final raw = await extractRaw(
messages: messages,
schema: schema,
toolName: toolName,
toolDescription: toolDescription,
maxRetries: maxRetries,
onRetry: onRetry,
);
return fromJson(raw);
}