FastAPI 0.141
Last reviewed Sep 12, 2026
Prompt Details
Prompt Composition
3prompts
- Python 3155 lines · 3.8K tokens
- Pydantic 2.1356 lines · 1.3K tokens
- FastAPI 0.14179 lines · 3.4K tokens
Total290 lines · 8.5K tokens
CWE Coverage
- 20
- 23
- 36
- 59
- 78
- 79
- 89
- 95
- 117
- 201
- 208
- 209
- 214
- 250
- 295
- 306
- 307
- 319
- 328
- 338
- 347
- 352
- 367
- 379
- 409
- 416
- 426
- 427
- 434
- 470
- 502
- 525
- 532
- 552
- 598
- 601
- 611
- 613
- 614
- 639
- 674
- 732
- 770
- 772
- 776
- 807
- 829
- 862
- 915
- 916
- 918
- 942
- 1004
- 1104
- 1275
- 1284
- 1287
- 1333
- 1385
- 1395
Prompt Preview
Apply the Pydantic 2.13 and Python 3 prompts first. These rules cover FastAPI 0.141 dependency injection, authentication, request processing, response filtering, cookies, sessions, HTML output, asynchronous work, proxy configuration, and deployment.
Models and dependencies
- Use distinct Pydantic models for input, internal state, persistence, and public output.
- Expect FastAPI 0.141 to validate parsed JSON bodies and query, path, header, and cookie values with Pydantic's Python-mode
validate_python(), not JSON mode. Strict mode there, model-wide or per field, rejects ISO date and datetime strings, UUID strings, enum values, and allDecimalinput in bodies, and rejects every non-string scalar type, such asintorbool, in parameters. - Put
Field(strict=True)on thestr,int,float, andboolbody fields where coercion matters. KeepUUID,Decimal, date, and enum fields lax with explicit constraints, usingField(strict=False)inside an otherwise strict model, instead of dropping strictness from the whole model. When a body needs JSON-mode strictness, validate it withModel.model_validate_json(await request.body())instead of declaring a body parameter, and checkContent-Typeyourself because FastAPI's check no longer applies. - Put authentication and authorization dependencies on every protected router or operation, including custom API routes; protect mounted applications and generated documentation separately because they do not inherit app/router dependencies.
- Route any Starlette
HTTPEndpointsubclass with an explicitmethods=list