diff --git a/docs/guides/creating-interactive-workflows.md b/docs/guides/creating-interactive-workflows.md index 776364798c43..89fabb732c9b 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 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/).