Hi, I would like to ask about result validation as...
# ask-community
d
Hi, I would like to ask about result validation as suggested in PIN16, it seems that we can add a validator to a task and throw ValidationError if that task returns a value that fails the validator. Is that still a WIP or we can use it already or some time sooner? And btw is it by now we can only add validators to a result object and call result.validate() and throw a validation error ourselves? Thanks https://docs.prefect.io/core/pins/pin-16-results-and-targets.html
k
Hey @dipsy wong, the Result takes in
validators
and
run_validators
.
validators
is a list of callables that should return True if everything looks good. Then this will run if you set
run_validators=True
You can call
result.validate
yourself. You just need to create that
Result
class yourself with the appropriate validators.
d
@Kevin Kho I had a look at the code with @dipsy wong and it look like you can set the validators and run_validator that are used in the result.validate function. However this is not wired at all. Neither in the task or result. Is it expected? As well we cannot create custom result as it would not be serialized when we register the flow. Can we wire the result.validate before we persist result?
k
Let me dig through the code. I just saw it by reading the docs.
d
Thank you for following up on that
k
I saw the same thing digging. Asking the team for more details.
d
Great. At least we see the same think. And this is not align with the doc. Thank you for following with the team
k
Ok so it is not hooked up and we are likely going remove it from the docs because we are working on some other validation stuff in the future. So you would need to call that validate method yourself, or create some other way to validate data for now. Sorry about that.
d
Thank you for checking @Kevin Kho Do you know the timeline of the refactoring work that include that and the result handling to be completed?
k
It won’’t be anytime immediate to be honest so I would recommend the logic be handled inside the task. I think you might be able to plug the validations into the state handler as well. Is it data validations or schema validations?
d
We want to do both. And only persist the result if all are good
k
I guess the state handler won’t work as you don’t have the data at that point. Unfortunately, the only options for now would be to apply that logic manually in the task and error out, or potentially use the result interface manually also and call the
validate()
method. I wouldn’t recommend the
validate()
method because it may be removed from the public API as noone has used it (from what I have seen).
d
Yes I would not use it. I may have and idea to run that by creating my own custom task that call validate on the result
I may do that for the time been