<@ULVA73B9P> Is it possible to create Pydantic mod...
# ask-community
r
@Marvin Is it possible to create Pydantic models so that the Prefect UI performs client-side validation that involves aggregation? For example, if I want the user to input values that sum to 1.0, I want the UI to validate this input instead of having to spawn expensive infrastructure to check the input using a
@model_validator
.
m
thought for 246.2 seconds
Short answer: not today. In Prefect 3.x, the UI does not execute your Pydantic validators in the browser. When you fill out a form, the UI sends your values and the JSON Schema to a backend endpoint that performs server-side validation before any run is created. That validation is based on standard JSON Schema constraints (types, min/max, enum, required, if/then/else, etc.). Aggregate rules like “these numbers must sum to 1.0” cannot be expressed in JSON Schema and therefore can’t be enforced by the UI without running your Python code. Key points: - The UI’s “pre-submit” validation is server-side and lightweight — it does not spin up your workers/infrastructure — but it also does not run custom Pydantic
@model_validator
logic. - JSON Schema can handle many constraints (type, range, length, enums, dependentRequired/if-then-else), but not arithmetic across fields like a sum-equals-1 rule. Docs/refs: - Form building with Pydantic/JSON Schema - Pass inputs to workflows - The UI validation endpoint (used by the form) is documented here: prefect.server.api.ui.schemas Workarounds you can consider: - Normalize in your flow: accept non-normalized weights (constrain each value with JSON Schema: min/max, item count) and normalize to sum to 1.0 at the start of the run. - Fail fast at start: keep your Pydantic
@model_validator
and raise immediately; the run will exit almost instantly and still avoid doing any expensive work. - If you truly need to block before any run is created, you’d need a custom frontend or service that evaluates your aggregation rule before invoking Prefect — the built-in UI isn’t extensible for custom client-side logic today. If you share your exact parameter shape, I can suggest the strongest JSON Schema constraints the UI can enforce up front and a minimal “fail fast” pattern for anything it can’t.