{"record":{"id":"a184a2644cde0f5a","repo":"n8n-io/n8n","slug":"langsmith-client-not-initialized-check-langsmith","errorCode":null,"errorMessage":"LangSmith client not initialized - check LANGSMITH_API_KEY","messagePattern":"LangSmith client not initialized - check LANGSMITH_API_KEY","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/ai-workflow-builder.ee/evaluations/cli/index.ts","lineNumber":485,"sourceCode":" */\nexport async function runV2Evaluation(): Promise<void> {\n\tconst args = parseEvaluationArgs();\n\n\tif (args.backend === 'langsmith' && (args.prompt || args.promptsCsv || args.testCase)) {\n\t\tthrow new Error(\n\t\t\t'LangSmith mode requires `--dataset` and does not support `--prompt`, `--prompts-csv`, or `--test-case`',\n\t\t);\n\t}\n\n\t// Setup environment with per-stage model configuration\n\tconst logger = createLogger(args.verbose);\n\tconst stageModels = argsToStageModels(args);\n\n\tconst env = await setupTestEnvironment(stageModels, logger);\n\n\t// Validate LangSmith client early if langsmith backend is requested\n\tif (args.backend === 'langsmith' && !env.lsClient) {\n\t\tthrow new Error('LangSmith client not initialized - check LANGSMITH_API_KEY');\n\t}\n\n\t// Create workflow generator based on agent type\n\tconst generateWorkflow =\n\t\targs.agent === AGENT_TYPES.CODE_BUILDER\n\t\t\t? createCodeWorkflowBuilderGenerator(\n\t\t\t\t\tenv.parsedNodeTypes,\n\t\t\t\t\tenv.llms,\n\t\t\t\t\targs.timeoutMs,\n\t\t\t\t\tenv.nodeDefinitionDirs,\n\t\t\t\t)\n\t\t\t: createWorkflowGenerator(env.parsedNodeTypes, env.llms, args.featureFlags);\n\n\t// Create evaluators based on suite type\n\tconst evaluators = createEvaluators({\n\t\tsuite: args.suite,\n\t\tjudgeLlm: env.llms.judge,\n\t\tparsedNodeTypes: env.parsedNodeTypes,","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/ai-workflow-builder.ee/evaluations/cli/index.ts#L467-L503","documentation":"Thrown when `--backend langsmith` is requested but `setupTestEnvironment(...)` did not produce an `lsClient`. The client is built from the `LANGSMITH_API_KEY` environment variable; if it is absent or empty the client is `undefined` and the run aborts before touching the LangSmith API. This is a deliberate early-validation so the failure points at credentials rather than at a downstream 'unauthorized' response.","triggerScenarios":"`args.backend === 'langsmith'` AND `env.lsClient` is falsy after environment setup. Typically `LANGSMITH_API_KEY` is unset, set to an empty string, or only exported in a different shell than the one running the eval.","commonSituations":"Running evals in a fresh terminal, in CI without the secret in the matrix env, after switching accounts/projects, or when the key is stored in a `.env` file that the CLI does not auto-load.","solutions":["Export the key in the same shell that runs the eval: `export LANGSMITH_API_KEY=lsv2_sk_...`.","If using a `.env` loader, confirm it runs before `runV2Evaluation()`; otherwise prefix the command inline: `LANGSMITH_API_KEY=lsv2_sk_... pnpm eval --backend langsmith --dataset NAME`.","In CI, add `LANGSMITH_API_KEY` to the repository/worker secret store and verify the job actually receives it (print its length, never the value)."],"exampleFix":"// before\n$ pnpm eval --backend langsmith --dataset my-dataset\nError: LangSmith client not initialized - check LANGSMITH_API_KEY\n// after\n$ export LANGSMITH_API_KEY=lsv2_sk_...\n$ pnpm eval --backend langsmith --dataset my-dataset","handlingStrategy":"validation","validationCode":"function assertLangsmithEnv(): void {\n  const key = process.env.LANGSMITH_API_KEY;\n  if (!key || key.trim() === '') {\n    throw new Error('LANGSMITH_API_KEY is missing or empty; set it before using --backend langsmith');\n  }\n}\n// call before runV2Evaluation when backend === 'langsmith'\nif (backend === 'langsmith') assertLangsmithEnv();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Store the key in your team secret manager and inject it into the eval job's env explicitly.","In CI, fail the job early if `LANGSMITH_API_KEY` is unset instead of letting it reach the CLI.","Print `process.env.LANGSMITH_API_KEY?.length` (never the value) at job start to confirm the secret is present."],"tags":["langsmith","cli","configuration","credentials","env"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}