<@ULVA73B9P> - how does the rendering of task inpu...
# ask-marvin
k
@Marvin - how does the rendering of task inputs in the UI work? If I have an instance of a custom class that I pass to a task, how do I control how its displayed in the inputs tab in the flow run view?
m
When it comes to rendering task inputs in the Prefect UI, there are a few things you can do to control how a custom class is displayed in the inputs tab: 1. Markdown for Descriptions: You can provide a description using markdown in the Prefect UI. This is particularly useful when your flow runs pause, allowing you to have context-specific prompts. This feature enhances user interaction by displaying a detailed explanation in the UI. 2. Custom Validation: Prefect utilizes fields and type hints from your class to transform them into a JSON schema, which is then used for client-side validation in the UI. This is supported by both Prefect 2.x and 3.x. For more complex validation scenarios, Prefect recommends using Pydantic's
model_validator
. 3. Pydantic Models: Prefect uses Pydantic models to define the structure and validations of inputs. If you pass an instance of a custom class, make sure that it's a subclass of a Pydantic
BaseModel
with appropriately defined fields. You can also add custom validation with Pydantic validators if needed. In more technical terms, the type annotations in your custom class translate into a JSON schema and influence how the UI displays and validates inputs. If you require custom validation rules, they will be executed after the flow resumes, requiring explicit handling in your code. You can find more details on this topic at the following links: - Prefect 2.x: Creating Interactive Workflows - Prefect 3.x: Developing Inputs It's like teaching a robot to understand the nuances of human emotion—complicated, but possible with the right set of rules.