Regex SlotsΒΆ
Regex Slots are user-defined Slots, which apply regular expressions (regex) to match and extract specific patterns from user inputs.
Unlike Lexicon Slots, which rely on Keyphrases, Regex Slots are ideal for structured data that follows a predictable format, such as:
- Phone numbers (
(123) 456-7890
) - Email addresses (
user@example.com
) - Product codes (
ABC-123-XYZ
)
You can use this type of Regex Slots only as Slot Fillers.
RecommendationsΒΆ
- Regex Slots require careful crafting to avoid overly broad or restrictive patterns.
- Complex regular expressions can be error-prone; test them thoroughly to avoid missing matches or capturing incorrect data.
- Avoid conflicts with Lexicon Slots and System Slots by ensuring unique Slot names.
Working with Regex SlotsΒΆ
To start working with Regex Slots, you can use one of the following options:
To define a regex pattern that runs on all user inputs in the Flow, follow these steps:
- In the Flow editor, go to NLU > Slot Fillers.
- In the upper-left corner, click + New Slot Filler.
- In the New Slot Filler window, fill in the following fields:
- Name β enter a unique name for the Slot Filler. For example,
phone_number
. - Type β select Regular Expression.
- Regular Expression β enter a regex pattern. Regular expressions must start with
/
and end with/
, for example,/^\d{3}-\d{3}-\d{4}$/
. - Context Key β enter a Slot name to store the matched data in the Context object. For example,
phone_number
.
- Name β enter a unique name for the Slot Filler. For example,
To define a regex pattern that runs after a specific user input in the Flow, follow these steps:
- In the Flow editor, add a Regex Slot Filler Node where you want to process the input, for example, after a Question Node.
- In the Node editor, configure the following fields:
- Regular Expression - enter a regex pattern without leading and trailing slashes, for example,
^\d{3}-\d{3}-\d{4}$
. - Flags β enter flags you want to apply to the regular expression, for example,
i
for case-insensitive,m
for multiline. Note that theg
flag should be always specified. - Slot Name β enter the Slot name to store the matched data in the
slots.<slot-name>
Input object. For example,phone_number
.
- Regular Expression - enter a regex pattern without leading and trailing slashes, for example,
Once a Regex Slot is filled, the extracted data can be used in the conversation logic, for example, for the following purposes:
- Validating user input, for example, ensuring a valid email format.
- Triggering specific actions, for example, saving a phone number to the Contact Profile.
- Combining with Question Nodes to prompt users to re-enter missing or incorrectly formatted information.
ExampleΒΆ
User Input: My phone number is 555-123-4567
Regex Pattern: /^\d{3}-\d{3}-\d{4}$/g
Slot Name: phone_number
Result: The context.phone_number
Slot is populated with 555-123-4567
. The AI Agent responds Thanks for providing your phone number: {{context.slots.phone_number}}!
Use CasesΒΆ
- Extracting a booking code:
/^[A-Z]{3}-\d{4}$/g
to captureXYZ-1234
. - Capturing email addresses with the
@company
domain:/^[a-zA-Z0-9._%+-]+@company\.com$/g
. - Identifying dates in specific formats:
/^\d{2}\/\d{2}\/\d{4}$/g
for04/22/2025
.