Install any skill in seconds. Free to start, no credit card required.
Get Started Free →jeremylongshore/langchain-middleware-patterns
Build composable middleware for LangChain 1.0 chains and LangGraph 1.0 agents — PII redaction, caching, retry, token budgets, guardrails — with ORDERING rules that avoid cache-key leakage and double-counting.
Passed 19 of 22 test cases with the skill, and 13 of 22 without it.
and 13 more in the full report
7 fixed12 passed either way2 still failing1 broke
Tokens, turns and time describe resource use, not a dollar price.
One of 7 test cases the skill fixed. Same model, same prompt, with and without the skill.
Which cryptographic digest function and delimiter character does the canonical LangChain middleware pattern use for computing fast, collision-safe cache keys across prompt, tool definitions, and tenant ID?
| Checked | Without skill | With skill |
|---|---|---|
| The response selects blake2b as the hashing algorithm. | Missed | Passed |
| The response uses the byte unit separator character between key fields. | Missed | Passed |
The instructions your model reads when the skill loads.
Tenant A sends a prompt: "Summarize this support ticket from [email protected]
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 [email protected] 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:
on_llm_end; the token-usage aggregator sums both; a single logical call
bills as two, tenant's per-session budget trips at 50% of true usage.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.set_llm_cache(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.This skill defines the canonical middleware order for LangChain 1.0 chains and
LangGraph 1.0 agents, with an ordering-invariants matrix (every adjacent pair
has a named failure mode if you swap them), six reference implementations, a
cache-key hash that includes prompt plus bound-tools plus tenant_id, retry
telemetry that deduplicates by request_id, and an integration test pattern
that asserts the ordering invariant on every build.
Pin: langchain-core 1.0.x, langchain 1.0.x, langgraph 1.0.x. Pain-catalog
anchors: P10, P24, P25, P34, P61, with supporting references to P27, P29,
P30, P33.
test cases passed, vs 13 / 22 without
More skills from the same source and nearby in the registry, with their headline benchmark lift.