Story #22 Schema Validation · Input Contracts · Data Integrity

The Payload That Was Valid JSON but Invalid Business Data

"The request passed schema validation. It contained a negative quantity and a delivery date three years in the past"

Westbridge Procurement's purchase-order API validated JSON structure against its OpenAPI schema but lacked business-rule validation. Orders with negative quantities, past delivery dates, and impossible constraints reached downstream tax and fulfillment services, causing cascading failures.

What happened

Westbridge Procurement’s purchase-order API used a published OpenAPI schema to validate incoming requests. JSON structure, required fields, data types, and string formats were all checked automatically.

A supplier system with a data migration bug began submitting orders with negative line-item quantities, delivery dates set three years in the past, and total amounts that didn’t match the sum of line items. All of these requests passed schema validation—the types were correct, the required fields were present, the strings were formatted properly.

Downstream tax calculation services received negative amounts and produced incorrect tax entries. Inventory services tried to reserve negative quantities and threw unexpected errors. Fulfillment services rejected past delivery dates but returned cryptic errors that the procurement system didn’t handle. Some corrupted purchase orders persisted to the database and triggered automated payment workflows.

Unwinding the damage required auditing weeks of orders, crediting incorrect payments, and manually reconciling inventory.

Root cause

The API validated structure but not semantics. OpenAPI schema validation is not business-rule validation. No test submitted requests with values that were structurally valid but business-invalid—negative quantities, impossible dates, mismatched totals.

The fix

The team added a business-rule validation layer that ran before persistence: quantities must be positive, delivery dates must be in the future within a valid range, totals must match line item sums, supplier IDs must reference active accounts. Each rule returned a specific error response. Contract tests were written for every validation rule with valid and invalid examples.

Lesson learned

Schema validation is necessary but not sufficient. An API contract must define the business rules that make data meaningful, not just the types that make it parseable.

The Payload That Was Valid JSON but Invalid Business Data