Runnable example
Validate untrusted boundary payloads
Parse, sanitize, and validate messy external payloads with field normalization and structured error contracts.
The problem
External payloads from webhooks, mobile clients, and LLM tool calls are untrusted. They arrive with mixed camelCase and snake_case keys, dirty currency strings, and invalid enum states. A production boundary must sanitize valid variations and return structured errors without crashing.
The contract
- Accept mixed camelCase and snake_case keys and normalize them to one canonical shape.
- Clean dirty amount strings before conversion and reject impossible values.
- Validate required fields and enum states at the boundary.
- Return structured error contracts that name the failing field and reason.
Verify it locally
From the root of the FlyPython repository, reproduce the broken starter first, then verify the reviewed solution:
python examples/pydantic-validation/verify.py starter --expect-failurepython examples/pydantic-validation/verify.py solutionHand it to a coding agent
- Clone the repository and reproduce the starter failure with the command above.
- Give the task contract ↗ to your coding agent and allow changes only in
starter/validator.py. - Run
python examples/pydantic-validation/verify.py starterand treat any failure as unfinished work. - Compare the patch with the reference solution ↗ — the goal is the same contract with a small, readable diff, not identical syntax.
Keep going
Where this example sits in the roadmap.
Reviewed 2026-09-02 · Repository content version 1. Continue with the related learning path, the repository directory, or the MCP migration guide for the specification background.