Prompt
Do I need to validate API schemas in production?
Latest observation
Oct 29, 2026
OpenAI APIWeb search: off
Usually yes, but selectively.
Short answer
You generally want schema validation at the API boundary in production for:
- Incoming requests: to reject malformed or unsafe input early
- Outgoing responses: when you need strong guarantees that your service isn’t serving invalid data
- Critical workflows: payments, auth, compliance, integrations, etc.
But you usually don’t want to validate everything, everywhere, all the time if it adds too much latency or cost.
Best practice
A common production approach is:
- Validate external requests
- Path/query/body against your OpenAPI/JSON Schema/Pydantic/etc.
- Return a clean 4xx error on mismatch
- Validate internal assumptions in code
- Type checks, invariants, unit tests, assertions
- Optionally validate responses
- Especially for public APIs or when using generated schemas
- Use stricter validation in staging/CI
- Catch schema drift before deployment
When production validation is especially important
- Public-facing APIs
- Microservices with many consumers
- Third-party integrations
- Security-sensitive endpoints
- Regulated domains
When you might relax it
- Very high-throughput internal services where latency is critical
- Stable internal contracts with strong CI/type enforcement
- Performance-sensitive hot paths, if you’ve measured the cost
In those cases, you might validate:
- only at service edges
- only on writes
- only sampling a fraction of traffic
- or only in canary deployments
Rule of thumb
If invalid data could cause:
- security issues,
- data corruption,
- customer-visible failures,
- or expensive downstream errors,
then yes, validate in production.
If you want, I can also give you:
- a practical validation strategy for production APIs, or
- a pros/cons table for request vs response validation.