From 8883fe022c368458d1a909d4c85c6abe736ebf03 Mon Sep 17 00:00:00 2001 From: Chris Pickett Date: Thu, 1 Feb 2024 10:56:49 -0500 Subject: [PATCH 1/3] Add documentation on providing a description when pausing a flow run --- docs/guides/creating-interactive-workflows.md | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/docs/guides/creating-interactive-workflows.md b/docs/guides/creating-interactive-workflows.md index 776364798c43..e6ba5b870c05 100644 --- a/docs/guides/creating-interactive-workflows.md +++ b/docs/guides/creating-interactive-workflows.md @@ -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 markdown and 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/). From c4b4023f354e69afa5c8a0e2825ad89e35aacb26 Mon Sep 17 00:00:00 2001 From: Chris Pickett Date: Thu, 1 Feb 2024 11:04:21 -0500 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Bill Palombi --- docs/guides/creating-interactive-workflows.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guides/creating-interactive-workflows.md b/docs/guides/creating-interactive-workflows.md index e6ba5b870c05..b4cbdba9c0c9 100644 --- a/docs/guides/creating-interactive-workflows.md +++ b/docs/guides/creating-interactive-workflows.md @@ -135,9 +135,9 @@ 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 markdown and runtime data +### Providing a description and 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: +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 e027a09f867b742c5df8e06dd5cd6cffb5f930a8 Mon Sep 17 00:00:00 2001 From: Chris Pickett Date: Thu, 1 Feb 2024 11:05:03 -0500 Subject: [PATCH 3/3] Update docs/guides/creating-interactive-workflows.md --- docs/guides/creating-interactive-workflows.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/creating-interactive-workflows.md b/docs/guides/creating-interactive-workflows.md index b4cbdba9c0c9..89fabb732c9b 100644 --- a/docs/guides/creating-interactive-workflows.md +++ b/docs/guides/creating-interactive-workflows.md @@ -135,7 +135,7 @@ 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 and runtime data +### 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: