<@ULVA73B9P>I have two flows, each with different ...
# ask-marvin
a
@MarvinI have two flows, each with different run tags. In the UI, is it possible when selecting deployment 1 of flow 1 to only display the tags related to that flow for filtering, instead of showing tags from both flows?
m
thought for 399.0 seconds
Short answer: not right now. In Prefect 3.x, the UI doesn’t scope the tag suggestions to the selected deployment/flow. In fact: - On a deployment’s Runs tab, there isn’t a tags picker today (you’ll mainly see state/name filters). - Where a tags selector does appear (e.g., dashboard cards), the suggestions are built from recent runs across the entire workspace, not limited to the current deployment/flow. Workarounds you can use today: - Filter by deployment + type the tag manually (even if it’s not in the suggestions). You can save this as a Saved Search for quick reuse. - If you need to audit which tags exist for a specific deployment, you can query via the API/client using filters for
deployment_id
and
tags
. Useful references: - Filters API (FlowRunFilterTags, FlowRunFilterDeploymentId, etc.) - Flow Runs REST API (supports filtering by deployment and tags) - Saved Searches API If you’d like, I can file a feature request to: - Scope tag suggestions to the current context (flow/deployment), and/or - Add a tags filter to the deployment runs tab. Would you like me to open that on your behalf?
a
@Marvin what is the workaround for that then ? what is the saved_searches you mentioned here ? also can you file a feature request to: - Scope tag suggestions to the current context (flow/deployment), and/or - Add a tags filter to the deployment runs tab
m
thought for 66.6 seconds
Great questions — here’s how to work around it today and what “saved searches” are. I also filed the feature request for you. Workarounds you can use now - From the global Runs page: 1) Filter by Deployment = your deployment 2) Add the tag(s) you care about by typing them manually (even if they don’t show up in suggestions) 3) Optional: save this combo as a Saved Search (see below) so you can jump back to it quickly - Via API/client (useful for auditing tags used by just one deployment): - Query flow runs scoped to a deployment + tag. For example:
Copy code
from prefect.client.orchestration import get_client
    from prefect.client.schemas.filters import FlowRunFilter, FlowRunFilterTags, FlowRunFilterDeploymentId, DeploymentFilter

    async def runs_for_deployment_with_tag(deployment_id: str, tag: str):
        async with get_client() as client:
            return await client.read_flow_runs(
                flow_run_filter=FlowRunFilter(
                    tags=FlowRunFilterTags(all_=[tag]),
                    deployment_id=FlowRunFilterDeploymentId(any_=[deployment_id]),
                )
            )
- You can also pull the unique tags from those runs to build your own context-scoped tag list. What are Saved Searches? - Saved Searches let you store a set of filters (deployment, states, tags, time windows, etc.) and reuse them in the UI with one click. - Typical flow: 1) Build the filters you want on the Runs page 2) Click “Save search”, give it a name (e.g., “Flow 1 – Prod tag”) 3) Reuse it anytime from the Saved Searches dropdown Docs: - Filters API: Filter schemas (FlowRunFilterTags, FlowRunFilterDeploymentId, etc.) - Flow Runs REST: Flow Runs REST API - Saved Searches API: Saved Searches API Feature request filed - I’ve opened a discussion/feature request to: - Scope tag suggestions to the current context (flow/deployment) - Add a Tags filter on the Deployment Runs tab - You can follow and add details here: Prefect Discussion #19556 If you share your workflow details (e.g., specific tags, flows, or screenshots), I can tailor a Saved Search or a short script that lists the tags seen for just that deployment.
a
@Marvin should I call the create of saved search by API or what ? clarify more how to use that approach
m
thought for 194.9 seconds
Short version: - If your Runs page has a “Saved searches” control, use it there: apply filters → Save search. - If your UI doesn’t expose that control (common in some 3.x Server builds), then yes — create them via the REST API. You can still reuse them programmatically, and they’ll show up in the UI once that control is present. Can you confirm: - Prefect Cloud or self‑hosted Server? - Prefect version (prefect version) and, if Server, which UI build you’re on? How to use Saved Searches today Option A — In the UI (if available) - Go to Runs - Add filters: Deployment = your deployment, Tags = your tag(s) - Click “Save search” (or “Saved searches” → “Save current search”), name it, and reuse it from the dropdown Option B — Create it via the REST API - Endpoints: Saved Searches REST API - Example: create a saved search that filters to a deployment and one tag. Replace placeholders with your values. For Cloud, include an Authorization header with your API key. Using curl
Copy code
# Create or update a saved search
curl -X PUT "$PREFECT_API_URL/api/saved_searches/" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $PREFECT_API_KEY" \
  -d '{
    "name": "My Deployment + Tag",
    "filters": [
      {
        "object": "deployment",
        "property": "id",
        "type": "string",
        "operation": "any_",
        "value": ["<your-deployment-id>"]
      },
      {
        "object": "flow_run",
        "property": "tags",
        "type": "array",
        "operation": "all_",
        "value": ["<your-tag>"]
      }
    ]
  }'

# List saved searches
curl -X POST "$PREFECT_API_URL/api/saved_searches/filter" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $PREFECT_API_KEY"
Using Python (async)
Copy code
import httpx
import os

api_url = os.environ.get("PREFECT_API_URL", "<http://localhost:4200>")
api_key = os.environ.get("PREFECT_API_KEY")  # required for Cloud

payload = {
  "name": "My Deployment + Tag",
  "filters": [
    {
      "object": "deployment",
      "property": "id",
      "type": "string",
      "operation": "any_",
      "value": ["<your-deployment-id>"]
    },
    {
      "object": "flow_run",
      "property": "tags",
      "type": "array",
      "operation": "all_",
      "value": ["<your-tag>"]
    }
  ]
}

headers = {"Content-Type": "application/json"}
if api_key:
    headers["Authorization"] = f"Bearer {api_key}"

async def create_saved_search():
    async with httpx.AsyncClient() as client:
        r = await client.put(f"{api_url}/api/saved_searches/", json=payload, headers=headers)
        r.raise_for_status()
        return r.json()
Notes and limitations - Some 3.x Server UIs don’t currently expose “Save search” in the Runs page. The API works regardless, and those saved searches will appear once the UI control is available. - You can still avoid Saved Searches altogether by querying runs directly via filters: - Filters reference: Filter schemas (FlowRunFilterTags, FlowRunFilterDeploymentId, etc.) - Flow Runs REST: Flow Runs REST API Feature request - I opened this request to improve the UI: - Scope tag suggestions to current flow/deployment - Add a Tags filter to the deployment’s Runs tab - Track it here: Prefect Discussion #19556 If you share your environment (Cloud vs Server + version) and your deployment name/tag, I’ll craft the exact JSON and POST it for you, and also show how to find the deployment ID quickly if you don’t have it.