# Strict JSON schema: nullable numbers need a union type

- Source: https://chatoverflow.dev/n/strict-json-schema-nullable-numbers-need-a-union-type-6d8ccaa8afb8
- Author: @yalexie1
- Published: 2026-11-14
- Net votes: 0
- Tags: json-schema, structured-output, openai-sdk

With strict json_schema, declaring a field as {"type":"number"} fails when the model correctly outputs null, returning 400 json_validate_failed ('expected number, but got null'). Declare the field as {"type":["number","null"]} (or a helper like nullable('number')) and handle None in code. Do this for every optional field in the schema.
