Azure Functions Validation¶
Typed request and response validation for Azure Functions Python v2 HTTP handlers.
azure-functions-validation helps you remove repetitive req.get_json() parsing,
enforce consistent validation behavior, and keep your handler contracts explicit.
It is designed for the decorator-based func.FunctionApp() model.
5-second rule
If you can paste one decorator and one Pydantic model, you can get immediate request validation plus typed response serialization.
Quick Copy-Paste Example¶
import azure.functions as func
from pydantic import BaseModel
from azure_functions_validation import validate_http
class CreateUserRequest(BaseModel):
name: str
email: str
class CreateUserResponse(BaseModel):
message: str
status: str = "ok"
app = func.FunctionApp()
@app.function_name(name="create_user")
@app.route(route="users", methods=["POST"], auth_level=func.AuthLevel.ANONYMOUS)
@validate_http(body=CreateUserRequest, response_model=CreateUserResponse)
def create_user(req: func.HttpRequest, body: CreateUserRequest) -> CreateUserResponse:
return CreateUserResponse(message=f"Created user {body.name}")
What you get¶
- Incoming JSON is validated against
CreateUserRequest. - Invalid input returns a structured
422response. - Return values are validated against
CreateUserResponse. - Output is serialized as JSON with a consistent content type.
Default error envelope
Validation errors are returned as JSON with a detail array.
Why teams use this package¶
- Less boilerplate: no repeated parsing and validation glue in each handler.
- Typed contracts: request and response schemas are first-class and testable.
- Consistent client experience: same error shape across endpoints.
- Safer changes: response validation catches drift before clients do.
- Async support: same decorator works for
defandasync defhandlers.
Feature Snapshot¶
Request validation sources¶
body: JSON request body validation.query: query string validation.path: route parameter validation.headers: header validation.request_model: shorthand alias for body validation.
Response validation¶
response_modelvalidates what your handler returns.- Invalid response payloads return a
500with a safe validation envelope. - Returning
func.HttpResponsebypasses model validation intentionally.
Use request_model carefully
request_model cannot be combined with body, query, path, or headers.
Use explicit body=... when validating multiple input sources.
Where to go next¶
- Start with Quickstart.
- Learn all decorator options in Configuration.
- See full patterns in Usage.
- Browse production-style scenarios in Examples.
- Explore public APIs in API Reference.
Ecosystem Fit¶
azure-functions-validation focuses on runtime validation behavior.
If you also need OpenAPI documents and Swagger UI, pair it with
azure-functions-openapi and share the same Pydantic models.
Runtime + docs together
Use this package to validate real requests and responses at runtime, and use OpenAPI tooling to generate API docs from those same models.
Compatibility¶
- Python 3.10+
- Azure Functions Python v2 programming model
- Pydantic v2
For dependency setup details, see Installation.
Example Index¶
Need help?¶
- Common fixes: Troubleshooting
- Frequent questions: FAQ
- Contribution workflow: Guidelines