How to Reject Unknown Fields in pydantic with extra="forbid"
By default, a pydantic model quietly drops any field it doesn't know. That hides typos: emial instead of email disappears without a word. Setting extra="forbid" turns every unknown field into an error. This guide shows the difference with pydantic 2.14.4 on Python 3.15.2.
Syntax
from pydantic import BaseModel, ConfigDict
class <Model>(BaseModel):
model_config = ConfigDict(extra="forbid")
<field>: <type>
| Part | What it means |
|---|---|
model_config | The model's settings. It's a class attribute, not a field |
ConfigDict(...) | Builds those settings |
extra="forbid" | Any field that isn't declared raises a ValidationError. The other choices are "ignore" (the default) and "allow" |
The ConfigDict reference describes extra as: "Whether to ignore, allow, or forbid extra data during model initialization. Defaults to 'ignore'."
The Example
A User model has two fields, name and age. The script creates one user correctly, then passes a third field, emial, as a typing slip for email would.
Prerequisites
- pydantic in your project, for example with
uv add pydantic. This guide uses pydantic 2.14.4 on Python 3.15.2.
Step 1: Write the Script
from pydantic import BaseModel, ConfigDict, ValidationError
class User(BaseModel):
model_config = ConfigDict(extra="forbid")
name: str
age: int
print(User(name="Ada", age=36))
try:
User(name="Ada", age=36, emial="ada@example.com")
except ValidationError as error:
print(error)

Step 2: Run It
uv run python strict_user.py
name='Ada' age=36
1 validation error for User
emial
Extra inputs are not permitted [type=extra_forbidden, input_value='ada@example.com', input_type=str]
For further information visit https://errors.pydantic.dev/2.14/v/extra_forbidden

The valid user printed normally. The second one failed, and the error names the unknown field, emial, and the value it carried. The command works unchanged in PowerShell.
Without forbid
Here's the same second user against a User model with no model_config, which uses the default, "ignore":
name='Ada' age=36
No error, and the email is gone. With ConfigDict(extra="allow") instead, the model keeps it as an extra attribute:
name='Ada' age=36 emial='ada@example.com'
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Leaving the default | A misspelled field is dropped without a warning | Set extra="forbid" when every field is known in advance, such as in a settings file |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Extra inputs are not permitted [type=extra_forbidden ...] | The data has a field the model doesn't declare | Fix the field's spelling, or add the field to the model |
FAQ
Does forbid apply to models nested inside this one?
No. Each model has its own model_config. With extra="forbid" on User only, a nested Address model still dropped an unknown postcode without an error, and printed name='Ada' address=Address(city='London'). A shared base class sets it once: when Address inherited from a Strict(BaseModel) class with extra="forbid", the same postcode failed with Extra inputs are not permitted.
When is ignore the better choice?
When the data comes from a source that adds fields you don't use, such as another team's API. Forbid would then fail on every new field they add.
Conclusion
model_config = ConfigDict(extra="forbid") made User refuse the misspelled emial with Extra inputs are not permitted, where the default would have dropped it without a word.
Additional Resources
- ConfigDict.extra — the three values with examples.
- Models — how pydantic models validate their data.
