# \[Solved\] Problem in custom slot \[ValueError: Failed to find slot type\]

**URL:** <https://forum.rasa.com/t/solved-problem-in-custom-slot-valueerror-failed-to-find-slot-type/13407>\
**Category:** Rasa Open Source\
**Created:** [July 23, 2019, 11:30am UTC](https://forum.rasa.com/t/solved-problem-in-custom-slot-valueerror-failed-to-find-slot-type/13407 "2019-07-23T11:30:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![saurabh-m523](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/saurabh-m523/32/7887_2.png) [@saurabh-m523](https://forum.rasa.com/u/saurabh-m523)\
**Post date:** [July 23, 2019, 11:30am UTC](https://forum.rasa.com/t/solved-problem-in-custom-slot-valueerror-failed-to-find-slot-type/13407/1 "2019-07-23T11:30:14Z")

</div>

I created my own custom slot module [slots.py](https://forum.rasa.com/uploads/short-url/36NYFexVV103wEWcmFxesrmf6Vs.py) (362 Bytes) with class `ViewSlot`. It is in the same folder as the [domain.yml](https://forum.rasa.com/uploads/short-url/gPpZGgA0CENhPOaLloioEG6i9Cb.yml) (3.6 KB). Inside domain.yml, I have a slot `view_slot` of type `slots.ViewSlot`, but still I’m getting the following error while training:

```
Traceback (most recent call last):
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\site-packages\rasa\core\slots.py", line 68, in resolve_by_type
    return class_from_module_path(type_name)
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\site-packages\rasa\utils\common.py", line 188, in class_from_module_path
    m = importlib.import_module(module_name)
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\importlib\ __init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'slots'

    During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\runpy.py", line 193, in _run_module_as_main
    " __main__", mod_spec)
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\geuser\AppData\Local\Programs\Python\Python36\Scripts\rasa.exe\ __main__.py", line 9, in <module>
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\site-packages\rasa\ __main__.py", line 70, in main
    cmdline_arguments.func(cmdline_arguments)
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\site-packages\rasa\cli\train.py", line 84, in train
    kwargs=extract_additional_arguments(args),
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\site-packages\rasa\train.py", line 40, in train
    kwargs=kwargs,
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\asyncio\base_events.py", line 484, in run_until_complete
    return future.result()
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\site-packages\rasa\train.py", line 72, in train_async
    domain = Domain.load(domain, skill_imports)
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\site-packages\rasa\core\domain.py", line 73, in load
    other = cls.from_path(path, skill_imports)
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\site-packages\rasa\core\domain.py", line 87, in from_path
    domain = cls.from_file(path)
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\site-packages\rasa\core\domain.py", line 100, in from_file
    return cls.from_yaml(rasa.utils.io.read_file(path))
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\site-packages\rasa\core\domain.py", line 110, in from_yaml
    return cls.from_dict(data)
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\site-packages\rasa\core\domain.py", line 115, in from_dict
    slots = cls.collect_slots(data.get("slots", {}))
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\site-packages\rasa\core\domain.py", line 205, in collect_slots
    slot_class = Slot.resolve_by_type(slot_dict[slot_name].get("type"))
  File "c:\users\geuser\appdata\local\programs\python\python36\lib\site-packages\rasa\core\slots.py", line 73, in resolve_by_type
    "sure its module path is correct.".format(type_name)
ValueError: Failed to find slot type, 'slots.ViewSlot' is neither a known type nor user-defined. If you are creating your own slot type, make sure its module path is correct.

```

I couldn’t figure out how to work with custom slot? The doc does not explain this very well. A detailed example will be much appreciated. Thanks!

P.S.: I used the command `rasa train` for training, do I need to specify anything else in this command?

---

<div class="post-metadata">

**Author:** ![Ghostvv](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/ghostvv/32/211_2.png) [@Ghostvv](https://forum.rasa.com/u/Ghostvv)\
**Post date:** [July 24, 2019, 8:42am UTC](https://forum.rasa.com/t/solved-problem-in-custom-slot-valueerror-failed-to-find-slot-type/13407/2 "2019-07-24T08:42:44Z")

</div>

python cannot import your custom class, you need to put the path to the class in your domain file

---

<div class="post-metadata">

**Author:** ![saurabh-m523](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/saurabh-m523/32/7887_2.png) [@saurabh-m523](https://forum.rasa.com/u/saurabh-m523)\
**Post date:** [July 24, 2019, 9:01am UTC](https://forum.rasa.com/t/solved-problem-in-custom-slot-valueerror-failed-to-find-slot-type/13407/4 "2019-07-24T09:01:22Z")

</div>

Ya so as per this [thread](https://github.com/RasaHQ/rasa/issues/2013#issuecomment-377786524), I defined my slot’s type as `slots.ViewSlot` in the domain file. Is there some other way of putting the path to the class in `domain.yml`? (my domain file and custom class file are in the same folder.)

---

<div class="post-metadata">

**Author:** ![Ghostvv](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/ghostvv/32/211_2.png) [@Ghostvv](https://forum.rasa.com/u/Ghostvv)\
**Post date:** [July 24, 2019, 9:35am UTC](https://forum.rasa.com/t/solved-problem-in-custom-slot-valueerror-failed-to-find-slot-type/13407/5 "2019-07-24T09:35:55Z")

</div>

hm, can you import the class from python shell?

---

<div class="post-metadata">

**Author:** ![saurabh-m523](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/saurabh-m523/32/7887_2.png) [@saurabh-m523](https://forum.rasa.com/u/saurabh-m523)\
**Post date:** [July 24, 2019, 11:03am UTC](https://forum.rasa.com/t/solved-problem-in-custom-slot-valueerror-failed-to-find-slot-type/13407/6 "2019-07-24T11:03:23Z")

</div>

Yes. `from slots import ViewSlot` is not giving any errors.

---

<div class="post-metadata">

**Author:** ![saurabh-m523](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/saurabh-m523/32/7887_2.png) [@saurabh-m523](https://forum.rasa.com/u/saurabh-m523)\
**Post date:** [July 25, 2019, 4:09am UTC](https://forum.rasa.com/t/solved-problem-in-custom-slot-valueerror-failed-to-find-slot-type/13407/7 "2019-07-25T04:09:47Z")

</div>

Okay so, I don’t know why, but setting the `PYTHONPATH` environment variable to my directory’s path worked. [This](https://docs.python.org/3.6/using/windows.html#excursus-setting-environment-variables) is how you set it in windows. [This](https://github.com/RasaHQ/rasa/issues/2013#issuecomment-511371776) for linux.

---

<div class="post-metadata">

**Author:** ![RodrigoSdeCarvalho](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/rodrigosdecarvalho/32/23570_2.png) [@RodrigoSdeCarvalho](https://forum.rasa.com/u/RodrigoSdeCarvalho)\
**Post date:** [December 22, 2023, 2:17am UTC](https://forum.rasa.com/t/solved-problem-in-custom-slot-valueerror-failed-to-find-slot-type/13407/8 "2023-12-22T02:17:51Z")

</div>

For me its different, if i import something other than a file from rasa, its not found anymore. Does your file import some other python file of your project or external lib too?
