- Applies to
- Gatewayruntime for API, AI, and MCP gateways
- Hosting
- Managed EdgeManaged DedicatedSelf-Hosted
Request Validation Policy
The Request Validation policy validates incoming requests against your OpenAPI schema definitions, ensuring that all requests conform to your API's expected structure and data types before they reach your backend services.
With this policy, you'll benefit from:
- Data Integrity Protection: Prevent malformed or invalid data from reaching your backend systems
- Automatic Schema Enforcement: Leverage your existing OpenAPI definitions for validation without additional code
- Comprehensive Validation: Validate request bodies, query parameters, path parameters, and headers
- Detailed Error Responses: Return clear, actionable error messages that help API consumers fix invalid requests
- Developer-Friendly Experience: Improve the developer experience by providing immediate feedback on request issues
- Reduced Backend Errors: Minimize crashes and unexpected behavior caused by invalid input data
- API Contract Enforcement: Ensure all API consumers adhere to your documented API contract
When configured, any requests that do not conform to your OpenAPI schema will be
rejected with a 400: Bad Request response containing a detailed error message
(in JSON) explaining why the request was not accepted.
Configuration
The configuration shows how to configure the policy in the 'policies.json' document.
config/policies.json
Policy Configuration
name<string>- The name of your policy instance. This is used as a reference in your routes.policyType<string>- The identifier of the policy. This is used by the Zuplo UI. Value should berequest-validation-inbound.handler.export<string>- The name of the exported type. Value should beRequestValidationInboundPolicy.handler.module<string>- The module containing the policy. Value should be$import(@zuplo/runtime).handler.options<object>- The options for this policy. See Policy Options below.
Policy Options
The options for this policy are specified below. All properties are optional unless specifically marked as required.
validateBody<string>- The action to perform when validation fails. Allowed values arenone,log-only,reject-and-log,reject-only. Defaults to"none".validateQueryParameters<string>- The action to perform when validation fails. Allowed values arenone,log-only,reject-and-log,reject-only. Defaults to"none".validatePathParameters<string>- The action to perform when validation fails. Allowed values arenone,log-only,reject-and-log,reject-only. Defaults to"none".validateHeaders<string>- The action to perform when validation fails. Allowed values arenone,log-only,reject-and-log,reject-only. Defaults to"none".logLevel<string>- The log level to use when logging validation errors. Allowed values areerror,warn,info,debug. Defaults to"info".includeRequestInLogs<boolean>- Whether to include the request in the logs. Defaults tofalse.
Using the Policy
The Request Validation Inbound policy validates incoming requests against your OpenAPI schema definitions. This ensures that all requests to your API conform to your specified data structure and types before they reach your backend services.
How It Works
This policy automatically validates incoming requests based on the OpenAPI schemas defined in your API specification. It checks:
- Request Bodies: Validates JSON/XML payloads against your schema definitions
- Query Parameters: Ensures query parameters match expected types and constraints
- Path Parameters: Validates URL path parameters against defined patterns
- Headers: Verifies required headers are present and conform to specifications
When a request fails validation, the policy returns a detailed 400 Bad Request response with specific information about which part of the request failed validation and why.
Configuration
The policy requires minimal configuration as it automatically uses your existing OpenAPI schemas. You can enable or disable validation for specific parts of the request (body, query parameters, headers) through the policy options.
OpenAPI Schema Example
Here's an example of how to specify a schema for validation in a request body in your OpenAPI specification:
Code
Advanced Validation
The policy supports the full range of OpenAPI schema validation features, including:
- Type validation (string, number, boolean, array, object)
- Format validation (date, date-time, email, etc.)
- Pattern matching with regular expressions
- Numeric constraints (minimum, maximum, multipleOf)
- String constraints (minLength, maxLength)
- Array constraints (minItems, maxItems, uniqueItems)
- Required properties
- Enum values
- Complex schemas with allOf, anyOf, oneOf, and not
Compatibility date 2026-11-06
From compatibility date 2026-11-06, the policy validates requests against the
rules your OpenAPI document declares. For how to adopt the date in an existing
project, see
Compatibility dates.
- JSON Schema dialect: Validation follows the dialect a schema declares in
$schemaorjsonSchemaDialect. It supports JSON Schema 2020-12, 2019-09, draft-07, and draft-06. In draft-07 and draft-06, keywords next to a$refother than annotations are ignored, as those dialects specify. - Formats: Standard formats such as
date-time,email,hostname,ipv4,ipv6,uri,uuid, and the OpenAPI numeric formats are checked as their specifications define them.url,binary,password, and unknown formats aren't checked, soformat: "url"doesn't reject an invalid URL. Useformat: "uri"or apatterninstead. - Patterns: A
patternis a Unicode regular expression. A pattern such as^\p{L}+$matchescafé. - Own properties only:
requiredandpropertieslook only at properties the request sets, so{}doesn't satisfy"required": ["constructor"]. - Parameter coercion: Query, path, and header values arrive as strings, and
the policy still coerces them to the declared type. A query string
?limit=5is valid for{ "type": "integer" }. - Path item parameters: Parameters declared on a path item, rather than on
an operation, are validated in every location the policy checks. An operation
parameter with the same
nameandinoverrides the path item's.
Before this date, a request that carried a parameter declared on the path item
failed with Validator not found when the policy validated that location. From
this date, that error no longer occurs for those parameters. A request that
breaks the parameter's schema is handled like any other validation failure: a
400 response with reject-only or reject-and-log, and a log entry without
rejecting the request with log-only.
Code
With validatePathParameters set to reject-only, POST /users/3 succeeds and
POST /users/0 returns a 400 because id is below the minimum.
A schema that declares a dialect other than those four fails the build and names where the dialect is declared.
Read more about how policies work