Agent skill · software engineering · jeremylongshore
langchain-middleware-patterns
Build composable middleware for LangChain 1.0 chains and LangGraph 1.0\
Why this skill is useful
Adds a comprehensive set of middleware patterns and implementation details for LangChain and LangGraph that are not available in public documentation, including specific ordering rules and failure modes.
What it needs
Requires langchain-anthropic, langchain-core, langchain-redis, langgraph, presidio-analyzer, presidio-anonymizer, python, redis installed locally. About 9k tokens when loaded. Last updated 2026-08-07. 2,604 stars on the source repository.
What this skill does
LangChain Middleware Patterns (Python) Overview Tenant A sends a prompt: "Summarize this support ticket from alice@acme.com about her overdue invoice." The chain's caching middleware ran before the PII redaction middleware, so the raw prompt — email and all — became part of the cache key. Thirty seconds later Tenant B sends a semantically identical prompt (different tenant, different customer, same shape). Cache hits. Tenant B's user gets back a summary that names alice@acme.com and her overdue invoice. That is pain-catalog entry P24 in production, and it is a real class of incident — post-mortems read like "we added caching to cut cost, leaked a customer's PII to a different tenant within an hour." The sibling failure modes: P25 — Retry middleware runs the model call twice on a 429; both attempts fire onllmend; the token-usage aggregator sums both; a single logical call bills as two, tenant's per-session budget trips at 50% of true usage. P10 — Agent loops exceed 15 iterations on vague prompts. There is no default cost cap. A per-session token-budget middleware solves this; without one, a single "help me with my account" prompt can burn thousands of tokens. P34 — Runnable.invoke does not sanitize prompt injection. A RAG document containing "Ignore previous instructions and..." is followed verbatim. Guardrails middleware is your injection defense; without it, indirect prompt injection is a one-line exploit. P61 — setllmcache(InMemoryCache()) hashes the prompt string only. Two chains with different tool bindings return the same cached response; tools are silently ignored by the cache key. …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills jeremylongshore/langchain-middleware-patterns