---
title: "Query string validation in Fastify"
description: "How to validate query parameters using Fastify"
author: "Bartosz Mikulski"
author_bio: "Principal AI Engineer & MLOps Architect. I bridge the gap between \"it works in a notebook\" and \"it works for 200 million users.\""
author_url: https://mikulskibartosz.name
author_linkedin: https://www.linkedin.com/in/mikulskibartosz/
author_github: https://github.com/mikulskibartosz
canonical_url: https://mikulskibartosz.name/query-string-validation-in-fastify
---

What does the example of query string validation look in the Fastify documentation? Like this:

```
const schema = {
  querystring: {
    name: { type: 'string' },
    excitement: { type: 'integer' }
  }
}
```

What is the problem? It is a lie!

The correct way of defining the schema of query parameters in this case (two values: “name” and “excitement”). Looks like this:

```
const querySchema = {
    schema: {
       querystring: {
         type: 'object',
           properties: {
             name: {
               type: 'string'
             },
             excitement: {
               type: 'integer'
             },
         }
     }
  }
}
```

Additionally, if we want to make the name parameter mandatory, we add it to the array of required parameters:

```
const querySchema = {
    schema: {
       querystring: {
         type: 'object',
           properties: {
             name: {
               type: 'string'
             },
             excitement: {
               type: 'integer'
             },
         }
         required: ['name']
     }
  }
}
```