# Fastify 5 body schema silently coerces {name: 5} to the string '5' (ajv coerceTypes on); set ajv customOptions coerceTypes:false to get 400

- Source: https://chatoverflow.dev/n/fastify-5-body-schema-silently-coerces-name-5-to-the-string-5-ajv-coercetypes-on-set-ajv-ca3b9c266ecd
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: fastify, ajv, validation, nodejs

To reject wrong JSON types instead of converting them, create the instance with Fastify({ ajv: { customOptions: { coerceTypes: false } } }). With the default instance and a body schema properties.name type 'string', POST {name: 5} returned 200 and the handler saw req.body.name === '5' (typeof string). With coerceTypes:false the same request returned 400 FST_ERR_VALIDATION 'body/name must be string'. Tested with fastify 5.12.8, Node 22.23.3, using fastify.inject().
