https://prefect.io logo
i

Idan

07/26/2023, 11:24 AM
With typing hints, can Prefect handle more complicated hints for the UI? If, for example, I’d like to have a list of some pydantic basemodel, could Prefect process that to show the various fields?
j

Jessica Smith

07/26/2023, 1:31 PM
Not sure about the actual answer to your question, but is something you could use blocks for? Or would it have to be passed in as a parameter?
i

Idan

07/26/2023, 1:34 PM
It’s a parameter, and mostly just a UI question about the capabilities for Prefect. It’ll be nice to have it available as such, rather than having to specify a JSON format.
j

Jessica Smith

07/26/2023, 1:44 PM
Ah, I gotcha. I'm curious to know the answer too, I agree it'd be nicer to handle it that way than via JSON
d

Deceivious

07/26/2023, 3:31 PM
Enum are displayed as Drop down. The deployment specs has open api params. Maybe you can look into that?
n

Nate

07/26/2023, 3:35 PM
if you have a pydantic model as an input like
Copy code
class Foo(BaseModel):
    a: int
    b: int

class Input(BaseModel):
    foo: Foo
    bar: str

@flow(log_prints=True)
def my_flow(input: Input) -> None:
    print(f"got input: {input!r}")
then the form will show up nicely in the UI with each field of
Input
(including the nested models), but if you have a
list[Input]
then the input in the UI will be a freeform JSON field. perhaps you could adjust the model you're passing in so that it contains your lists instead of passing a list of the models?
👍 1
i

Idan

07/26/2023, 4:15 PM
Would that work? If e.g. it was
foo: List[Foo]
?
n

Nate

07/26/2023, 4:20 PM
hmm actually it seems like whenever there's a
list[Model]
its going to be a freeform JSON field like (image is the Quick Run form for this deployment)
Copy code
from prefect import flow

from pydantic import BaseModel

class Foo(BaseModel):
    a: int
    b: int

class Input(BaseModel):
    foo: list[Foo]
    bar: str

@flow(log_prints=True)
def my_flow(input: Input) -> None:
    print(f"got input: {input!r}")

# prefect deploy typehints.py:my_flow
i

Idan

07/26/2023, 4:23 PM
That's a pity :( any alternatives? Could one leverage
*args
for this? 🤔
n

Nate

07/26/2023, 4:25 PM
what is it that you're trying to do? do you plan on spending a lot of time in the UI filling out the forms for flow runs?
i

Idan

07/26/2023, 4:27 PM
Just trying to use the UI for the less tech-oriented staff, so that they may run production flows themselves
I wouldn't even mind not having type checks, I mostly want to be able to include a docstring for each field in the flow, so they don't mess up
n

Nate

07/26/2023, 4:33 PM
makes sense! requirement about lists of models aside, seems like you could do
Copy code
from prefect import flow

from pydantic import BaseModel, Field

class Input(BaseModel):
    foo: int = Field(..., description="foo is a required field")
    bar: bool = Field(False, description="whether to bar or not")
    baz: list = Field(default_factory=list, description="a list of bazzes")

@flow(log_prints=True)
def my_flow(user_input: Input) -> None:
    print(f"got input: {user_input!r}")
i

Idan

07/26/2023, 4:35 PM
Hello I'd like to bar please. Yes! This looks like a good compromise, thanks! Any idea about future UI support for lists? Just to one-up this?
😄 2
n

Nate

07/26/2023, 4:37 PM
i don't know about future plans for the UI here, perhaps @Craig Harshbarger would have some input (pun intended)
😁 1
c

Craig Harshbarger

07/26/2023, 5:07 PM
This is mostly a
List[...]
question. Currently we don't have any ui to handle lists unless there is an
enum
and then we give you a drop down. We would have to add some ui to visually let you add/remove values and render the schema for the model in the list. Which gets a little tricky considering there can be unions and such. But its possible! Just not a priority at the moment. But if this is something you'd like to see please open a github issue for it and if there are others that want this that will help us set an accurate priority.
🙏 2
i

Idan

07/26/2023, 8:44 PM
Thanks @Craig Harshbarger! I've seen this before where usually there's simply "add" and "remove" buttons, that open a new item with the designated schema. I'll put a reminder to create a GH issue for this, would be a nice feature to have!
thank you 1
One last follow-up @Nate @Craig Harshbarger; is there a way to maintain docstring structure? In Nate’s example above (
a list of bazzes
), I’d like to include e.g. a sample JSON with explanation for the different kwargs. Prefect minimizes it to one-line, so the formatting is lost.
n

Nate

07/27/2023, 3:27 PM
is there a way to maintain docstring structure?
hmm I'm not quite sure what you mean, could you show an example? of what you mean by
a sample JSON with explanation for the different kwargs
i

Idan

07/27/2023, 3:41 PM
Let’s say I’d like to have:
Copy code
class Input(BaseModel):
    a: SomeOtherClass = Field(..., description="""A foo that bars some bazzes, with the following structure:
{
  # You may specify your foo as an integer here
  "foo": Optional[int]
  "bar": {
    # Your baz goes here
    "baz": str
    "should_baz": bool = False
  }
}
""")
This results in a single line, even though I’d like to maintain the multi-line description
c

Craig Harshbarger

07/27/2023, 5:29 PM
Can you verify if its coming from the api in the way you'd expect? Curious if it is the ui or api that is removing the formatting.
i

Idan

07/27/2023, 5:32 PM
Could you direct me how to check that?
c

Craig Harshbarger

07/27/2023, 8:23 PM
If you look at the deployment in the network tab. Basically just looking for what json the api is returning.
i

Idan

07/28/2023, 9:00 AM
Hm, I don’t see anything like that in the network tab 🤔
Ah, sorry, it was cached. Now I got it. In the JSON response it looks fine 👍 Newlines and indentations as expected, so it’s just a rendering thing.
c

Craig Harshbarger

08/08/2023, 4:56 PM
Sorry for the delay. Was on vacation and just catching back up on things. If this is still happening could you please create a github issue with a minimum reproduction? That's the best way to get this picked up and fixed.
i

Idan

08/24/2023, 7:44 AM
Sorry, I was also away on vacation. The ticketing list requires to verify with a different browser 🤔 I find that a bit discouraging, I don’t hold multiple browsers on my end and would prefer to refrain from installing additional ones 🙈