Error handling and re-prompts

While talking with the AI assistant, the user may say something unexpected, and the AI assistant will be unable to proceed with the conversation. To handle error situations gracefully and get the user back on track, you can use the fallback() function.

Fallbacks can help you to:

Customizing default error messages

If the AI assistant fails to recognize the user’s input, Alan AI replies with one of the default error phrases. You can provide a set of custom phrases with which Alan AI must reply in no-match cases. To do this, add the fallback() function to the dialog script and specify one or more phrases in it.

For example:

Dialog script
fallback('Please say it again', 'Sorry, I did not get it this time', 'Could you please rephrase that?');

Now, if the user gives a command that is not available in the dialog script or cannot be recognized, this default fallback will be matched, and Alan AI will reply with one of the defined phrases picked at random.

You can add more complex logic to the fallback() function:

Dialog script
fallback(p => {'Sorry, I have no answer');
    console.log('An error in the dialog is encountered');

Prompting for the correct input

When placed in user-defined contexts, fallbacks provide a user-friendly way to ‘lock’ the user at a certain point in the dialog. They can be helpful if you expect a specific input from the user and cannot move forward in the dialog without it.

To handle an error, add the fallback() function to the context and specify one or more prompt phrases in it. If the user’s input cannot be matched to any command in the context, Alan AI will prompt the user for the correct input using one of the defined phrases and continue re-prompting until the required command is obtained.


Fallbacks in user-defined contexts are context-dependent — they are active only when contexts to which they are added are activated.

Check the chooseDish context in the example below:

Dialog script
intent('What do you have?', p => {'We have pizza and burgers');

let chooseDish = context(() => {
    intent('Get me a $(ITEM: pizza, burger...)', p => {`Adding ${p.ITEM.value} to your order...`);

    intent('Cancel (the order)-', p => {'Your order is cancelled');

    fallback('You need to order something. Say: get me a pizza or get me a burger. Or say cancel to cancel the order.');

Now, when users enter the chooseDish context by saying: What do you have?, they will need to finish this step either by ordering something or by cancelling the order. Until then, they will remain in the context, and Alan AI will keep on prompting for the correct command.