API Input Validation Checklist: Types, Limits, Sanitization, and Safe Error Responses
APIssecure codingrequest validationbackend developmenttesting

API Input Validation Checklist: Types, Limits, Sanitization, and Safe Error Responses

VValidator Cloud Editorial Team
2026-11-14
7 min read

A practical API input validation checklist covering types, limits, nested data, sanitization, errors, authorization, and negative testing.

Before an API accepts a request, it should establish that the input has the expected shape, size, encoding, and meaning. This API input validation checklist provides a reusable workflow for reviewing endpoints, covering primitive types, required fields, limits, nested objects, arrays, dates, URLs, cross-field rules, sanitization, error responses, and negative tests. Use it before launching an endpoint, reviewing a pull request, or changing an existing contract.

Overview

API request validation is a server-side responsibility. Client-side checks improve user feedback, but they cannot be treated as a security boundary because clients can be bypassed, modified, or replaced. The API should validate every request at the point where it enters the system and should apply the same rules regardless of the caller.

A useful validation design separates three concerns:

  • Shape validation: Does the request use the expected content type, fields, data types, nesting, and collection structure?
  • Constraint validation: Are values within acceptable length, range, format, and count limits?
  • Business validation: Are the values valid together and permitted for this operation, account, resource, or workflow state?

Schema-based validation can make the first two layers consistent across services, but a schema is not a complete authorization or business-rule system. For implementation details covering drafts, formats, errors, and compatibility testing, see the JSON Schema Validation Guide.

Validation should happen before expensive processing, database writes, external calls, or state changes. It should also produce predictable outcomes: reject malformed input clearly, avoid exposing internal details, and record enough structured information for debugging without logging secrets or sensitive personal data.

Checklist by scenario

For every endpoint

  • Confirm the accepted HTTP method and content type.
  • Reject malformed JSON, unexpected media types, and invalid character encoding.
  • Define which fields are required, optional, nullable, or read-only.
  • Decide whether unknown fields are rejected, ignored, or preserved. Apply the choice consistently and document it.
  • Validate primitive types explicitly. Do not assume that a string containing digits is equivalent to a number, or that a truthy value is a Boolean.
  • Set maximum request sizes, field lengths, array lengths, and nesting depth appropriate to the endpoint.
  • Verify authentication and authorization separately from input validity. A well-formed request can still be unauthorized.

For strings and text fields

  • Define minimum and maximum lengths after deciding how whitespace and Unicode characters are handled.
  • Normalize only where the product requirement supports it. For example, trimming an email address may be reasonable, while silently changing a legal name may not be.
  • Use allowlists for controlled values such as status, country code, currency, or sort direction.
  • Validate formats with a deliberate rule rather than an excessively broad or brittle regular expression.
  • Encode output for its destination. Input validation does not replace context-specific output encoding for HTML, SQL, shell commands, logs, or templates.

For numbers, dates, and identifiers

  • Check numeric type, minimum, maximum, precision, and whether negative or zero values are allowed.
  • Guard against non-finite values, unsafe integer conversions, and unexpected decimal behavior.
  • Require a documented date or timestamp format, including timezone behavior. Reject ambiguous dates when they could change the result.
  • Validate identifiers for permitted character sets and length, but do not assume that format validation proves the resource exists or belongs to the caller.
  • Use exact comparison rules for money, quantities, and other values where rounding can affect a transaction.

For URLs, files, and external values

  • Restrict URL schemes and define whether redirects, ports, private network addresses, or local hostnames are permitted.
  • For uploaded files, validate declared and detected media types, size, filename handling, and storage behavior. Do not trust the filename or client-provided content type alone.
  • Set timeouts and response-size limits when the API fetches a user-supplied URL. Treat server-side requests as a separate security review.
  • When validating domains, certificates, DNS, or ownership data, keep network checks separate from basic syntax checks. The domain and SSL certificate validation checklist provides a related review path.

For nested objects and arrays

  • Validate every nested object recursively, including objects inside arrays.
  • Set collection limits and reject duplicate entries when uniqueness is required.
  • Specify whether an empty array or object is valid, rather than relying on framework defaults.
  • Prevent duplicate or conflicting representations of the same value, such as accepting both a top-level field and a nested alternative.
  • For patch operations, distinguish between an omitted field and an explicitly null field.

For cross-field and workflow rules

  • Check relationships such as start date before end date, amount matching currency, or a required address when a delivery option is selected.
  • Verify that referenced resources exist and that the caller can use them.
  • Apply state-transition rules server-side; do not accept a requested status merely because it is an allowed enum value.
  • Use idempotency controls for operations that create charges, orders, or other non-repeatable effects. See the Validation API Reliability Guide for related retry and timeout considerations.

For errors and observability

  • Return a stable status convention and a machine-readable error code.
  • Identify the invalid field or path without echoing sensitive input.
  • Use general messages for security-sensitive failures where detailed feedback could help an attacker.
  • Keep error formats consistent across endpoints and API versions.
  • Track validation failures by endpoint, rule, and version, while excluding credentials, tokens, payment data, and unnecessary personal information from logs.

What to double-check

Use this compact review table when deciding where a rule belongs:

Validation layerQuestionTypical examples
TransportCan the request be safely parsed?HTTP method, content type, encoding, body size
SchemaDoes the data have the expected shape?Required fields, types, enums, nested objects
ConstraintsAre individual values acceptable?Length, range, precision, format, collection limits
Business rulesDo the values make sense together?Date relationships, state transitions, account limits
AuthorizationMay this caller perform this operation?Resource ownership, role, tenant boundary
External verificationCan a value be checked outside the request?Address, domain, identity, fraud, or document checks

Do not combine all failures into one generic “invalid request” path if operators need to distinguish malformed payloads from unavailable verification services. At the same time, avoid returning an internal exception, database query, stack trace, or validation implementation detail to the caller.

Build a negative-test set for every endpoint. A reusable template can include: missing required field; wrong primitive type; null where disallowed; empty string; whitespace-only value; minimum and maximum boundary; just-beyond-limit value; malformed date; invalid enum; duplicate array item; unknown field; deeply nested object; oversized body; conflicting fields; unauthorized resource ID; and repeated request with the same idempotency key. Add tests for malformed encodings and unexpected content types where those inputs are possible.

Run these tests at more than one level. Unit tests should cover individual rules, contract tests should verify the published request and response shape, and integration tests should confirm that invalid input does not create partial state or trigger unintended external calls. Fuzz or property-based testing can supplement, but not replace, specific boundary cases.

Common mistakes

  • Relying on client-side validation: Treat browser or mobile checks as convenience features, never as the API boundary.
  • Using one large regular expression for everything: Complex expressions are difficult to maintain and may reject valid data or accept unsafe input. Prefer clear, purpose-specific rules.
  • Confusing sanitization with validation: Removing characters can change meaning and may create a false sense of safety. First decide what is valid, then encode or normalize for the destination.
  • Validating only the outer object: Nested values, array members, and patch operations need explicit rules.
  • Trusting parsed types: Framework coercion may turn strings into numbers, accept unexpected Boolean representations, or silently discard fields. Review and configure coercion deliberately.
  • Leaking too much in errors: Field-level feedback is useful, but database details, secrets, tokens, and internal paths do not belong in public responses.
  • Changing rules without a compatibility plan: Tightening a constraint can break existing clients. Version the contract, communicate the change, and test representative older payloads.
  • Skipping authorization after validation: A valid identifier is not proof that the caller may access the identified resource.

When to revisit

Review this API validation checklist before seasonal planning cycles, endpoint launches, major releases, and changes to workflows or tools. Revisit it whenever a field is added, renamed, made optional, or given a new limit; when a schema library or framework changes its defaults; when an API version is introduced; or when monitoring shows a new class of malformed request.

Schedule a focused review after an incident, a dependency upgrade, a change in external verification behavior, or a migration between JSON Schema drafts or validation libraries. Include application developers, security reviewers, and service owners when rules affect authorization, sensitive data, payments, identity checks, or external calls.

For a practical final pass, choose one endpoint and document its accepted content type, field table, limits, cross-field rules, authorization assumptions, error format, and negative tests. Then verify that invalid requests fail before side effects occur, that logs contain useful non-sensitive diagnostics, and that the published contract matches the deployed behavior. Repeat the same review for each endpoint with a different risk profile rather than assuming one global schema covers every use case.

Related Topics

#APIs#secure coding#request validation#backend development#testing
V

Validator Cloud Editorial Team

Developer API Validation Editors

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.