FastAPI endpoint design, Pydantic validation, dependency injection, and async patterns
{{ ... }}), and always declare variable sources. Avoid HTML comments (<!-- -->) as they may expose sensitive info or facilitate injection attacksOAuth2PasswordBearer or similar for authCORSMiddlewareAPIRouter and tagsdeprecated=Trueresponse_model parameterField() for validation constraints (min/max, regex, etc.)model_config for Pydantic v2 configurationDepends() for shared logic (auth, db sessions, etc.)async def for I/O-bound endpointsasyncio.gather() for parallel async operationsrun_in_executor)async with) for managing async resources (DB sessions, HTTP clients)BackgroundTasks for work that should outlive the response@app.on_event("startup"/"shutdown")) to initialize/cleanup shared async resourcesasyncio.Semaphore when calling external servicesHTTPException for expected errors with proper status codesdependencies module for reusable dependenciesconfig.py for settings management