{"record":{"id":"e1f5aaa8e7da7c61","repo":"mlflow/mlflow","slug":"an-mlflow-experiment-id-is-required-please-provid","errorCode":null,"errorMessage":"An MLflow experiment ID is required, please provide the experimentId option to init, or set the MLFLOW_EXPERIMENT_ID environment variable","messagePattern":"An MLflow experiment ID is required, please provide the experimentId option to init, or set the MLFLOW_EXPERIMENT_ID environment variable","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"libs/typescript/core/src/core/config.ts","lineNumber":247,"sourceCode":" *       span.setOutputs({ result });\n *       return result;\n *     }\n *   );\n * }\n * ```\n */\nexport function init(config: MLflowTracingInitOptions): void {\n  const trackingUri = config.trackingUri ?? process.env.MLFLOW_TRACKING_URI;\n  const experimentId = config.experimentId ?? process.env.MLFLOW_EXPERIMENT_ID;\n\n  if (!trackingUri) {\n    throw new Error(\n      'An MLflow Tracking URI is required, please provide the trackingUri option to init, or set the MLFLOW_TRACKING_URI environment variable',\n    );\n  }\n\n  if (!experimentId) {\n    throw new Error(\n      'An MLflow experiment ID is required, please provide the experimentId option to init, or set the MLFLOW_EXPERIMENT_ID environment variable',\n    );\n  }\n\n  if (typeof trackingUri !== 'string') {\n    throw new Error('trackingUri must be a string');\n  }\n\n  if (typeof experimentId !== 'string') {\n    throw new Error('experimentId must be a string');\n  }\n\n  const databricksConfigPath =\n    config.databricksConfigPath ?? path.join(os.homedir(), '.databrickscfg');\n\n  // Validate non-Databricks URIs\n  if (!isDatabricksUri(trackingUri) && !isValidHttpUri(trackingUri)) {\n    throw new Error(","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/libs/typescript/core/src/core/config.ts#L229-L265","documentation":"init() requires an experiment ID, from the experimentId option or the MLFLOW_EXPERIMENT_ID environment variable. Without it the SDK cannot target an experiment for trace storage and throws before proceeding to further validation.","triggerScenarios":"Calling init({ trackingUri: '...' }) with no experimentId and MLFLOW_EXPERIMENT_ID unset.","commonSituations":"New MLflow experiments not created yet so no ID is available; env var defined in one environment but not another; copying sample code that omits experimentId.","solutions":["Pass experimentId explicitly in init().","Set the MLFLOW_EXPERIMENT_ID environment variable.","Create an experiment in the MLflow UI/API (mlflow.create_experiment) and use its ID.","Use experimentId '0' (Default experiment) for local testing."],"exampleFix":"// before\ninit({ trackingUri: 'http://localhost:5000' });\n// after\ninit({ trackingUri: 'http://localhost:5000', experimentId: '0' });","handlingStrategy":"validation","validationCode":"const experimentId = configExperimentId ?? process.env.MLFLOW_EXPERIMENT_ID;\nif (!experimentId) {\n  throw new Error('Set MLFLOW_EXPERIMENT_ID or pass experimentId to init()');\n}\ninit({ trackingUri, experimentId });","typeGuard":"function hasExperimentId(c: { experimentId?: string }): c is { experimentId: string } {\n  return typeof c.experimentId === 'string' && c.experimentId.length > 0;\n}","tryCatchPattern":"try {\n  init(initOptions);\n} catch (err) {\n  if ((err as Error).message.includes('experiment ID is required')) {\n    console.error('Create an experiment and set MLFLOW_EXPERIMENT_ID');\n  }\n  throw err;\n}","preventionTips":["Create the experiment ahead of time and store its ID in config.","Pass experimentId explicitly in init() rather than via env.","Use '0' (Default experiment) for quick local smoke tests.","Verify env var injection in each deployment environment."],"tags":["configuration","missing-env-var","init","tracing"],"backgroundTag":"missing-env-var","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}