#553·clack

Custom validation messages for select-like prompts

Author: aqeelatCreated Jun 3, 2026Updated Jun 3, 2026

Context

This came up while evaluating @clack/prompts as a potential replacement for enquirer.js, comparing it with enquirer.js and @inquirer/prompts.

Split out from: #550

Problem

multiselect has a required option with a built-in validation message:

txt
Please select at least one option

That message is not customizable, and there is no general validation hook for select-like prompts.

In enquirer.js, this kind of validation can be customized:

typescript
validate(value) {
  if (value.length === 0) return 'You must choose at least one package.'
  return true
}

Proposal

Add a validate option to select-like prompts, initially multiselect and groupMultiselect:

typescript
const selected = await multiselect({
  message: 'Choose packages',
  options: [...],
  validate: (values) => {
    if (values.length === 0) return 'Select at least one package.'
    return true
  },
})

The validation function could return true or a string error message.

Notes

This could either replace or complement the current required option.