langchain-common-errors
Diagnose and fix common LangChain errors and exceptions. Use when encountering LangChain import errors, auth failures, output parsing issues, agent loops, or version conflicts. Trigger: "langchain error", "langchain exception", "debug langchain", "langchain not working", "langchain troubleshoot".
Best use case
langchain-common-errors is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Diagnose and fix common LangChain errors and exceptions. Use when encountering LangChain import errors, auth failures, output parsing issues, agent loops, or version conflicts. Trigger: "langchain error", "langchain exception", "debug langchain", "langchain not working", "langchain troubleshoot".
Teams using langchain-common-errors should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/langchain-common-errors/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How langchain-common-errors Compares
| Feature / Agent | langchain-common-errors | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Diagnose and fix common LangChain errors and exceptions. Use when encountering LangChain import errors, auth failures, output parsing issues, agent loops, or version conflicts. Trigger: "langchain error", "langchain exception", "debug langchain", "langchain not working", "langchain troubleshoot".
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
AI Agents for Coding
Browse AI agent skills for coding, debugging, testing, refactoring, code review, and developer workflows across Claude, Cursor, and Codex.
ChatGPT vs Claude for Agent Skills
Compare ChatGPT and Claude for AI agent skills across coding, writing, research, and reusable workflow execution.
SKILL.md Source
# LangChain Common Errors
## Overview
Quick reference for the most frequent LangChain errors with exact error messages, root causes, and copy-paste fixes.
## Import Errors
### `Cannot find module '@langchain/openai'`
```bash
# Provider package not installed
npm install @langchain/openai
# Also: @langchain/anthropic, @langchain/google-genai, @langchain/community
```
### `Cannot import name 'ChatOpenAI' from 'langchain'` (Python)
```python
# Old import path (pre-0.2). Use provider packages:
# OLD: from langchain.chat_models import ChatOpenAI
# NEW:
from langchain_openai import ChatOpenAI
```
### `@langchain/core version mismatch`
```bash
# All @langchain/* packages must share the same minor version
npm ls @langchain/core
# Fix: update all together
npm install @langchain/core@latest @langchain/openai@latest @langchain/anthropic@latest
```
## Authentication Errors
### `AuthenticationError: Incorrect API key provided`
```typescript
// Key not set or wrong format
// Check:
console.log("Key present:", !!process.env.OPENAI_API_KEY);
console.log("Key prefix:", process.env.OPENAI_API_KEY?.slice(0, 7));
// Should be "sk-..." for OpenAI, "sk-ant-..." for Anthropic
// Fix: ensure dotenv is loaded BEFORE imports
import "dotenv/config";
import { ChatOpenAI } from "@langchain/openai";
```
### `Error: OPENAI_API_KEY is not set`
```typescript
// Model constructor can't find the key
// Option 1: environment variable
process.env.OPENAI_API_KEY = "sk-...";
// Option 2: pass directly (not recommended for production)
const model = new ChatOpenAI({
model: "gpt-4o-mini",
apiKey: "sk-...",
});
```
## Chain Errors
### `Missing value for input variable "topic"`
```typescript
// Template has variables not provided in invoke()
const prompt = ChatPromptTemplate.fromTemplate("Tell me about {topic} in {language}");
console.log(prompt.inputVariables); // ["topic", "language"]
// Fix: provide ALL variables
await chain.invoke({ topic: "AI", language: "English" }); // not just { topic: "AI" }
```
### `Expected mapping type as input to ChatPromptTemplate`
```typescript
// Passing a string instead of an object
// WRONG:
await chain.invoke("hello");
// RIGHT:
await chain.invoke({ input: "hello" });
```
## Output Parsing Errors
### `OutputParserException: Failed to parse`
```typescript
// LLM output doesn't match expected format
// Fix 1: Use withStructuredOutput (most reliable)
import { z } from "zod";
const schema = z.object({
answer: z.string(),
confidence: z.number().optional(), // make fields optional for resilience
});
const structuredModel = model.withStructuredOutput(schema);
// Fix 2: Add retry parser (Python)
// from langchain.output_parsers import RetryWithErrorOutputParser
// retry_parser = RetryWithErrorOutputParser.from_llm(parser=parser, llm=llm)
```
### `ZodError: validation failed`
```typescript
// Structured output doesn't match Zod schema
// Fix: make optional fields nullable, add defaults
const Schema = z.object({
answer: z.string(),
confidence: z.number().min(0).max(1).default(0.5),
sources: z.array(z.string()).default([]),
});
```
## Agent Errors
### `AgentExecutor: max iterations reached`
```typescript
// Agent stuck in a tool-calling loop
const executor = new AgentExecutor({
agent,
tools,
maxIterations: 15, // increase from default 10
earlyStoppingMethod: "force", // force stop instead of error
});
// Root cause: usually a vague system prompt. Be specific about when to stop.
```
### `Missing placeholder 'agent_scratchpad'`
```typescript
// Agent prompt MUST include the scratchpad placeholder
const prompt = ChatPromptTemplate.fromMessages([
["system", "You are helpful."],
["human", "{input}"],
new MessagesPlaceholder("agent_scratchpad"), // REQUIRED
]);
```
## Rate Limiting
### `429 Too Many Requests / RateLimitError`
```typescript
// Built-in retry handles this automatically
const model = new ChatOpenAI({
model: "gpt-4o-mini",
maxRetries: 5, // exponential backoff on 429
});
// For batch processing, control concurrency
const results = await chain.batch(inputs, { maxConcurrency: 5 });
```
## Memory/History Errors
### `KeyError: 'chat_history'`
```typescript
// MessagesPlaceholder name must match invoke key
const prompt = ChatPromptTemplate.fromMessages([
new MessagesPlaceholder("chat_history"), // this name...
["human", "{input}"],
]);
await chain.invoke({
input: "hello",
chat_history: [], // ...must match this key
});
```
## Debugging Toolkit
### Enable Debug Logging
```typescript
// See every step in chain execution
import { setVerbose } from "@langchain/core";
setVerbose(true); // logs all chain steps
// Python equivalent:
// import langchain; langchain.debug = True
```
### Enable LangSmith Tracing
```bash
# Add to .env — all chains automatically traced
LANGSMITH_TRACING=true
LANGSMITH_API_KEY=lsv2_...
LANGSMITH_PROJECT=my-debug-session
```
### Check Version Compatibility
```bash
# All @langchain/* packages should be on compatible versions
npm ls @langchain/core 2>&1 | head -20
# Python
pip show langchain langchain-core langchain-openai | grep -E "Name|Version"
```
## Quick Diagnostic Script
```typescript
import "dotenv/config";
async function diagnose() {
const checks: Record<string, string> = {};
// Check env vars
checks["OPENAI_API_KEY"] = process.env.OPENAI_API_KEY ? "set" : "MISSING";
checks["ANTHROPIC_API_KEY"] = process.env.ANTHROPIC_API_KEY ? "set" : "MISSING";
// Check imports
try {
await import("@langchain/core");
checks["@langchain/core"] = "OK";
} catch { checks["@langchain/core"] = "MISSING"; }
try {
const { ChatOpenAI } = await import("@langchain/openai");
const llm = new ChatOpenAI({ model: "gpt-4o-mini" });
await llm.invoke("test");
checks["OpenAI connection"] = "OK";
} catch (e: any) {
checks["OpenAI connection"] = e.message.slice(0, 80);
}
console.table(checks);
}
await diagnose();
```
## Resources
- [LangChain Troubleshooting](https://js.langchain.com/docs/troubleshooting/)
- [LangSmith Debugging](https://docs.smith.langchain.com/)
- [GitHub Issues](https://github.com/langchain-ai/langchainjs/issues)
## Next Steps
For complex debugging, use `langchain-debug-bundle` to collect comprehensive evidence.Related Skills
workhuman-common-errors
Workhuman common errors for employee recognition and rewards API. Use when integrating Workhuman Social Recognition, or building recognition workflows with HRIS systems. Trigger: "workhuman common errors".
wispr-common-errors
Wispr Flow common errors for voice-to-text API integration. Use when integrating Wispr Flow dictation, WebSocket streaming, or building voice-powered applications. Trigger: "wispr common errors".
windsurf-common-errors
Diagnose and fix common Windsurf IDE and Cascade errors. Use when Cascade stops working, Supercomplete fails, indexing hangs, or encountering Windsurf-specific issues. Trigger with phrases like "windsurf error", "fix windsurf", "windsurf not working", "cascade broken", "windsurf slow".
webflow-common-errors
Diagnose and fix Webflow Data API v2 errors — 400, 401, 403, 404, 409, 429, 500. Use when encountering Webflow API errors, debugging failed requests, or troubleshooting integration issues. Trigger with phrases like "webflow error", "fix webflow", "webflow not working", "debug webflow", "webflow 429", "webflow 401".
vercel-common-errors
Diagnose and fix common Vercel deployment and function errors. Use when encountering Vercel errors, debugging failed deployments, or troubleshooting serverless function issues. Trigger with phrases like "vercel error", "fix vercel", "vercel not working", "debug vercel", "vercel 500", "vercel build failed".
veeva-common-errors
Veeva Vault common errors for REST API and clinical operations. Use when working with Veeva Vault document management and CRM. Trigger: "veeva common errors".
vastai-common-errors
Diagnose and fix Vast.ai common errors and exceptions. Use when encountering Vast.ai errors, debugging failed instances, or troubleshooting GPU rental issues. Trigger with phrases like "vastai error", "fix vastai", "vastai not working", "debug vastai", "vastai instance failed".
twinmind-common-errors
Diagnose and fix TwinMind common errors and exceptions. Use when encountering transcription errors, debugging failed requests, or troubleshooting integration issues. Trigger with phrases like "twinmind error", "fix twinmind", "twinmind not working", "debug twinmind", "transcription failed".
together-common-errors
Together AI common errors for inference, fine-tuning, and model deployment. Use when working with Together AI's OpenAI-compatible API. Trigger: "together common errors".
techsmith-common-errors
TechSmith common errors for Snagit COM API and Camtasia automation. Use when working with TechSmith screen capture and video editing automation. Trigger: "techsmith common errors".
supabase-common-errors
Diagnose and fix Supabase errors across PostgREST, PostgreSQL, Auth, Storage, and Realtime. Use when encountering error codes like PGRST301, 42501, 23505, or auth failures. Use when debugging failed queries, RLS policy violations, or HTTP 4xx/5xx responses. Trigger with "supabase error", "fix supabase", "PGRST", "supabase 403", "RLS not working", "supabase auth error", "unique constraint", "foreign key violation".
stackblitz-common-errors
Fix WebContainer and StackBlitz errors: COOP/COEP, SharedArrayBuffer, boot failures. Use when WebContainers fail to boot, embeds don't load, or processes crash inside WebContainers. Trigger: "stackblitz error", "webcontainer error", "SharedArrayBuffer not defined".