Using custom slot mappings with forms


The paragraph below is taken from the Forms docs. I didn’t quite get the sentence, "slots will be only filled by entities with the same name as the slot that are picked up from the user input."

Could I get some clarification and maybe an example on how slots will be only filled by entitites with the same name…


Custom slot mappings

If you do not define slot mappings, slots will be only filled by entities with the same name as the slot that are picked up from the user input. Some slots, like cuisine , can be picked up using a single entity, but a FormAction can also support yes/no questions and free-text input. The slot_mappings method defines how to extract slot values from user responses.

Hi @Jmg007,

regarding your other post I assume you already have seen the slot_mappings methods of your Imagine the following mapping:

"new_agreement": [
                self.from_intent(intent="confirm", value="yes"),
                self.from_intent(intent="deny", value="no"),

Here we have two ways of filling the slot new_agreement: by intent (confirm/deny) or by entity (slot_shift).

In order to let Rasa fill this slot with the entitiy slot_shift, there have to be an entity called slot_shift in your domain.yml and an Extractor for this entitiy - in this case you want to use the CRFEntityExtractor.

That means: If your domain.yml defines an entity which actually can be extracted, then you can fill a slot with it, as long as the likewise slot_mapping exists, demonstrated in my sample.

Kind regards

Thanks Julian. Got it all working now. The only thing I still don’t quite get is the difference between entities and slots. In the end aren’t they both performing the same task - essentially a placeholder for user information that can be extracted?

Thanks again.

Hi @Jmg007,

The only thing I still don’t quite get is the difference between entities and slots.

You have to imagine those two terms separated from each other. An entity can be seen as an object with semantic relevance, e.g. for the task Named Entity Recognition. Popular entities are e.g. PERSON, LOCATION, NUMBER - objects that we often want to extract out of text.

A slot is something our bot should fill - primarily it doesn’t matter with which kind of information. Let’s say you are for the first time at a local dentist - usually you have to fill out a form with personal information about yourself. Consider everything to fill out as a slot similar to the one we are talking about - with the difference that our slot should be filled automatically.

Now Rasa simply offers the possibility to fill a slot with the value of any recognized entity. Imagine this example:

Our bot has only one single task: He should fill a slot called fullname.

Now the setup is simple: We create a Form, define one slot and the following mapping:

"fullname": self.from_text()

If the bot asks “Please give me your fullname” you have many possibilities to respond. A few samples:

  • Peter Parker
  • Gandalf the Grey
  • Julian
  • Shitstorm
  • Blink182

Out of this perspective, the slot would even be filled with the value “Shitstorm” because noone determines how to properly validate the value, e.g. to not being a proper name. Thank god, Rasa provided some additional methods for this one: Why don’t we use a mechanism that already exists for this task? leading to:

"fullname": self.from_entity(entity="PERSON")

This would tell the Bot to fill the slot exclusively with a value that corresponds to the entity PERSON, e.g. “Peter Parker” - assumed that our NLU-Core extracted the entity PERSON properly.

Of course this mechanisms are error-prone such that it is always a good idea to use the validator-methods to inject some additional validation but I think you got it now.

Did this help?


1 Like

Thanks Julian!