Complete worked example
python
import json
from datetime import date
from pydantic import BaseModel, ConfigDict, Field, ValidationError
class Plan(BaseModel):
model_config = ConfigDict(strict=True)
day: date
count: int
def inspect_example(request):
value = request["value"]
try:
if request["mode"] == "json":
plan = Plan.model_validate_json(json.dumps(value))
else:
plan = Plan.model_validate(value)
return {"value": plan.model_dump(mode="json")}
except ValidationError as error:
return {"error": sorted({e["type"] for e in error.errors()})}- Reasoning
- The fixture labels the chosen mode and passes the same conceptual payload through each channel. In JSON mode, the ISO date is interpreted using the JSON date rules and the result is dumped back into JSON-compatible values. In Python mode, that date string fails the strict date field. The integer count remains strict in both modes: the string "2" and boolean true are not an integer count. Inspect the successful date conversion together with those rejected integer representations. This makes it clear why strict does not mean every JSON string is rejected or every vaguely numeric value is accepted.