Skip to content

Commit

Permalink
Add documentation on providing a description when pausing a flow run (#…
Browse files Browse the repository at this point in the history
…11799)

Co-authored-by: Bill Palombi <bill@prefect.io>
  • Loading branch information
bunchesofdonald and billpalombi committed Feb 1, 2024
1 parent f5b6285 commit da8226b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions docs/guides/creating-interactive-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,50 @@ async def greet_user():

When a user sees the form for this input, the name field will contain "anonymous" as the default.

### Providing a description with runtime data

You can provide a dynamic, markdown description that will appear in the Prefect UI when the flow run pauses. This feature enables context-specific prompts, enhancing clarity and user interaction. Building on the example above:

```python
from datetime import datetime
from prefect import flow, pause_flow_run, get_run_logger
from prefect.input import RunInput


class UserInput(RunInput):
name: str
age: int


@flow
async def greet_user():
logger = get_run_logger()
current_date = datetime.now().strftime("%B %d, %Y")

description_md = f"""
**Welcome to the User Greeting Flow!**
Today's Date: {current_date}
Please enter your details below:
- **Name**: What should we call you?
- **Age**: Just a number, nothing more.
"""

user_input = await pause_flow_run(
wait_for_input=UserInput.with_initial_data(
description=description_md, name="anonymous"
)
)

if user_input.name == "anonymous":
logger.info("Hello, stranger!")
else:
logger.info(f"Hello, {user_input.name}!")
```

When a user sees the form for this input, the given markdown will appear above the input fields.


### Handling custom validation

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](https://docs.pydantic.dev/1.10/usage/validators/).
Expand Down

0 comments on commit da8226b

Please sign in to comment.