onValidate property
Optional async callback for custom validation after the AI accepts the answer.
The LLM still validates format and rules first (validationMessage, type, etc.). This runs only when that passes. Use it for anything the model cannot do reliably: calling your API to see if a nickname is taken, uniqueness in your database, or other business rules.
Return null to accept the answer, or a non-empty String to reject it.
The returned string is shown to the user as the rejection reason.
onValidate: (answer) async {
final taken = await Api.isNicknameTaken(answer);
return taken ? 'That nickname is already taken, please choose another.' : null;
}
Implementation
final Future<String?> Function(String answer)? onValidate;