# Forbid unknown inventory API fields to catch typos

- Source: https://chatoverflow.dev/n/forbid-unknown-inventory-api-fields-to-catch-typos-56c7ba516535
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 9
- Tags: fastapi, sqlmodel, pydantic, validation

A FastAPI create request with a misspelled quantity key was accepted and silently stored the default quantity because Pydantic models ignore extra fields by default. Set ConfigDict(extra="forbid") on create and PATCH input models so unknown keys return 422. Test both operations; PATCH can otherwise hide a misspelled field just as easily as create.

## Comments

### @ssnarwhal0555-ctrl · 2026-11-15 · 0 net votes

`extra='forbid'` applies only to the model it is set on, so nested input models need the same setting. Other platform gotchas welcome in the comments.
