

# Fail workflow state
<a name="state-fail"></a>

**Managing state and transforming data**  
Learn about [Passing data between states with variables](workflow-variables.md) and [Transforming data with JSONata](transforming-data.md).

A `Fail` state (`"Type": "Fail"`) stops the execution of the state machine and marks it as a failure, unless it is caught by a `Catch` block.

The `Fail` state only allows the use of `Type` and `Comment` fields from the set of [common state fields](statemachine-structure.md#amazon-states-language-common-fields). In addition, the `Fail` state allows the following fields.

** `Cause` (Optional)**  
A custom string that describes the cause of the error. You can specify this field for operational or diagnostic purposes.  
In JSONata states, you can also specify a JSONata expression.

** `CausePath` (Optional, JSONPath only) **  
If you want to provide a detailed description about the cause of the error dynamically from the state input using a [reference path](amazon-states-language-paths.md#amazon-states-language-reference-paths), use `CausePath`. When resolved, the reference path must select a field that contains a string value.  
You can also specify `CausePath` using an [intrinsic function](intrinsic-functions.md) that returns a string. These intrinsics are: [States.Format](intrinsic-functions.md#asl-intrsc-func-generic), [States.JsonToString](intrinsic-functions.md#jsontostring), [States.ArrayGetItem](intrinsic-functions.md#arraygetitem), [States.Base64Encode](intrinsic-functions.md#base64encode), [States.Base64Decode](intrinsic-functions.md#base64decode), [States.Hash](intrinsic-functions.md#asl-intrsc-func-uuid-generate), and [States.UUID](intrinsic-functions.md#statesuuid).  
+ You can specify either `Cause` or `CausePath`, but not both in your Fail state definition.
+ As an information security best practice, we recommend that you remove any sensitive information or internal system details from the cause description.

** `Error` (Optional)**  
An error name that you can provide to perform error handling using [Retry](concepts-error-handling.md#error-handling-retrying-after-an-error) or [Catch](concepts-error-handling.md#error-handling-fallback-states) fields. You can also provide an error name for operational or diagnostic purposes.  
In JSONata states, you can also specify a JSONata expression.

** `ErrorPath` (Optional, JSONPath only) **  
If you want to provide a name for the error dynamically from the state input using a [reference path](amazon-states-language-paths.md#amazon-states-language-reference-paths), use `ErrorPath`. When resolved, the reference path must select a field that contains a string value.  
You can also specify `ErrorPath` using an [intrinsic function](intrinsic-functions.md) that returns a string. These intrinsics are: [States.Format](intrinsic-functions.md#asl-intrsc-func-generic), [States.JsonToString](intrinsic-functions.md#jsontostring), [States.ArrayGetItem](intrinsic-functions.md#arraygetitem), [States.Base64Encode](intrinsic-functions.md#base64encode), [States.Base64Decode](intrinsic-functions.md#base64decode), [States.Hash](intrinsic-functions.md#asl-intrsc-func-uuid-generate), and [States.UUID](intrinsic-functions.md#statesuuid).  
+ You can specify either `Error` or `ErrorPath`, but not both in your Fail state definition.
+ As an information security best practice, we recommend that you remove any sensitive information or internal system details from the error name.

Because `Fail` states always exit the state machine, they have no `Next` field and don't require an `End` field.

## Fail state definition examples
<a name="fail-state-examples"></a>

The following Fail state definition example specifies static `Error` and `Cause` field values.

```
"FailState": {
  "Type": "Fail",
  "Cause": "Invalid response.",
  "Error": "ErrorA"
}
```

The following Fail state definition example uses reference paths dynamically to resolve the `Error` and `Cause` field values.

```
"FailState": {
  "Type": "Fail",
  "CausePath": "$.Cause",
  "ErrorPath": "$.Error"
}
```

The following Fail state definition example uses the [States.Format](intrinsic-functions.md#asl-intrsc-func-generic) intrinsic function to specify the `Error` and `Cause` field values dynamically.

```
"FailState": {
  "Type": "Fail",
  "CausePath": "States.Format('This is a custom error message for {}, caused by {}.', $.Error, $.Cause)",
  "ErrorPath": "States.Format('{}', $.Error)"
}
```