{"record":{"id":"3f300ec967c8f239","repo":"infiniflow/ragflow","slug":"tenant-not-found-3f300e","errorCode":null,"errorMessage":"Tenant not found","messagePattern":"Tenant not found","errorType":"exception","errorClass":"LookupError","httpStatus":null,"severity":"error","filePath":"api/db/services/tenant_llm_service.py","lineNumber":134,"sourceCode":"        # model name must be xxx@yyy\n        try:\n            model_factories = settings.FACTORY_LLM_INFOS\n            model_providers = set([f[\"name\"] for f in model_factories])\n            if arr[-1] not in model_providers:\n                return model_name, None\n            return arr[0], arr[-1]\n        except Exception as e:\n            logging.exception(f\"TenantLLMService.split_model_name_and_factory got exception: {e}\")\n        return model_name, None\n\n    @classmethod\n    @DB.connection_context()\n    def get_model_config(cls, tenant_id, llm_type, llm_name=None):\n        from api.db.services.llm_service import LLMService\n\n        e, tenant = TenantService.get_by_id(tenant_id)\n        if not e:\n            raise LookupError(\"Tenant not found\")\n\n        if llm_type == LLMType.EMBEDDING.value:\n            mdlnm = tenant.embd_id if not llm_name else llm_name\n        elif llm_type == LLMType.ASR.value:\n            mdlnm = tenant.asr_id if not llm_name else llm_name\n        elif llm_type == LLMType.VISION.value:\n            mdlnm = tenant.img2txt_id if not llm_name else llm_name\n        elif llm_type == LLMType.CHAT.value:\n            mdlnm = tenant.llm_id if not llm_name else llm_name\n        elif llm_type == LLMType.RERANK:\n            mdlnm = tenant.rerank_id if not llm_name else llm_name\n        elif llm_type == LLMType.TTS:\n            mdlnm = tenant.tts_id if not llm_name else llm_name\n        elif llm_type == LLMType.OCR:\n            if not llm_name:\n                raise LookupError(\"OCR model name is required\")\n            mdlnm = llm_name\n        else:","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/api/db/services/tenant_llm_service.py#L116-L152","documentation":"Raised by TenantLLMService.get_model_config when TenantService.get_by_id(tenant_id) fails, i.e. no tenant row matches the id. The model-config resolution needs tenant defaults (embd_id, llm_id, etc.), so an unknown tenant aborts immediately with LookupError.","triggerScenarios":"Passing a tenant_id that does not exist (deleted tenant, wrong environment, malformed uuid) to any API that resolves model configuration — chat, embedding, rerank, ASR, TTS setup.","commonSituations":"Hard-coded tenant ids in scripts after recreating the database; JWT/api-key belonging to a removed user; multi-instance deployments pointing at different DBs.","solutions":["Verify the tenant id exists: SELECT id FROM tenant WHERE id = ... or via the user/tenant API.","Obtain tenant_id from the authenticated session/API key rather than hard-coding it.","If the tenant was deleted, recreate the user/tenant or use a valid one.","Ensure all RAGFlow instances connect to the same database in HA setups."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"ok, _tenant = TenantService.get_by_id(tenant_id)\nif not ok:\n    return json_error_response('tenant not found', 401)","typeGuard":"import uuid as _uuid\n\ndef is_valid_tenant_id(tenant_id: str) -> bool:\n    try:\n        _uuid.UUID(str(tenant_id))\n    except (ValueError, TypeError):\n        return False\n    return TenantService.get_by_id(tenant_id)[0]","tryCatchPattern":"try:\n    cfg = TenantLLMService.get_model_config(tenant_id, llm_type, llm_name)\nexcept LookupError as e:\n    if 'Tenant not found' in str(e):\n        abort(401, 'unknown tenant')\n    raise","preventionTips":["Derive tenant_id from the authenticated request, never from configuration files.","Re-fetch stored tenant ids after re-provisioning a database.","Keep all API instances pointed at one shared DB in HA deployments."],"tags":["not-found","tenant","model-config","lookup-error"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}