Skip to content

Commit

Permalink
Update docs with slot predicate validation (#12842)
Browse files Browse the repository at this point in the history
* update docs with slot validation

* address review comments

* rephrase customization of utter_internal_error_rasa
  • Loading branch information
ancalita authored Sep 22, 2023
1 parent 82aac8a commit 145ce06
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion docs/docs/concepts/flows.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ response will be used to fill the "account_type" slot.
:::note

The slot needs to be defined in the domain file. See the
[domain documentation](./domain.mdx) for more information. Additionaly, the slot
[domain documentation](./domain.mdx) for more information. Additionally, the slot
should have fitting slot mappings.

:::
Expand Down Expand Up @@ -483,6 +483,45 @@ flow is completed.
scope: "flow"
```

#### Slot validation

You can define slot validation rules directly in your flow yaml file by adding a `rejections` property to any
`collect_information` step. The `rejections` section is a list of mappings, where each mapping must have an
`if` and an `utter` mandatory properties:
- the `if` property is a condition written in natural language that is evaluated using the
[pypred](https://github.com/armon/pypred) library.
- the `utter` property is the name of the [response](./responses.mdx) the assistant will send if the condition evaluates
to `True`.

Here is an example:

```rasa-yaml title="flows.yml"
flows:
verify_eligibility:
description: This flow verifies if the user is eligible for creating an account.
name: verify eligibility
steps:
- id: "ask_age"
collect: "age"
rejections:
- if: age < 1
utter: utter_invalid_age
- if: age < 18
utter: utter_age_at_least_18
next: "ask_email"
```

Upon every validation failure, the assistant will automatically make another attempt to collect the information.
The assistant will repeatedly ask for the slot until none of the rejection conditions pass. Once all rejections have
evaluated to `False`, the assistant moves on to the `next` step with the collected value.

If the predicate defined in the `if` property is invalid, the assistant will log an error and respond with the
`utter_internal_error_rasa` response which by default is `Sorry, I'm having trouble understanding you right now.
Please try again later.`. You can override the text message for `utter_internal_error_rasa` by adding this response with
the custom text in your domain file. We recommend using end-to-end testing to ensure that your flows work as expected.

If no rejections are defined, the assistant will fill the slot with the collected value and proceed to the next step.

### Link

A `link` step is used to link to another flow. Here is an example:
Expand Down

0 comments on commit 145ce06

Please sign in to comment.