{"record":{"id":"dec5e9dc5d9e4d49","repo":"microsoft/semantic-kernel","slug":"file-not-found-file-path","errorCode":null,"errorMessage":"File not found: {file_path}","messagePattern":"File not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"python/samples/demos/assistants_group_chat/group_chat.py","lineNumber":61,"sourceCode":"    This will upload file.txt to the assistant for use with the code interpreter tool.\n\n    Type \"exit\" to exit the chat.\n    \"\"\"\n    )\n\n\ndef parse_upload_command(user_input: str):\n    \"\"\"Parse the user input for an upload command.\"\"\"\n    match = re.search(r\"\\[upload\\s+(code_interpreter|file_search)\\s+(.+)\\]\", user_input)\n    if match:\n        return match.group(1), match.group(2)\n    return None, None\n\n\nasync def handle_file_upload(assistant_agent: OpenAIAssistantAgent, purpose: str, file_path: str):\n    \"\"\"Handle the file upload command.\"\"\"\n    if not os.path.exists(file_path):\n        raise FileNotFoundError(f\"File not found: {file_path}\")\n\n    file_id = await assistant_agent.add_file(file_path, purpose=\"assistants\")\n    print(f\"File uploaded: {file_id}\")\n\n    if purpose == \"code_interpreter\":\n        await enable_code_interpreter(assistant_agent, file_id)\n    elif purpose == \"file_search\":\n        await enable_file_search(assistant_agent, file_id)\n\n\nasync def enable_code_interpreter(assistant_agent: OpenAIAssistantAgent, file_id: str):\n    \"\"\"Enable the file for code interpreter.\"\"\"\n    assistant_agent.code_interpreter_file_ids.append(file_id)\n    tools = [{\"type\": \"file_search\"}, {\"type\": \"code_interpreter\"}]\n    tool_resources = {\"code_interpreter\": {\"file_ids\": assistant_agent.code_interpreter_file_ids}}\n    await assistant_agent.modify_assistant(\n        assistant_id=assistant_agent.assistant.id, tools=tools, tool_resources=tool_resources\n    )","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/samples/demos/assistants_group_chat/group_chat.py#L43-L79","documentation":"A FileNotFoundError raised when a user issues an [upload <purpose> <path>] command in the assistants group chat demo but the supplied path does not resolve to an existing file on disk. The regex parse succeeds and produces a path, but os.path.exists() returns False, so the upload is aborted before calling the assistant's add_file.","triggerScenarios":"Typing an upload command like [upload code_interpreter ./data.csv] where ./data.csv does not exist relative to the process working directory, or the file was never created/moved/deleted.","commonSituations":"Relative paths resolved against an unexpected cwd; file lives under a different folder than where the demo is launched; the path contains spaces or was mistyped; the file was removed between sessions.","solutions":["Provide an absolute path in the upload command, or cd to the directory containing the file before launching the demo.","Verify the file exists with the same user/permissions that run the demo.","If the path has spaces, ensure the regex captures the full remainder (group 2 is .+) and quote-check the typed command."],"exampleFix":"// before\n[upload code_interpreter resources/my file.csv]\n\n// after\n[upload code_interpreter /abs/path/to/resources/my file.csv]","handlingStrategy":"validation","validationCode":"import os\n\nabs_path = os.path.abspath(file_path)\nif not os.path.isfile(abs_path):\n    print(f\"No such file: {abs_path}\")  # surface to user before upload\n    return","typeGuard":"import os\n\ndef is_valid_upload_path(p: str) -> bool:\n    return bool(p) and os.path.isfile(os.path.abspath(p))","tryCatchPattern":"try:\n    await handle_file_upload(agent, purpose, file_path)\nexcept FileNotFoundError:\n    print(f\"Could not find '{file_path}'. Check the path and retry.\")","preventionTips":["Resolve upload paths to absolute before the upload command.","Validate file existence with os.path.isfile (not just exists) to reject directories."],"tags":["filesystem","user-input","assistants","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}