{"record":{"id":"cafeb5cd60679933","repo":"langflow-ai/langflow","slug":"invalid-flow-id-not-a-valid-uuid-cafeb5","errorCode":null,"errorMessage":"Invalid flow_id: not a valid UUID.","messagePattern":"Invalid flow_id: not a valid UUID\\.","errorType":"http","errorClass":"HTTPException","httpStatus":422,"severity":"error","filePath":"src/backend/base/langflow/agentic/utils/assistant_runner.py","lineNumber":41,"sourceCode":"from langflow.agentic.services.flow_types import LANGFLOW_ASSISTANT_FLOW\nfrom langflow.api.v1.flows import _new_flow, _save_flow_to_fs\nfrom langflow.initial_setup.setup import get_or_create_default_folder\nfrom langflow.services.database.models.flow.guards import ensure_flow_unlocked, lock_flow_for_update\nfrom langflow.services.database.models.flow.model import Flow, FlowCreate\nfrom langflow.services.deps import get_storage_service\n\nif TYPE_CHECKING:\n    from sqlmodel.ext.asyncio.session import AsyncSession\n\nDEFAULT_FLOW_NAME = \"Assistant Flow\"\n\n\nasync def _ensure_flow(session: AsyncSession, user_id: UUID, flow_id: str | None) -> tuple[Flow, bool]:\n    if flow_id:\n        try:\n            flow_uuid = UUID(flow_id)\n        except ValueError as exc:\n            raise HTTPException(status_code=422, detail=\"Invalid flow_id: not a valid UUID.\") from exc\n        flow = await session.get(Flow, flow_uuid)\n        if flow is None or (flow.user_id is not None and str(flow.user_id) != str(user_id)):\n            raise HTTPException(status_code=404, detail=\"Flow not found.\")\n        return flow, False\n\n    folder = await get_or_create_default_folder(session, user_id)\n    new_flow = FlowCreate(\n        name=DEFAULT_FLOW_NAME,\n        description=\"Created by the Langflow Assistant via MCP\",\n        data={\"nodes\": [], \"edges\": []},\n        folder_id=folder.id,\n        user_id=user_id,\n    )\n    storage_service = get_storage_service()\n    created = await _new_flow(session=session, flow=new_flow, user_id=user_id, storage_service=storage_service)\n    await session.commit()\n    # _new_flow returns a FlowRead; re-fetch the ORM row so later edits persist.\n    db_flow = await session.get(Flow, created.id)","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/agentic/utils/assistant_runner.py#L23-L59","documentation":"Raised by the assistant runner's _ensure_flow when the supplied flow_id string cannot be parsed by the UUID constructor. The MCP assistant accepts an optional flow_id to target an existing flow; anything that is not a canonical UUID string (including UUIDs with braces, urn: prefix without normalization quirks, or plain garbage) is rejected with 422 before any DB access.","triggerScenarios":"Calling the assistant run/edit endpoint or MCP tool with flow_id like 'my-flow', '123', a flow name, or a URL fragment instead of the flow's UUID; passing an int id from an external system.","commonSituations":"Confusing the flow's display name or endpoint name with its id; copying the id with surrounding quotes/whitespace from the UI URL; integrations storing their own numeric primary keys.","solutions":["Use the flow's UUID as shown in the URL /api/v1/flows/{id} — copy it verbatim, no braces or prefixes.","If you only know the name, first resolve it via GET /api/v1/flows/?name=... and use the returned id.","Strip whitespace and validate the value client-side with a UUID regex before calling."],"exampleFix":"# before\nawait run_assistant(flow_id=\"Assistant Flow\", ...)\n\n# after\nflows = await client.get(\"/api/v1/flows/\", params={\"name\": \"Assistant Flow\"})\nawait run_assistant(flow_id=flows[0][\"id\"], ...)","handlingStrategy":"validation","validationCode":"from uuid import UUID\n\ndef is_flow_uuid(value: str) -> bool:\n    try:\n        UUID(value.strip())\n        return True\n    except (ValueError, AttributeError):\n        return False","typeGuard":"def is_uuid_string(v: str | None) -> TypeGuard[str]:\n    if not isinstance(v, str):\n        return False\n    try:\n        UUID(v.strip())\n        return True\n    except ValueError:\n        return False","tryCatchPattern":null,"preventionTips":["Always fetch flow ids from the API responses, never hand-type them.","Store ids unmodified (no braces/urn prefixes) in client state.","Validate with UUID() client-side before calling assistant endpoints."],"tags":["validation","uuid","assistant","http-422"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}