| **Mandatory run variables** | `messages`: A list of [`ChatMessage`](../../concepts/data-classes/chatmessage.mdx) instances to be validated– the last message in this list is the one that is validated |
| **Output variables** | `validated`: A list of messages if the last message is valid <br /> <br />`validation_error`: A list of messages if the last message is invalid |
`JsonSchemaValidator`checks the JSON content of a`ChatMessage`against a given[JSON Schema](https://json-schema.org/). If a message's JSON content follows the provided schema, it's moved to the`validated`output. If not, it's moved to the`validation_error`output. When there's an error, the component uses either the provided custom`error_template`or a default template to create the error message. These error`ChatMessages`can be used in Haystack recovery loops.
## Usage
### In a pipeline
In this simple pipeline, the `MessageProducer` sends a list of chat messages to a Generator through `BranchJoiner`. The resulting messages from the Generator are sent to `JsonSchemaValidator`, and the error `ChatMessages` are sent back to `BranchJoiner` for a recovery loop.
```python
from typing import List
from haystack import Pipeline
from haystack import component
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.components.joiners import BranchJoiner
from haystack.components.validators import JsonSchemaValidator