How to set a form slot based on another slot's value?

I have built a form based bot which captures information for an online clothing business. Among other things it asks what product, fabric and colour the user is interested in. I also need to capture the gender as “a blue jacket” could be for a man or a woman. Of course I can add “gender” to my form’s required_slots. Now assume the user tells the bot she is looking for “a white dress”. It doesn’t really make sense to ask “is this for a man or a woman?”.

What I’m looking for is a way to set a form slot based on another slot. In this case when the user enters the product I would use rules or ML classification to set the gender slot as male, female or None. If None I would expect the bot to ask the user to clarify the gender.

I’m thinking one approach could be to use the validate_product method on the form to return not only the product text but also the gender. It seems like a bit of a hack.

Is there a better way to do this?

Many thanks

I believe you can extract any slot from the FormAction class using tracker.get_slot(), Did you try this?

yeah I have no problems getting the slots. The question is where and when to do this? I’m basically trying to infer one slot when another slot is filled. validate_x kind of works but feels hacky

Ah, it seems if it is a straightforward assignment, you could do it from slot_mappings. Or it seems, it is validate_

A different angle, maybe default it in the story? If its a white_dress (gender=female)? NOte: I’m new to RASA