Skip to main content

Validation and serialization layer for Azure Functions Python v2 programming model

Project description

Azure Functions Validation

PyPI Python Version CI Release Security Scans codecov pre-commit Docs License: MIT

Read this in: 한국어 | 日本語 | 简体中文

Validation and serialization for the Azure Functions Python v2 programming model.


Part of the Azure Functions Python DX Toolkit → Bring FastAPI-like developer experience to Azure Functions

Why this exists

Azure Functions Python v2 handlers often drift into the same repeated problems:

  • Repeated manual parsing — every handler calls req.get_json(), req.params.get(), handles ValueError individually
  • Inconsistent error responses — some handlers return 400, others 422, formats vary across the project
  • Missing response contracts — response payloads silently diverge from the intended schema
  • No type safety — request data flows through as untyped dicts, bugs surface only at runtime

What it does

  • Typed validation — body, query, path, and header parameters validated via Pydantic v2
  • Automatic error responses — invalid requests get consistent 400/422 JSON error bodies
  • Response model enforcement — mismatches raise ResponseValidationError (HTTP 500)
  • Decorator-first API@validate_http wraps your handler, no boilerplate needed

FastAPI comparison

Feature FastAPI azure-functions-validation
Request body parsing Built-in via type hints @validate_http(body=Model)
Query/path/header validation Query(), Path(), Header() @validate_http(query=Model, path=Model, headers=Model)
Response model response_model= @validate_http(response_model=Model)
Validation errors Automatic 422 Automatic 422 with {"detail": [...]}
Error customization Exception handlers ErrorFormatter callback

Scope

  • Azure Functions Python v2 programming model
  • HTTP-triggered functions registered on func.FunctionApp()
  • Pydantic v2-based request and response validation

This package does not target the legacy function.json-based v1 programming model.

What this package does not do

This package does not own:

Features

  • Typed body, query, path, and header validation via @validate_http
  • Automatic 400 / 422 responses with {"detail": [...]} envelope
  • Response model validation — mismatches raise ResponseValidationError (HTTP 500)
  • Custom per-handler error formatting via ErrorFormatter

Installation

pip install azure-functions-validation

Your Azure Functions app should also include:

azure-functions
azure-functions-validation

For local development:

git clone https://github.com/yeongseon/azure-functions-validation.git
cd azure-functions-validation
pip install -e .[dev]

Quick Start

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 = "success"


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"Hello {body.name}")

Start the Functions host locally:

func start

Verify locally and on Azure

After deploying (see docs/deployment.md), the same request produces the same response in both environments.

Local

curl -s http://localhost:7071/api/users \
  -H "Content-Type: application/json" \
  -d '{"name": "Alice", "email": "alice@example.com"}'
{"message": "Hello Alice", "status": "success"}

Azure

curl -s "https://<your-app>.azurewebsites.net/api/users" \
  -H "Content-Type: application/json" \
  -d '{"name": "Alice", "email": "alice@example.com"}'
{"message": "Hello Alice", "status": "success"}

Invalid requests return the same 400 error in both environments:

Local

curl -s http://localhost:7071/api/users \
  -H "Content-Type: application/json" \
  -d 'not json'
{"detail": [{"loc": [], "msg": "Invalid JSON", "type": "value_error"}]}

HTTP 400

Azure

curl -s "https://<your-app>.azurewebsites.net/api/users" \
  -H "Content-Type: application/json" \
  -d 'not json'
{"detail": [{"loc": [], "msg": "Invalid JSON", "type": "value_error"}]}

HTTP 400

Verified against a temporary Azure Functions deployment in koreacentral (Python 3.12, Consumption plan). Response captured and URL anonymized.

When to use

  • You have HTTP-triggered Azure Functions that accept JSON request bodies
  • You want Pydantic-based validation without writing manual parsing code
  • You need consistent error response formats across handlers
  • You want response schema enforcement to catch contract drift

Documentation

  • Project docs live under docs/
  • Smoke-tested examples live under examples/
  • Product requirements: PRD.md
  • Design principles: DESIGN.md

Ecosystem

This package is part of the Azure Functions Python DX Toolkit.

Design principle: azure-functions-validation owns request/response validation and serialization. azure-functions-openapi owns API documentation and spec generation. azure-functions-langgraph owns LangGraph runtime exposure.

Package Role
azure-functions-langgraph LangGraph deployment adapter for Azure Functions
azure-functions-validation Request/response validation and serialization
azure-functions-openapi OpenAPI spec generation and Swagger UI
azure-functions-logging Structured logging and observability
azure-functions-doctor Pre-deploy diagnostic CLI
azure-functions-scaffold Project scaffolding
azure-functions-durable-graph Manifest-first graph runtime with Durable Functions
azure-functions-python-cookbook Recipes and examples

For AI Coding Assistants

When integrating with LLM-powered coding assistants, provide these files for context:

  • llms.txt — Concise index with quick start and API overview
  • llms-full.txt — Expanded reference with full signatures and patterns

Reference the files at repository root:

Disclaimer

This project is an independent community project and is not affiliated with, endorsed by, or maintained by Microsoft.

Azure and Azure Functions are trademarks of Microsoft Corporation.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

azure_functions_validation-0.7.0.tar.gz (105.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

azure_functions_validation-0.7.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file azure_functions_validation-0.7.0.tar.gz.

File metadata

File hashes

Hashes for azure_functions_validation-0.7.0.tar.gz
Algorithm Hash digest
SHA256 6bb227a6cad335e120fe0d2ece24eeaff433d302ccaea9e16d5b6bcd6012bb41
MD5 046fc28810119bfc1f689b3f23ad0fed
BLAKE2b-256 5a2c13cd9bcc355b5fbe87c84f457936a00f91f11434e50f35b1c23676e2acb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for azure_functions_validation-0.7.0.tar.gz:

Publisher: publish-pypi.yml on yeongseon/azure-functions-validation

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file azure_functions_validation-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for azure_functions_validation-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad9fd33b4b992837b36e16db9175fb433039c7bf7ee5c9272c124a33774ef16c
MD5 e0dbf662e71db93042524fbfa71b0b70
BLAKE2b-256 213462b80a2126688482440e4f3de097840836732dec70a67f2cb1d6bf08767b

See more details on using hashes here.

Provenance

The following attestation bundles were made for azure_functions_validation-0.7.0-py3-none-any.whl:

Publisher: publish-pypi.yml on yeongseon/azure-functions-validation

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page