<@ULVA73B9P> I added custom validator to my workfl...
# ask-marvin
k
@Marvin I added custom validator to my workflow input pydantic model but somehow I am still able to bypass it on the UI by triggering a workflow. Somehow the error was not raised. What am I missing? My validator is like this and both attr_1 and attr_2 have a default value of None.
Copy code
@root_validator
    def validate_mutually_exclusive(cls, values):
        if values.get("attr_1") is None and values.get("attr_2") is None:
            raise ValueError(
                "attr_1 and attr_2 are mutually exclusive. One of them must can be set."
            )
        return values
m
It seems like you might be encountering a situation where Prefect's UI validation is based on the JSON schema generated from your
RunInput
or
BaseModel
class type annotations, while your custom Pydantic validator runs as Python logic after the flow resumes. Since the custom validation happens server-side, you may not see the error raised until the flow has already started. This means you'll need to handle custom validation errors explicitly within your flow itself. Here's a relevant excerpt from the Prefect documentation:
Prefect uses the fields and type hints on your
RunInput
or
BaseModel
class to validate the general structure of input your flow receives, but you might require more complex validation. If you do, you can use Pydantic validators. Custom validation runs after the flow resumes. Prefect transforms the type annotations in your
RunInput
or
BaseModel
class to a JSON schema and uses that schema in the UI for client-side validation. However, custom validation requires running Python logic defined in your
RunInput
class. Because of this, validation happens after the flow resumes, so you'll want to handle it explicitly in your flow.
For best practices on implementing custom validation logic within your flow, refer to the Prefect documentation: Creating Interactive Workflows. No related GitHub issues were found, which means your situation might be unique or not widely reported. If you continue to experience problems, consider reaching out to the Prefect community or opening an issue on GitHub.