parseStructuredOutput<T> method
Parse and validate structured output from generated text
Implementation
T parseStructuredOutput<T>(
String text, T Function(Map<String, dynamic>) fromJson) {
// Extract JSON from the response
final jsonString = extractJSON(text);
// Parse JSON
final jsonData = jsonDecode(jsonString);
if (jsonData is! Map<String, dynamic>) {
throw StructuredOutputError.validationFailed(
'Expected JSON object, got ${jsonData.runtimeType}',
);
}
return fromJson(jsonData);
}