Skip to main content
Assertions are validation checks that verify the AI Agent’s responses and different aspects of the Flow for each Step during a Playbook run.

How to Use Assertions

Assertions include an input field where you can provide the text or data you want to validate during the Playbook run. Assertions are case-sensitive. The text, Intent names, Slot names, and data fields that you enter in the input field must match exactly what you want to validate. Specific assertion types include an option to validate only a portion of the provided text or data:
  • Use fuzzy search — for text assertions.
  • Use partial comparison — for data and context assertions.
The fuzzy search functionality handles case-insensitive matches, differences in spaces, tab stops, and newlines, and escaped characters.
PatternFeatureMatches
My orderCase Insensitivitymy order, MY ORDER
Differences in spaces
My   order
Newlines
My

order
Escaped CharactersMy\norder, My\torder
You can also invert the assertion check with the Invert assertion option. This option switches the assertion check to validate the absence of the defined value. Inverted assertions must also match the exact text or data provided in the assertion. You can activate both Invert assertion and Use fuzzy search to validate the absence of a portion of the provided text or data, for example, only the "status": "active" JSON property or the word "error" in the AI Agent’s response.

Assertion Types

Text Assertion

Validates text in the AI Agent’s response against the expected text or pattern provided in the input field.
ParameterTypeDescription
Invert assertionOptionSets the assertion to validate the absence of the text or pattern provided in the input field.
Use fuzzy searchOptionAllows partial matches in the AI Agent’s response.
TextInput fieldSets the exact text or pattern to validate.

Examples

In this example, configure the assertion as follows:
ParameterValue
Invert assertionDeactivated
Use fuzzy searchDeactivated
TextYour order has been confirmed
Validates that Your order has been confirmed is present in the AI Agent’s response. Fails if We have received your order is in the AI Agent’s response.
In this example, configure the assertion as follows:
ParameterValue
Invert assertionActivated
Use fuzzy searchActivated
Text"error"
Validates that the AI Agent’s response doesn’t include error, for example, Your order will be shipped shortly. Fails if the AI Agent’s response includes error, for example, We found an error while processing your order.

Data Assertion

Validates the AI Agent message’s data fields and JSON structures against the data provided in the input field. If the AI Agent’s response doesn’t include any data fields, the Assertion checks data fields in the user input.
ParameterTypeDescription
Invert assertionOptionSets the assertion to validate the absence of the JSON structure provided in the input field or the user input.
Use partial comparisonOptionAllows matches of a subset of the data structure to validate.
DataInput fieldSets the data structure to validate in JSON format.

Examples

In this example, configure the assertion as follows:
ParameterValue
Invert assertionDeactivated
Use partial comparisonDeactivated
Data
{
"userId": "12345",
"status": "active",
"timestamp": "2024-01-01T10:00:00Z"
}
Validates only the exact JSON object provided in the input field.
In this example, configure the assertion as follows:
ParameterValue
Invert assertionDeactivated
Use partial comparisonActivated
Data
{
"userId": "12345",
"status": "active"
}
Validates any JSON structure that contains the JSON object provided in the input field, for example:
{
"userId": "12345", // part of the provided JSON object
"status": "active", // part of the provided JSON object
"timestamp": "2024-01-01T10:00:00Z" // not part of the provided JSON object
}
Fails if the JSON structure doesn’t contain the JSON object provided in the input field, for example:
{
"userId": "12345", // subset of the provided JSON object
"status": "failed", // not part of the provided JSON object
"timestamp": "2024-01-01T10:00:00Z" // not part of the provided JSON object
}
In this example, configure the assertion as follows:
ParameterValue
Invert assertionActivated
Use partial comparisonActivated
Data
{
"status": "failed"
}
Validates any JSON structure that doesn’t contain the JSON object provided in the input field, for example:
{
"userId": "12345",
"status": "active", // validates if status isn't failed
"timestamp": "2024-01-01T10:00:00Z"
}

Intent Assertion

Validates that the Intent provided in the input field has been recognized in the user input.
ParameterTypeDescription
Invert assertionOptionSets the assertion to validate the absence of the Intent provided in the input field.
IntentInput fieldSets the Intent name to validate.

Examples

In this example, configure the assertion as follows:
ParameterValue
Invert assertionDeactivated
Intent"greet.hello"
Validates only that the "greet.hello" Intent has been recognized.
In this example, configure the assertion as follows:
ParameterValue
Invert assertionActivated
Intent"cancel.order"
Validates that the "cancel.order" Intent hasn’t been recognized.

Slot Assertion

Validates that the Slot provided in the input field has been recognized in the user input.
ParameterTypeDescription
Invert assertionOptionSets the assertion to validate the absence of the Slot provided in the input field.
SlotInput fieldSets the Slot name to validate.

Examples

In this example, configure the assertion as follows:
ParameterValue
Invert assertionDeactivated
Slotusername
Validates only that the username Slot has been recognized.
In this example, configure the assertion as follows:
ParameterValue
Invert assertionActivated
Slotpassword
Validates that the password Slot hasn’t been recognized.

Context Assertion

Validates the data in the Context object against the data provided in the input field.
ParameterTypeDescription
Invert assertionOptionSets the assertion to validate the absence of the context data provided in the input field
Use partial comparisonOptionAllows matches of a subset of the context data to validate.
Context dataInput fieldSets the context data to validate in JSON format.

Examples

In this example, configure the assertion as follows:
ParameterValue
Invert assertionDeactivated
Use partial comparisonDeactivated
Context data
{
"authenticated": true,
"userRole": "premium",
"sessionId": "abc123"
}
Validates only the exact JSON object provided in the input field.
In this example, configure the assertion as follows:
ParameterValue
Invert assertionDeactivated
Use partial comparisonActivated
Context data
{
"hasCreditCard": true,
"activeCreditCard": true
}
Validates any context data that contains the JSON object provided in the input field, for example:
{
"hasCreditCard": true, // part of the provided JSON object
"activeCreditCard": true, // part of the provided JSON object
"sessionId": "abc123" // not part of the provided JSON object
}
Fails if the JSON structure doesn’t contain the JSON object provided in the input field, for example:
{
"hasCreditCard": true, // subset of the provided JSON object
"activeCreditCard": false, // not part of the provided JSON object
"sessionId": "abc123" // not part of the provided JSON object
}
In this example, configure the assertion as follows:
ParameterValue
Invert assertionActivated
Use partial comparisonActivated
Context data
{
"activeCreditCard": false
}
Validates any JSON structure that doesn’t contain the JSON object provided in the input field, for example:
{
"hasCreditCard": true,
"activeCreditCard": true, // validates if activeCreditCard isn't false
"creditCardNumber": "1234567890"
}

State Assertion

Validates the conversation state.
ParameterTypeDescription
Invert assertionOptionSets the assertion to validate the absence of the State provided in the input field.
StateInput fieldSets the State name to validate.

Examples

In this example, configure the assertion as follows:
ParameterValue
Invert assertionDeactivated
Statewaiting_for_input
Validates only that the waiting_for_input State is active.
In this example, configure the assertion as follows:
ParameterValue
Invert assertionActivated
Stateerror_state
Validates only that the error_state State isn’t active.

Best Practices

For testing best practices, see Best Practices: Testing your Virtual Agents with Playbooks.

More Information

I