Skip to main content
View full project on GitHub Database cleanup is critical for self-hosted Prefect deployments (see database maintenance guide), but it’s risky: too automated and you might delete important data, too manual and it becomes a constant burden. This example shows how to build a cleanup workflow that evolves with your confidence:
  • Start with human approval: Preview what will be deleted, pause the flow, and manually approve/reject via a UI form
  • Graduate to AI autonomy: Switch to an AI agent that investigates system health using Prefect MCP tools and returns structured decisions with confidence scores
Build trust incrementally by monitoring decisions in lower-risk environments before enabling AI autonomy in production. For a full deployment example with scheduling and environment configuration, see: github.com/zzstoatzz/prefect-mcp-server-demo

Setup

The Prefect MCP server provides AI agents with read-only tools for investigating your Prefect instance. See How to use the Prefect MCP server for setup.

Configuration: Make Cleanup Policy Explicit

Instead of scattering configuration across your code, define it as a structured Pydantic model. This becomes a UI form automatically - see form building guide.
When using approval_type="human", the flow pauses and shows a form in the UI.
When using approval_type="ai", a pydantic-ai agent investigates using Prefect MCP tools to decide if cleanup is safe.

Deployment Examples