| name | langchain-incident-runbook |
| description | Incident response procedures for LangChain production issues.
Use when responding to production incidents, diagnosing outages,
or implementing emergency procedures for LLM applications.
Trigger with phrases like "langchain incident", "langchain outage",
"langchain production issue", "langchain emergency", "langchain down".
|
| allowed-tools | Read, Write, Edit, Bash(curl:*), Grep |
| version | 1.0.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
LangChain Incident Runbook
Overview
Standard operating procedures for responding to LangChain production incidents with diagnosis, mitigation, and recovery steps.
Prerequisites
- Access to production infrastructure
- Monitoring dashboards configured
- LangSmith or equivalent tracing
- On-call rotation established
Incident Classification
Severity Levels
| Level | Description | Response Time | Examples |
|---|
| SEV1 | Complete outage | 15 min | All LLM calls failing |
| SEV2 | Major degradation | 30 min | 50%+ error rate, >10s latency |
| SEV3 | Minor degradation | 2 hours | <10% errors, slow responses |
| SEV4 | Low impact | 24 hours | Intermittent issues |
Runbook: LLM Provider Outage
Detection
curl -s https://status.openai.com/api/v2/status.json | jq '.status.indicator'
curl -s https://status.anthropic.com/api/v2/status.json | jq '.status.indicator'
Diagnosis
import asyncio
from langchain_openai import ChatOpenAI
from langchain_anthropic import ChatAnthropic
async def diagnose_providers():
"""Check all configured providers."""
results = {}
try:
llm = ChatOpenAI(model="gpt-4o-mini", request_timeout=10)
await llm.ainvoke("test")
results["openai"] = "OK"
except Exception as e:
results["openai"] = f"FAIL: {e}"
try:
llm = ChatAnthropic(model="claude-3-5-sonnet-20241022", timeout=10)
await llm.ainvoke("test")
results["anthropic"] = "OK"
except Exception as e:
results["anthropic"] = f"FAIL: {e}"
return results
print(asyncio.run(diagnose_providers()))
Mitigation: Enable Fallback
from langchain_openai import ChatOpenAI
from langchain_anthropic import ChatAnthropic
llm = ChatOpenAI(model="gpt-4o-mini")
primary = ChatOpenAI(model="gpt-4o-mini", max_retries=1, request_timeout=5)
fallback = ChatAnthropic(model="claude-3-haiku-20240307")
llm = primary.with_fallbacks([fallback])
Recovery
- Monitor provider status page
- Gradually remove fallback when primary recovers
- Document incident in post-mortem
Runbook: High Error Rate
Detection
grep -i "error" /var/log/langchain/app.log | tail -50
Diagnosis
from collections import Counter
import json
def analyze_errors(log_file: str) -> dict:
"""Analyze error patterns from logs."""
errors = []
with open(log_file) as f:
for line in f:
if "error" in line.lower():
try:
log = json.loads(line)
errors.append(log.get("error_type", "unknown"))
except:
pass
return dict(Counter(errors).most_common(10))
ERROR_CAUSES = {
"RateLimitError": "Exceeded API quota - reduce load or increase limits",
"AuthenticationError": "Invalid API key - check secrets",
"Timeout": "Network issues or overloaded provider",
"OutputParserException": "LLM output format changed - check prompts",
"ValidationError": "Schema mismatch - update Pydantic models",
}
Mitigation
from functools import wraps
import time
def emergency_rate_limit(calls_per_minute: int = 10):
"""Emergency rate limiter decorator."""
interval = 60.0 / calls_per_minute
last_call = [0]
def decorator(func):
@wraps(func)
async def wrapper(*args, **kwargs):
elapsed = time.time() - last_call[0]
if elapsed < interval:
await asyncio.sleep(interval - elapsed)
last_call[0] = time.time()
return await func(*args, **kwargs)
return wrapper
return decorator
from langchain_core.globals import set_llm_cache
from langchain_community.cache import InMemoryCache
set_llm_cache(InMemoryCache())
Runbook: Memory/Performance Issues
Detection
ps aux | grep python | head -5
Diagnosis
import tracemalloc
tracemalloc.start()
chain.invoke({"input": "test"})
snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.statistics('lineno')
print("Top 10 memory allocations:")
for stat in top_stats[:10]:
print(stat)
Mitigation
from langchain_core.globals import set_llm_cache
set_llm_cache(None)
Runbook: Cost Spike
Detection
Diagnosis
def analyze_costs(traces: list) -> dict:
"""Analyze cost from trace data."""
by_chain = {}
for trace in traces:
chain_name = trace.get("name", "unknown")
tokens = trace.get("total_tokens", 0)
if chain_name not in by_chain:
by_chain[chain_name] = {"count": 0, "tokens": 0}
by_chain[chain_name]["count"] += 1
by_chain[chain_name]["tokens"] += tokens
return sorted(by_chain.items(), key=lambda x: x[1]["tokens"], reverse=True)
Mitigation
class BudgetExceeded(Exception):
pass
daily_spend = 0
DAILY_LIMIT = 100.0
def check_budget(cost: float):
global daily_spend
daily_spend += cost
if daily_spend > DAILY_LIMIT:
raise BudgetExceeded(f"Daily limit ${DAILY_LIMIT} exceeded")
Incident Response Checklist
During Incident
Post-Incident
Resources
Next Steps
Use langchain-debug-bundle for detailed evidence collection.