The slot type "any" does not seem to work correctly

Context: I’m looking to migrate my bot from the .md training examples (1.x) to the .yml format (2.x) and I’m getting some trouble with Rasa.

I’m currently using slot type “any” (reference here: Domain) for certain objects that are gathered during the conversation. However, these objects that I use during the conversation, are either a list or a JSON/dictionary type. After I used the automated migration script for my stories, running the rasa train command gave me multiple errors that these slots when set are not of the type str, bool, list, text.

So I removed all of the “problematic stories” with these slots and tried to create stories afresh using rasa interactive hoping that it’ll give me the right format. However, once I exported the stories and re-ran the training, I got the same error even for the format that rasa interactive exported. The JSON seems to be represented as a multi-level bulleted list inside the slot_was_set node of the story.

I also tried actually putting in the JSON in place of the tree and got the same result.

How should I format a slot of type “any”, especially if it could be a JSON?

Hi @ganeshv, I got this working by enclosing a dict in quotes in my stories/rules, like this:

  steps:
    - intent: i1
    - action: action_1
    - slot_was_set:
      - misc: '{"day": "Monday", "colour": "blue"}'
    - action: action_2

It trains alright and when I set this kind of slot value from within a custom action, it behaves like it should (like a dictionary) when I access it later.

Regarding the migration script and interactive learning: What’s the format you get from those? Is it the same, just not quoted? If yes, then I guess we need to fix it (it’d be awesome if you could report the bug on GitHub by creating an issue).

I also reckon that there should be an example in the docs of how a dict/list slot value should be written in data. If you want, you can add this to the docs yourself and create a pull request :slight_smile:

Hello @SamS ,

Thank you for responding :slight_smile: .

  1. It trains alright

Okay I’ll try training with the single quotes surrounding the JSON.

  1. when I set this kind of slot value from within a custom action, it behaves like it should (like a dictionary) when I access it later.

I can confirm that this works correctly as well during the conversation. This was when I was using rasa interactive to understand how the format is exported.

  1. Regarding the migration script and interactive learning: What’s the format you get from those? Is it the same, just not quoted?

Yes; both the migration and the interactive learning give the same format. It converts lists and JSON objects into a tree structure within YAML, which then blocks the training.

The format looks something like this -

- action: previous_action
- slot_was_set:
    - SLOT_NAME:
        SLOT_KEY_1:
          slot_property_1: <value>
          slot_property_2: <value>
          slot_property_list_3:
          - slot_property_3_1: <value>
            slot_property_3_2: <value>
          - slot_property_3_1: <value>
            slot_property_3_2: <value>
          - slot_property_3_1: <value>
            slot_property_3_2: <value>
          - slot_property_3_1: <value>
            slot_property_3_2: <value>
        SLOT_KEY_2
...
  1. If yes, then I guess we need to fix it (it’d be awesome if you could report the bug on GitHub by creating an issue).

I’ve created the bug on github here - The format for exporting "any" type slots (in JSON or list) through migration or interactive learning blocks any subsequent training · Issue #7683 · RasaHQ/rasa · GitHub

  1. I also reckon that there should be an example in the docs of how a dict/list slot value should be written in data.

I’ll work on this later today and create a PR.

Thanks!

Awesome, thanks a lot for your help towards fixing this!

My apologies @SamS; I got sidetracked in the last two weeks with some critical issues. Here’s the PR for the doc update. I modified two docs - Updated docs for slot type any by ganeshviyer · Pull Request #7748 · RasaHQ/rasa · GitHub.

1 Like

Hey @ganeshv, you may’ve noticed some disagreement around this. I have to admit that while answering your questions I never thought about Melinda’s point – that actually slots of type any are useless in stories as they never influence the conversation. Now, strictly speaking, these slots can be included in your training stories. And maybe you want to have them there for clarity (I sometimes do this too). But they will never influence your models trained on those stories.

So, given the context: My answers above mostly hold, but we agreed to not change the docs because we don’t want to encourage anyone to include slots of type any in stories. Interactive Learning will change as soon as possible so that it doesn’t include those slots in exported stories. And as for the migration scripts, those need to change too so as not to break training (thanks for creating the issue for this!).

Again, sorry for the confusion!

No worries @SamS. Sorry, was away for a while and just getting to the forum messages. And yes, your approach works great!

1 Like