You are viewing documentation for our open source project which is maintained by the community. If you want to get started building assistants with Rasa please check out our latest [documentation here](/content/docs/index.html).

You can do custom extraction and validation of slot values by writing custom actions in three different ways.

## `action_validate_slot_mappings`

You can use the `action_validate_slot_mappings` action to define custom extraction and / or validation of slots that can be set or updated outside of a form context.

This action is called automatically at the end of the default action [`action_extract_slots`](https://legacy-docs-oss.rasa.com/docs/rasa/default-actions#action_extract_slots), so the name must not be changed. If you are using Rasa SDK, you should extend the Rasa SDK [`ValidationAction` class](https://legacy-docs-oss.rasa.com/docs/rasa/action-server/validation-action#how-to-subclass-validationaction). If you are using a different action server, you will need to implement an action class with equivalent functionality to the Rasa SDK class. Please see [the action server docs](https://legacy-docs-oss.rasa.com/docs/rasa/action-server/validation-action#validationaction-class-implementation) for details.

With this option, you do not need to specify the `action` key in the [custom slot mapping](https://legacy-docs-oss.rasa.com/docs/rasa/domain#custom-slot-mappings), since the default action [`action_extract_slots`](https://legacy-docs-oss.rasa.com/docs/rasa/default-actions#action_extract_slots) runs `action_validate_slot_mappings` automatically if present in the `actions` section of the domain.

## `validate_<form name>`

Custom actions named `validate_<form name>` will run automatically if the form it specifies in its name is activated. If you are using Rasa SDK, the custom action should inherit from the Rasa SDK [`FormValidationAction` class](https://legacy-docs-oss.rasa.com/docs/rasa/action-server/validation-action#formvalidationaction-class). If you are not using Rasa SDK, you will need to implement an action or action class with equivalent functionality to the `FormValidationClass` in your custom action server. Please see [the action server docs](https://legacy-docs-oss.rasa.com/docs/rasa/action-server/validation-action#formvalidationaction-class-implementation) for details.

## Regular Custom Action

You can use a regular custom action [custom action](https://legacy-docs-oss.rasa.com/docs/rasa/custom-actions) that returns [`slot`](https://legacy-docs-oss.rasa.com/docs/rasa/action-server/events#slot) events for custom slot extraction. Use this option if neither [`action_validate_slot_mappings`](https://legacy-docs-oss.rasa.com/docs/rasa/slot-validation-actions/#action_validate_slot_mappings) or [`validate_<form name>`](https://legacy-docs-oss.rasa.com/docs/rasa/slot-validation-actions/#validate_form-name) meet your needs. For example, if you want to reuse the same custom action explicitly in a story or rule, you should use a regular custom action for custom slot extraction.
A slot validation action should only return `slot` and [`bot`](https://legacy-docs-oss.rasa.com/docs/rasa/action-server/events#bot) events. Any other event type will be filtered out by the default action [`action_extract_slots`](https://legacy-docs-oss.rasa.com/docs/rasa/default-actions#action_extract_slots). The name of the custom action must be specified in the `action` key of the relevant [custom slot mapping](https://legacy-docs-oss.rasa.com/docs/rasa/domain#custom-slot-mappings) in the domain. Note that the action name must be listed in the domain `actions` section too.

##### Using different actions for extraction and validation

You can use both a regular custom action and `action_validate_slot_mappings` together to extract and validate a slot. For example, you can specify a regular custom action as the `action` for a `custom` slot mapping, and also add validation logic for the same slot to `action_validate_slot_mappings`. The custom action specified in the custom slot mapping will be called first, and `action_validate_slot_mappings` will be called afterwards.
