Krystal
05/02/2024, 1:09 PM@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
Marvin
05/02/2024, 1:09 PMRunInput
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 yourFor 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.orRunInput
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 yourBaseModel
orRunInput
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 yourBaseModel
class. Because of this, validation happens after the flow resumes, so you'll want to handle it explicitly in your flow.RunInput