Skip to content
Skills Library
Programming · Review & audit

langchain-common-errors

/langchain-common-errors

Diagnose and fix common LangChain errors and exceptions. Use when encountering LangChain errors, debugging failures, or troubleshooting integration issues. Trigger with phrases like "langchain error", "langchain exception", "debug langchain", "langchain not working", "langchain troubleshoot".

Repository
agent ↗
Licence
MIT
Last repository change
14.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
3
Deprecation

No signals detected. Repository changed on 14.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Diagnose and fix common LangChain errors and exceptions. Use when encountering LangChain errors, debugging failures, or troubleshooting integration issues. Trigger with phrases like "langchain error", "langchain exception", "debug langchain", "langchain not working", "langchain troubleshoot".

Triggers from the description

langchain errorlangchain exceptiondebug langchainlangchain not workinglangchain troubleshoot
Original author description

Diagnose and fix common LangChain errors and exceptions. Use when encountering LangChain errors, debugging failures, or troubleshooting integration issues. Trigger with phrases like "langchain error", "langchain exception", "debug langchain", "langchain not working", "langchain troubleshoot".

How it works

  1. Overview
  2. Prerequisites
  3. Error Reference
  4. Debugging Tips
  5. Resources
  6. Next Steps
Original SKILL.md headings · 218 lines, 609 words
SKILL.md preview
---
name: langchain-common-errors
description: |
  Diagnose and fix common LangChain errors and exceptions.
  Use when encountering LangChain errors, debugging failures,
  or troubleshooting integration issues.
  Trigger with phrases like "langchain error", "langchain exception",
  "debug langchain", "langchain not working", "langchain troubleshoot".
allowed-tools: Read, Write, Edit, Grep
version: 1.0.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
---

# LangChain Common Errors

## Overview
Quick reference for diagnosing and resolving the most common LangChain errors.

## Prerequisites
- LangChain installed and configured
- Access to application logs
- Understanding of your LangChain implementation

## Error Reference

### Authentication Errors

#### `openai.AuthenticationError: Incorrect API key provided`
```python
# Cause: Invalid or missing API key
# Solution:
import os
os.environ["OPENAI_API_KEY"] = "sk-..."  # Set correct key

# Verify key is loaded
from langchain_openai import ChatOpenAI
llm = ChatOpenAI()  # Will raise error if key invalid
```

#### `anthropic.AuthenticationError: Invalid x-api-key`
```python
# Cause: Anthropic API key not set or invalid
# Solution:
os.environ["ANTHROPIC_API_KEY"] = "sk-ant-..."

# Or pass directly
from langchain_anthropic import ChatAnthropic
llm = ChatAnthropic(api_key="sk-ant-...")
```

### Import Errors

#### `ModuleNotFoundError: No module named 'langchain_openai'`
```bash
# Cause: Provider package not installed
# Solution:
pip install langchain-openai

# For other providers:
pip install langchain-anthropic
pip install langchain-google-genai
pip install langchain-community
```

#### `ImportError: cannot import name 'ChatOpenAI' from 'langchain'`
```python
# Cause: Using old import path (pre-0.2.0)
# Old (deprecated):
from langchain.chat_models import ChatOpenAI

# New (correct):
from langchain_openai import ChatOpenAI
```

### Rate Limiting

#### `openai.RateLimitError: Rate limit reached`
```python
# Cause: Too many API requests
# Solution: Implement retry with backoff
from langchain_openai import ChatOpenAI
from tenacity import retry, wait_exponential, stop_after_attempt

@retry(wait=wait_exponential(min=1, max=60), stop=stop_after_attempt(5))
def call_with_retry(llm, prompt):
    return llm.invoke(prompt)

# Or use LangChain's built-in retry
llm = ChatOpenAI(max_retries=3)
```

### Output Parsing Errors

#### `OutputParserException: Failed to parse output`
```python
# Cause: LLM output doesn't match expected format
# Solution 1: Use with_retry
from langchain.output_parsers import RetryOutputParser

parser = RetryOutputParser.from_llm(parser=your_parser, llm=llm)

# Solution 2: Use structured output (more reliable)
from pydantic import BaseModel

class Output(BaseModel):
    answer: str

llm_with_structure = llm.with_structured_output(Output)
```

#### `ValidationError: field required`
```python
# Cause: Pydantic model validation failed
# Solution: Make fields optional or provide defaults
from pydantic import BaseModel, Field
from typing import Optional

class Output(BaseModel):
    answer: str
    confidence: Optional[float] = Field(default=None)
```

### Chain Errors

#### `ValueError: Missing required input keys`
```python
# Cause: Input dict missing required variables
# Debug:
prompt = ChatPromptTemplate.from_template("Hello {name}, you are {age}")
print(prompt.input_variables)  # ['name', 'age']

# Solution: Provide all required keys
chain.invoke({"name": "Alice", "age": 30})
```

#### `TypeError: Expected mapping type as input`
```python
# Cause: Passing wrong input type
# Wrong:
chain.invoke("hello")

# Correct:
chain.invoke({"input": "hello"})
```

### Agent Errors

#### `AgentExecutor: max iterations reached`
```python
# Cause: Agent stuck in loop
# Solution: Increase iterations or improve prompts
agent_executor = AgentExecutor(
    agent=agent,
    tools=tools,
    max_iterations=20,  # Increase from default 15
    early_stopping_method="force"  # Force stop after max
)
```

#### `ToolException: Tool execution failed`
```python
# Cause: Tool raised an exception
# Solution: Add error handling in tool
@tool
def my_tool(input: str) -> str:
    """Tool description."""
    try:
        # Tool logic
        return result
    except Exception as e:
        return f"Tool error: {str(e)}"
```

### Memory Errors

#### `KeyError: 'chat_history'`
```python
# Cause: Memory key mismatch
# Solution: Ensure consistent key names
prompt = ChatPromptTemplate.from_messages([
    MessagesPlaceholder(variable_name="chat_history"),  # Match this
    ("human", "{input}")
])

# When invoking:
chain.invoke({
    "input": "hello",
    "chat_history": []  # Must match placeholder name
})
```

## Debugging Tips

### Enable Verbose Mode
```python
import langchain
langchain.debug = True  # Shows all chain steps

# Or per-component
agent_executor = AgentExecutor(verbose=True)
```

### Trace with LangSmith
```python
# Set environment variables
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_API_KEY"] = "your-langsmith-key"
os.environ["LANGCHAIN_PROJECT"] = "my-project"

# All chains automatically traced
```

### Check Version Compatibility
```bash
pip show langchain langchain-core langchain-openai

# Ensure versions are compatible:
# langchain >= 0.3.0
# langchain-core >= 0.3.0
# langchain-openai >= 0.2.0
```

## Resources
- [LangChain Troubleshooting](https://python.langchain.com/docs/troubleshooting/)
- [LangSmith Debugging](https://docs.smith.langchain.com/)
- [GitHub Issues](https://github.com/langchain-ai/langchain/issues)

## Next Steps
For complex debugging, use `langchain-debug-bundle` to collect evidence.

Versions

RepositoryScoreLicence
This page · HelixDevelopment/agent100MIT
jeremylongshore/tons-of-skills-marketplace100MIT

Database snapshot: 13.11.2026 · package version 031b9049f33c (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100firecrawl-common-errors
    Diagnose and fix FireCrawl common errors and exceptions. Use when encountering FireCrawl errors, debugging failed requests, or troubleshooting integration issues. Trigger with phrases like "firecrawl error", "fix firecrawl", "firecrawl not working", "debug firecrawl".
  • 100hex-common-errors
    Diagnose and fix Hex common errors and exceptions. Use when encountering Hex errors, debugging failed requests, or troubleshooting integration issues. Trigger with phrases like "hex error", "fix hex", "hex not working", "debug hex".
  • 100posthog-common-errors
    Diagnose and fix PostHog common errors and exceptions. Use when encountering PostHog errors, debugging failed requests, or troubleshooting integration issues. Trigger with phrases like "posthog error", "fix posthog", "posthog not working", "debug posthog".
  • 100framer-common-errors
    Diagnose and fix Framer common errors and exceptions. Use when encountering Framer errors, debugging failed requests, or troubleshooting integration issues. Trigger with phrases like "framer error", "fix framer", "framer not working", "debug framer".

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.