input validation
Checking that data from a user, file or caller is acceptable before using it, and rejecting or asking again if not.
In more detail
Validation rejects data that is the wrong type, out of range, badly formed or too large before it can cause errors or security problems. For a web API this means checking every part of a request, such as headers, body size and field values, against the contract at the boundary, before any query is built. A function or service that receives impossible input should signal a clear error rather than return a wrong answer.
Example
The course loops until input passes string checks such as isdigit, or catches ValueError from int().Related terms
- deny by default — The rule that anything not explicitly allowed is refused, including when the facts needed to decide are missing.
- SQL injection — An attack where untrusted input is joined into a database query so that part of it runs as SQL, letting an attacker read or change data.
- resource exhaustion — Running a service out of memory, time, connections or money by making it do unbounded work, whether by accident or on purpose.
- 400 Bad Request — The HTTP status meaning the request is malformed or asks for something outside what the API allows, such as a page size above the maximum.
- validation schema — A description of what valid data looks like, checked by code while the program runs so bad data is rejected at the door.
- Zod — A TypeScript library for declaring validation schemas that check data at run time and also produce matching static types.
- API contract — The written promise an API makes about its operations, inputs, outputs and errors, which callers rely on while the code behind it changes.
- ValueError — The Python exception raised when a function gets an argument of the right type but an unacceptable value, such as int("hello").
- try statement — The statement that runs a block of code and, if a listed exception happens there, runs an except block instead of letting the program stop.
- raise statement — The statement that signals an error by creating and throwing an exception, as in raise ValueError("width must be positive").
- isdigit() — String methods that check what kind of characters a string contains, such as isdigit for only digits.
Taught in
- Filtering And Searching — Modern API Architecture: REST, GraphQL & gRPC
- Partial Responses — Modern API Architecture: REST, GraphQL & gRPC
- WebSockets — Modern API Architecture: REST, GraphQL & gRPC
- Security Best Practices — Modern API Architecture: REST, GraphQL & gRPC
- End-to-End Type Safety: Shared Schemas & DTOs — Production Full-Stack Engineering
- Environment Configuration: Secrets & Multi-Stage — Production Full-Stack Engineering
- API Contract Architecture: OpenAPI 3.1 & Schema Truth — Production Full-Stack Engineering
- Type-Safe RPC Architectures: tRPC & Procedures — Production Full-Stack Engineering
- Resilient Error Handling: Problem Details & Envelopes — Production Full-Stack Engineering
- Raising, And Writing Your Own Exception — Hands-on Python: Complete Video Course & Book