Assertions - Cognigy Documentation
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.
Fuzzy Search Examples
| Pattern | Feature | Matches |
|---|---|---|
My order |
Case Insensitivity | my order, MY ORDER |
| Differences in spaces | <br>My order<br> |
|
| Newlines | <br>My<br>order<br> |
|
| Escaped Characters | My\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.
| Parameter | Type | Description |
|---|---|---|
| Invert assertion | Option | Sets the assertion to validate the absence of the text or pattern provided in the input field. |
| Use fuzzy search | Option | Allows partial matches in the AI Agent’s response. |
| Text | Input field | Sets the exact text or pattern to validate. |
Examples
Exact Match
In this example, configure the assertion as follows:
| Parameter | Value |
|---|---|
| Invert assertion | Deactivated |
| Use fuzzy search | Deactivated |
| Text | Your 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.
Fuzzy Search
In this example, configure the assertion as follows:
| Parameter | Value |
|---|---|
| Invert assertion | Deactivated |
| Use fuzzy search | Activated |
| Text | "order" |
Validates that Your order has been confirmed and We have received your order are in the AI Agent’s response. Fails if We are preparing your purchase is in the AI Agent’s response.
Inverted Assertion
In this example, configure the assertion as follows:
| Parameter | Value |
|---|---|
| Invert assertion | Activated |
| Use fuzzy search | Activated |
| 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.
| Parameter | Type | Description |
|---|---|---|
| Invert assertion | Option | Sets the assertion to validate the absence of the JSON structure provided in the input field or the user input. |
| Use partial comparison | Option | Allows matches of a subset of the data structure to validate. |
| Data | Input field | Sets the data structure to validate in JSON format. |
Examples
Exact Match
In this example, configure the assertion as follows:
| Parameter | Value |
|---|---|
| Invert assertion | Deactivated |
| Use partial comparison | Deactivated |
| Data | <br>{<br>"userId": "12345",<br>"status": "active",<br>"timestamp": "2024-01-01T10:00:00Z"<br>}<br> |
Validates only the exact JSON object provided in the input field.
Partial Comparison
In this example, configure the assertion as follows:
| Parameter | Value |
|---|---|
| Invert assertion | Deactivated |
| Use partial comparison | Activated |
| Data | <br>{<br>"userId": "12345",<br>"status": "active"<br>}<br> |
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
}
Inverted Assertion
In this example, configure the assertion as follows:
| Parameter | Value |
|---|---|
| Invert assertion | Activated |
| Use partial comparison | Activated |
| Data | <br>{<br>"status": "failed"<br>}<br> |
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.
| Parameter | Type | Description |
|---|---|---|
| Invert assertion | Option | Sets the assertion to validate the absence of the Intent provided in the input field. |
| Intent | Input field | Sets the Intent name to validate. |
Examples
Exact Match
In this example, configure the assertion as follows:
| Parameter | Value |
|---|---|
| Invert assertion | Deactivated |
| Intent | "greet.hello" |
Validates only that the "greet.hello" Intent has been recognized.
Inverted Match
In this example, configure the assertion as follows:
| Parameter | Value |
|---|---|
| Invert assertion | Activated |
| 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.
| Parameter | Type | Description |
|---|---|---|
| Invert assertion | Option | Sets the assertion to validate the absence of the Slot provided in the input field. |
| Slot | Input field | Sets the Slot name to validate. |
Examples
Exact Match
In this example, configure the assertion as follows:
| Parameter | Value |
|---|---|
| Invert assertion | Deactivated |
| Slot | username |
Validates only that the username Slot has been recognized.
Inverted Assertion
In this example, configure the assertion as follows:
| Parameter | Value |
|---|---|
| Invert assertion | Activated |
| Slot | password |
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.
| Parameter | Type | Description |
|---|---|---|
| Invert assertion | Option | Sets the assertion to validate the absence of the context data provided in the input field |
| Use partial comparison | Option | Allows matches of a subset of the context data to validate. |
| Context data | Input field | Sets the context data to validate in JSON format. |
Examples
Exact Match
In this example, configure the assertion as follows:
| Parameter | Value |
|---|---|
| Invert assertion | Deactivated |
| Use partial comparison | Deactivated |
| Context data | <br>{<br>"authenticated": true,<br>"userRole": "premium",<br>"sessionId": "abc123"<br>}<br> |
Validates only the exact JSON object provided in the input field.
Partial Match
In this example, configure the assertion as follows:
| Parameter | Value |
|---|---|
| Invert assertion | Deactivated |
| Use partial comparison | Activated |
| Context data | <br>{<br>"hasCreditCard": true,<br>"activeCreditCard": true<br>}<br> |
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
}
Inverted Assertion
In this example, configure the assertion as follows:
| Parameter | Value |
|---|---|
| Invert assertion | Activated |
| Use partial comparison | Activated |
| Context data | <br>{<br>"activeCreditCard": false<br>}<br> |
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.
| Parameter | Type | Description |
|---|---|---|
| Invert assertion | Option | Sets the assertion to validate the absence of the State provided in the input field. |
| State | Input field | Sets the State name to validate. |
Examples
Exact Match
In this example, configure the assertion as follows:
| Parameter | Value |
|---|---|
| Invert assertion | Deactivated |
| State | waiting_for_input |
Validates only that the waiting_for_input State is active.
Inverted Assertion
In this example, configure the assertion as follows:
| Parameter | Value |
|---|---|
| Invert assertion | Activated |
| State | error_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
Last modified on April 21, 2026.